Nashorn comment nodes in the syntax tree
Sundararajan Athijegannathan
sundararajan.athijegannathan at oracle.com
Thu Aug 4 05:09:41 UTC 2016
I checked only the jdk.nashorn.api.tree.* (parser API) classes in jdk9.
Unfortunately, we'll not be able to support fixes on
jdk.nashorn.internal.* :(
-Sundar
On 8/3/2016 1:45 PM, Emilian Bold wrote:
>
> Also, please note that jdk.nashorn.internal.* packages are not
> APIs and
> therefore please avoid using those. Please use nashorn parser API
> defined by JEP 236 [ http://openjdk.java.net/jeps/236 ]
>
>
> I cannot use JEP 236 yet because it's only part of Java 9 and it's not
> being backported to JDK 8 (why??).
>
> And I cannot use Java 9 because it hasn't been released yet. Even if
> it would be, no company would instantly pick it up, especially with
> the big changes/breakages introduced by modules.
>
> So my only choice is to use JDK 8 with jdk.nashorn.internal.* while
> trying to keep an eye and maintain future compatibility with the JEP
> 236 Tree API.
>
> Yes, comments are swallowed (by design). But, I initially though that
> disturbs line & column number info. [i.e., position of various trees].
> i.e., that was the bug you reported. That does not seem to be the
> case.
>
>
> Could you tell me which classes produce the correct offsets in JDK 9
> compared to JDK 8?
>
> I have executed my test with Java 9 using the jdk.nashorn.internal.*
> packages and the test still fails. Actually, it seems to me with JDK 9
> functionNode.getStart() == functionNode.getFinish() so I'm not certain
> where the offsets are stored now.
>
>
>
> --emi
>
> On Fri, Jul 22, 2016 at 10:38 AM, Sundararajan Athijegannathan
> <sundararajan.athijegannathan at oracle.com
> <mailto:sundararajan.athijegannathan at oracle.com>> wrote:
>
> Hi,
>
> Yes, comments are swallowed (by design). But, I initially though that
> disturbs line & column number info. [i.e., position of various trees].
> i.e., that was the bug you reported. That does not seem to be the
> case.
>
> I wrote a simple sample and checked with jjs in jdk9 build. You can
> check start and end line/column numbers of subtrees (function,
> expression statement) are correct.
>
> Also, please note that jdk.nashorn.internal.* packages are not
> APIs and
> therefore please avoid using those. Please use nashorn parser API
> defined by JEP 236 [ http://openjdk.java.net/jeps/236 ]
>
> #-scripting needed
>
> var Parser = Java.type("jdk.nashorn.api.tree.Parser")
> var p = Parser.create();
> var cu = p.parse("t.js", <<EOF
> /* start script comment */
>
> function hello(){
> return 'world';
> }
>
> //some comment
> hello();
> EOF, print);
>
> var src = cu.sourceElements;
> var itr = src.iterator();
> var lm = cu.lineMap;
> while (itr.hasNext()) {
> var tree = itr.next();
> var start = tree.startPosition;
> var end = tree.endPosition;
> print(tree.kind,
> lm.getLineNumber(start),
> lm.getColumnNumber(start),
> lm.getLineNumber(end),
> lm.getColumnNumber(end));
> }
>
>
> Output:
>
> FUNCTION 3 2 5 1
> EXPRESSION_STATEMENT 8 4 8 11
>
> PS. please check line & column w.r.t beginning of test script parsed.
> i.e., the heredoc starting point.
>
> -Sundar
>
>
More information about the nashorn-dev
mailing list