Ruby (MRI) 语法树节点文档
mri 语法树中大部分节点的含义< /a> 可以很容易地推断出来。 这个列表很长(来源: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
然而 Python 的 AST 操作是一个内置库,它的文档要好得多。是否有一个地方记录了解析树语法树中的所有节点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有 Ruby AST 这样的东西,因此没有它的文档。每个实现都有自己的 AST,可能会也可能不会记录。
此外,您所说的不是抽象语法树,而是解析树(又名具体语法树),根据定义,它与用于构造它的特定解析器紧密相关。不同的解析器可能会为相同的代码和相同的语法构建非常不同的解析树。
您在那里显示的内容看起来像是来自 MRI 或 YARV 的解析树,这两者的记录都非常糟糕。
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.