I am trying to compile a line of source code and print a parse tree using Poly / ML. The following code compiles, but the parse tree is empty:
fun main () = let val stream = TextIO.openString "let val a = \"abc\"; val b = \"def\"; val c = a ^ b in print c end"; val _ = PolyML.compiler (fn () => TextIO.input1 stream, []); val (_, parseTree) = !PolyML.IDEInterface.parseTree in PolyML.print (parseTree); PolyML.print (List.length parseTree); List.map PolyML.print (parseTree); () end
Launch:
$ ./a.out [...] 0 $
What do I need to do to get the syntax tree from the compiler? I also tried the option using the compiler CPCompilerResultFun parameter. But that didn't work either:
fun main () = let fun useTree (NONE, _) () = (PolyML.print "not parsed"; ()) | useTree (SOME parseTree, _) () = (PolyML.print "parsed"; PolyML.print parseTree; ()); val stream = TextIO.openString "let val a = \"abc\"; val b = \"def\"; val c = a ^ b in print c end"; val _ = PolyML.compiler (fn () => TextIO.input1 stream, [PolyML.Compiler.CPCompilerResultFun useTree]); in () end
Running this produces no output.
source share