在哪里可以了解有关为Scala宏构造AST的信息?

编程入门 行业动态 更新时间:2024-10-11 21:24:17
本文介绍了在哪里可以了解有关为Scala宏构造AST的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在哪里可以学习如何构造Scala宏生成的AST?

Where I can learn how to construct the AST's that Scala's macros generate?

Scaladoc并不是我想要的那样有用.例如:

The Scaladoc isn't as helpful as I'd like. For example:

abstract def Apply(sym: Universe.Symbol, args: Universe.Tree*): Universe.Tree A factory method for Apply nodes.

但是如何确定应用"节点是什么?在哪里可以找到AST中节点类型的列表,以及它们如何组合在一起?

But how do I figure out what an Apply node is? Where can I find a list of the node types in AST's, and how they fit together?

推荐答案

关于编译器内部的可用文档并不多,但是可用的东西应该足以开始使用.

There isn't a lot of documentation for the internals of the compiler available, but the things that are available should be enough to get started.

Mirko Stocker 写了他的有关Scala重构的硕士论文.在附录D(第95页)中,他描述了AST的体系结构.它还包括图形概述:

Mirko Stocker, has written his Master Thesis about Scala Refactoring. In Appendix D (p. 95) he describes the architecture of the AST. It includes also a graphical overview:

查找有关AST信息的另一种方法是直接查看 reflect.internal.Trees ,其中包含AST.

Another way to find information about the AST is to look directly into the sources of reflect.internal.Trees, which contains the AST.

如果需要找出内部如何表示特定的源代码片段,请使用reify:

If one needs to find out how a specific source code snippet is represented internally there is reify:

scala> import reflect.runtime.universe._ import reflect.runtime.universe._ scala> showRaw(reify{val i = 0}.tree) res8: String = Block(List(ValDef(Modifiers(), newTermName("i"), TypeTree(), Literal(Constant(0)))), Literal(Constant(())))

更多推荐

在哪里可以了解有关为Scala宏构造AST的信息?

本文发布于:2023-11-07 10:22:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宏构   信息   Scala   AST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!