AW: Pattern-Matching Parse Trees
Karsten Kusche <[email protected]> Mon, 18 Sep 2023 06:08:40 +0000
| Newsgroups | gmane.comp.lang.smalltalk.vwnc |
|---|---|
| Message-ID | <[email protected]> |
Hi Andre, This is basically what the RewriteTool does for you (and it internally uses the ParseTreeRewriter that Christian talked about). Try searching for: `@condition ifFalse: `@falseBlock And replace it by:. `@condition not ifTrue: `@falseBlock Pay attention that you name the variables correctly, otherwise the rewriter wouldn't know what to put where. The RewriteTool searches in the selected methods, so make sure you have methods selected where the code appears. If you then click on replace it'll search for the methods, build the replacements and show you what'll be done. There's an "Execute All" in the context-menu. The syntax is a bit weird and I can't remember if `@ is enough of a prefix or if it needs to be `` @ sometimes. There's documentation for the tool, so you can also look into the Tools-Guide PDF in the docs folder. This tool is so wild, you can even specify blocks (I believe in curly brackets) to code if a node should match or not. Kind Regards Karsten Georg Heeg eK | Amtsgericht Dortmund HR A 12812 Wallstr. 22 | D-06366 Köthen Tel.: +49-3496-214328 Web: https://urldefense.com/v3/__http://www.heeg.de__;!!DZ3fjg!7NKdDWKRwnfOPGpQxK1PuApmMUtvSy7MpiFA7lc1abWNve7cdugV1rlUDHC3a_uIEx1liusakJZqrU3h$ -----Ursprüngliche Nachricht----- Von: [email protected] <[email protected]> Im Auftrag von Christian Haider Gesendet: Samstag, 16. September 2023 16:47 An: 'andre' <[email protected]>; [email protected] Betreff: AW: [vwnc] Pattern-Matching Parse Trees Look at Refactory.Browser.ParseTreeRewriter which does exactly what you want. All the refactorings and code critic rule are implemented with it, so there are plenty of examples. HTH, Christian -----Ursprüngliche Nachricht----- Von: [email protected] <[email protected]> Im Auftrag von andre Gesendet: Samstag, 16. September 2023 15:16 An: [email protected] Betreff: [vwnc] Pattern-Matching Parse Trees Is there a way to match patterns in a parse tree and do transformations and replacements? Something like '{CONDITION} ifFalse:[ {STATEMENTS} ]' => '{CONDITION} not ifTrue:[ {STATEMENTS} ]' I would like to write a set of transformation rules to normalize Smalltalk code in order to prepare it for automated translation to other languages. This is mainly to simplify expressions and control structures to make them compatible with the target language. Ideally idioms and design patterns can be transformed entirely, so pattern matching needs to go deep into a parse tree and check for constraints at any level. TIA Andre