Hi!
I need to be able to parse one 'token' at a time of a JavaScript
source (fx. a java.lang.String) and build an AST tree out of it.
The source string will not contain the complete JavaScript source when
I start parsing it but it should always contain valid JavaScript from
start to end of string at the time I parse.
An example:
I might start by having the following:
String javascript =
"var x = 0;\n" +
"for (int i = 0; i < 5; i++) {";
which is missing the ending "}" to have a valid for-loop.... but never
the less this will be the case when I start building the AST tree, so
I need to put each 'token' into the AST tree and keep checking for an
end-of-string event.
When I have parsed the above example I will add some more javascript,
for example:
javascript = javascript +
" x = x + i;\n" +
"}\n" +
"x\n";
and I should then be able to continue parsing from where I left off
before and add additional tokens to the AST tree.
I need to always be able to know if I'm inside a loop, a nested loop n
times, a function or what-ever, and I think that AST is the way to
go..... or can I keep this 'depth' by just reading tokens?
Anyone have an example of how to do this?
Also please do not hesitate to ask further questions if you didn't
understand the above ;-)
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino