Ruby (MRI) 语法树节点文档

发布于 2024-09-25 22:54:06 字数 971 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚 2024-10-02 22:54:06

没有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文