How do I use quasi-quotations to get an AST in Nemerle?
-
08-06-2021 - |
Frage
I try to get the AST of a simple code-snippet in Nemerle, using Nemerle's quasi-quotes.
This is the code I tried:
def ast() : void {
System.Console.WriteLine(<["Test"]>)
}
I ran it on IdeOne (ncc 0.9.3) and I got this error:
prog.nem:2:30:2:36: error: unbound name `Literal.String'
prog.nem:2:30:2:36: error: unbound name `PExpr.Literal'
How can I solve these issues?
Lösung
You just need to add Nemerle.Compiler.dll as a reference to your project. Also, some of the more complex quasi-quotes will only work in macros.
using Nemerle.Compiler;
using System.Console;
macro Test()
{
def x = <[ while (true) WriteLine(4) ]>.ToString();
<[ WriteLine($x) ]>
}
Andere Tipps
Quasi-quotations are intended for use in macros. They need a context of a compiler. Create a macro library project, and use a quasi-quotations in it.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow