ok we are getting somewhere, the problem is that if I do (SomeClass compiledMethodAt: #nameOfMethod it will look only in the instance side for method, how I look also for class methods ? Also how I can return source of class ? to be specific I need the names of instance variables, class variables and class instance variables . Markus that beautiful nodesDo outputs the full syntax tree yeap definetly what I need to do what I want. Does the ast method applies also to classes or only compiled methods ? On Fri, Jul 25, 2014 at 9:59 PM, Marcus Denker <marcus.denker@inria.fr> wrote:
On 25 Jul 2014, at 20:55, Marcus Denker <marcus.denker@inria.fr> wrote:
On 25 Jul 2014, at 20:49, Thierry Goubier <thierry.goubier@gmail.com> wrote:
Le 25/07/2014 20:37, kilon alios a écrit :
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 ?
No, just that you can write:
(Object compiledMethodAt: #printString) sourceCode
That's me not sanitizing my code samples (lifting it from the AltBrowser)
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 ?
Ok, as above, it should be understood as:
ast := RBParser parseMethod: (Object compiledMethodAt: #printString) onError: [ :msg :ps | ]. ast doSemanticAnalysisIn: self sourceClass.
There is a method on CompiledMethod called #ast that called the parser + semantic analysis:
( Object compiledMethodAt: #halt ) ast
No need to know details about RBParser.
as example how to query the AST see the method #accessesSlot:
accessesSlot: aSlot self ast nodesDo: [ :node | node isVariable and: [ node isInstance and: [ (node binding slot == aSlot) ifTrue: [^true]]]]. ^false