[e-lang] AST view of E program
Kevin Reid
kpreid at mac.com
Sat Oct 11 07:19:21 CDT 2008
On Oct 8, 2008, at 8:58, Marcelo D. Ré wrote:
> I have problem to print the AST. I couldn't find the way to do
> this. Where is the class or method makeEParse?
All Java classes are presented in E named as "makeX". The actual class
name is org.erights.e.elang.syntax.EParser.
> I didn't find it in the JavaDoc (http://www.erights.org/javadoc/index.html
> )
This is the method you want, for basic usage:
<http://www.erights.org/javadoc/org/erights/e/elang/syntax/EParser.html#run(org.erights.e.elib.tables.Twine)
>
> I need a program that print the on console AST view of a source.
There is no one true syntax for the AST besides normal Kernel-E
syntax, but you can get a TermL form using a converter that's available:
? def convert := <elang:visitors.makeConvertENode2Term>()
# value: <convert>
? convert(e`def x4k3 := (x10 * 4).keep(3)`)
# value: term`def(finalP("x4k3"),
# call(call(noun("x10"),
# "multiply",
# [quote(4)]),
# "keep",
# [quote(3)]))`
If you must have this from Java, then provided that an E vat is
already set up you can do this:
import org.erights.e.elib.tables.Twine;
import org.erights.e.elib.prim.E;
import org.erights.e.elang.syntax.EParser;
import org.erights.e.elang.evm.ENode;
import org.erights.e.elib.serial.Loader;
Object converter =
E.call((Loader)(safeScope.get("import__uriGetter"))
.get("org.erights.e.elang.visitors.makeConvertENode2Term"),
"run");
ENode node = EParser.run(Twine.fromString(source_text, source_url));
System.out.print(E.call(converter, "run", node));
But really, I expect that a reasonably efficient IDE-support module
would want to walk the ENode tree directly, not print it in any syntax.
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list