2015-01-30 14:04 GMT+01:00 kilon alios <kilon.al...@gmail.com>: > Ok thanks for the info, I am still however curious about these "tests" are > just tests (which may or may not happen) that determine the AST, for > example which node to use ? >
'tests' is just there because, in the grammar, there is this at a certain point: testlist: test 'test' "," testlist | test 'test' comma_opt ; I have named this use of test 'test', so SmaCC has deduced that testlist will be a list of test(s) nodes (or maybe other stuff such as atoms, depending on the productions for test).. so, SmaCC, in each rule where testlist is found, it will add a 'tests' instance variable. So, basically, the grammar rules explain how each node can be decomposed in sub-nodes, and the additional annotations (the 'test' naming and the {{}} or {{}}) drive how the classes for the nodes you want to keep are generated. In that testlist case, no node will be generated, but everywhere testlist appear on the right of the rule, then it will add a 'tests' instance variable. > > Or are they tests related to unit testing class PythonParserTests ? > Not at all :) > > Also you said I need to use the visitor created by PythonParser I assume > you mean PyRootNodeVisitor ? Just as it is explained in the AST chapter of > the documentation. > > In my case this simple python list will need me to subclass it and > override method visitListmaker , the aListmaker passed as argument to the > method should I assume it is PyListmakerNode ? > In my experience, what you need to do is you have a look at the ast generated and see if you can recognize the elements. From what I see in your simple example, the key to your list is that PyAtomNode instance with something in list. Once you have that, you know that you need to visit PyAtomNode (and check that it has the [ ] tokens). Looking into what is listmaker in atom in the grammar (congratulations by the way, you have seen it :) ), you'll see that it creates a listmaker node only in the first case: test followed by a list_for, otherwise it falls back to testlist... Thierry > > On Fri, Jan 30, 2015 at 10:50 AM, Thierry Goubier < > thierry.goub...@gmail.com> wrote: > >> Hi kilon, >> >> The tests instance variable is linked to the python grammar: top level >> items in an expression are probably tests, and, through the grammar, tests >> can be just atoms. >> >> So the tests instance variable doesn't means it is testing anything :) >> >> Thierry >> Le 30 janv. 2015 09:23, "kilon alios" <kilon.al...@gmail.com> a écrit : >> >> Ok so I tried to parse a very simple list like >>> >>> [ 67,12342,5 ] >>> >>> using Parse and explore , I can find these number by following this AST >>> (for example 67) >>> >>> PyFileInputNode>>statements: -> 1: PySimpleStmNode>>stmts: -> 1: >>> PyExprStmtNode>>tests: ->1: PyPowerNode>>atom: -> PyAtomNode>>list: -> 1: >>> PyPowerNode>>atom: -> PyPowerNode>>numberToken -> numberToken>>value -> 67 >>> >>> quite a structure, but the one thing I dont get is "tests" , why "tests" >>> ? >>> >>> Does it tests something and if yes what ? >>> >> >