I don't understand how to use aClass definition from workspace nor I understand your selector message.��

(aClass compiledMethodAt: self selector) sourceCode , self would imply that i try to operate this from inside another class with self selector being the method itself at the time executed ?

However because I try to parse pharo syntax to python code, the classes that I am parsing are��unrelated��to the parser class itself ��so I don't see how self selector would be relevant here.��


I also don't understand��

�� �� ast := RBParser parseMethod: aTarget text asString onError: [ :msg :pos | ^ self ].
�� �� ast doSemanticAnalysisIn: self sourceClass

what is aTarget ?��

Is there any documentation about RBParser how I can use it ? Or any documentation relevant to the subject ?��


On Fri, Jul 25, 2014 at 9:06 PM, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Le 25/07/2014 19:47, kilon alios a ��crit :


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.

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

(works also if aClass is the meta side)


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 := RBParser parseMethod: aTarget text asString onError: [ :msg :pos | ^ self ].
�� �� 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).



Would it make more sense to use something like PettitParser ?

Maybe. But probably not, RBParser is good enough.

Thierry