views:

36

answers:

1

The meaning of most nodes from mri's syntax tree can be easily infered. However the list is quite long (source: bin/parse_tree_abc):

:attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn,
:and, :case, :else, :if, :iter, :or, :rescue, :until, :when, :while,
:call, :fcall, :super, :vcall, :yield,
:args, :argscat, :array, :begin, :block, :block_arg, :block_pass, :bool,
:cfunc, :colon2, :const, :cvar, :defined, :defn, :dregx, :dstr, :dvar,
:dxstr, :ensure, :false, :fbody, :gvar, :hash, :ivar, :lit, :long, :lvar,
:match2, :match3, :nil, :not, :nth_ref, :return, :scope, :self, :str,
:splat, :to_ary, :true, :unknown, :value, :void, :zarray, :zarray,
:zclass, :zsuper

Since Python's AST manipulation is a builtin library, its documentation is far better. Is there a place where all nodes from parse tree's syntax tree is documented?

+1  A: 

There is no such thing as a Ruby AST, therefore there is no documentation for it. Every implementation has its own AST, which might or might not be documented.

Besides, what you are talking about is not the abstract syntax tree but the parse tree (aka concrete syntax tree), which is, by definition, closely tied to the specific parser used to construct it. Different parsers might construct very different parse trees for the same code and the same syntax.

What you show there looks like the parse tree from either MRI or YARV, both of which are notoriously badly documented.

Jörg W Mittag
Nicely put. It is MRI's syntax tree. But the term, while incorrect, conveys more easily the notion of what I mean. Even Ilya Grigorik's post, and refering sites, mention this as AST. But thanks for welcomed correction. Edit: funny fact: Googling for 'ruby "concrete syntax tree"' yields this page as first result, and "JAVA - Boolean Query / Expression to a Concrete syntax tree" as second one. Yes, common mistake.
Daniel Ribeiro