Skip to content

Instantly share code, notes, and snippets.

@ThierryGoubier
Last active August 29, 2015 14:16
Show Gist options
  • Save ThierryGoubier/54ba2fcf3cd2e7db9b1e to your computer and use it in GitHub Desktop.
Save ThierryGoubier/54ba2fcf3cd2e7db9b1e to your computer and use it in GitHub Desktop.
Python Parser Tests refactoring: RBParseTreeRewritter
| rewrite |
rewrite := RBParseTreeRewriter new
replace: 'self parse: `#l `{:node :dic |
| n |
n := ''source'' , (node methodNode selector allButFirst: 4).
dic at: #n put: n.
PythonParserTests compile: (RBParser parseMethod: n, '' ^ '', `#l newSource) formattedCode classified: ''resources''.
true }'
with: 'self parse: `{:dic |
RBParser parseExpression: ''self '', (dic at: #n) }'.
PythonParserTests methods
do: [ :e |
(rewrite executeTree: (RBParser parseMethod: e sourceCode))
ifTrue: [ PythonParserTests compile: rewrite tree newSource ] ]
@ThierryGoubier
Copy link
Author

Using RBParseTreeRewritter:

  • matching with RB patterns
  • adding some smalltalk code to the matching code to create additional methods
  • using it to change over 300 methods in one go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment