在哪里可以学习如何构造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的信息?
发布评论