Le 25/07/2014 19:47, kilon alios a ��crit :For the class, use aClass definition. For a method use CompiledMethod>>sourceCode; you can also ask the class for a selector as in: (aClass compiledMethodAt: self selector) sourceCode
I want to find the source of a Class and its methods (including all variables too, local , instance, class , class instance etc) and return them as a string or a collection of strings.
(works also if aClass is the meta side)�� �� ast := RBParser parseMethod: aTarget text asString onError: [ :msg :pos | ^ self ].
I have found MethodNode>>sourceText and CompiledMethod>>sourceCode but I have no clue how to send these messages or if they are the messages I am looking for.
Also any pointers as to how to navigate the Pharo syntax by code using something like AST would be greatly appreciated :)
http://stackoverflow.com/questions/24961556/how-to-ask-an-object-to-return-its-class-and-methods-source-as-a-string
�� �� ast doSemanticAnalysisIn: self sourceClass.
(you need the semantic analysis to have the variable bindings)
To navigate the parse tree you either write a visitor or use existing search structures and extend nodes, as is done in SmartSuggestions.
SmartSuggestions is probably an interesting place to look for that. The code above is from an ancestor to smart suggestion.
Then I have some code which does a visit + rewrite over an AST tree (a code tracing tool). Refactoring also does that (all things RB).Maybe. But probably not, RBParser is good enough.
Would it make more sense to use something like PettitParser ?
Thierry