2

我嘗試使用Nemerle的準引號來獲取Nemerle中簡單代碼段的AST。如何使用準引號在Nemerle中獲得AST?

這是我試過的代碼:

def ast() : void { 
    System.Console.WriteLine(<["Test"]>) 
} 

我跑它IdeOne(NCC 0.9.3),我得到這個錯誤:

prog.nem:2:30:2:36: error: unbound name `Literal.String' 
prog.nem:2:30:2:36: error: unbound name `PExpr.Literal' 

我該如何解決這些問題?

回答

3

你只需要添加Nemerle.Compiler.dll作爲你的項目的參考。另外,一些更復雜的準引號只能在宏中使用。

using Nemerle.Compiler; 
using System.Console; 

macro Test() 
{ 
    def x = <[ while (true) WriteLine(4) ]>.ToString(); 
    <[ WriteLine($x) ]> 
} 
2

準引用旨在用於宏。他們需要一個編譯器的上下文。創建一個宏庫項目,並在其中使用準引號。