Oh yes yes thank you, thank you both, this is exactly what I wanted. No need to send me your code ,I can parse this with regex I am already parsing pharo code with regex and it has been easy enough. It worked for messages like unary and keywords but I wanted to do more complex pharo syntax parsing to python. But if your code follows a better approach is more than welcomed. This is the first time I actually try to parse full syntax of a language. Basically what you gave me looks good enough to do what I want, I will also look at the classes themselves, I am surprised how small package AST is. I guess that the beauty of the smalltalk syntax. :) On Fri, Jul 25, 2014 at 10:51 PM, Thierry Goubier <thierry.goubier@gmail.com
wrote:
Le 25/07/2014 21:42, kilon alios a écrit :
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 .
For the class method:
SomeClass class compiledMethodAt: #nameOfClassMethod
For the instance variable, etc... SomeClass definition will give you that. But it's a bit tricky to parse; for example, if you want a reification (instance variable name is recognized as instance variable name in the ast), I have some code which does: parse, rewrite and reparse on a class definition (for the smart suggestion thing).
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 ?
Only source code. A class definition is not entirely code (see above).
On Fri, Jul 25, 2014 at 9:59 PM, Marcus Denker <marcus.denker@inria.fr> wrote:
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
Thanks Markus, this is a nice example.
Thierry