There is no grammar file as such (like javacc, antlr grammar) for
Nashorn grammar. But, there is a Java Nashorn Parser API in jdk 9 - JEP
http://openjdk.java.net/jeps/236 The parsed ECMAScript code is
represented via Tree API much like Javac's tree API.
Samples using nashorn parser API are :
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/withcheck.js
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/evalcheck.js
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/prettyprinter.js
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/flexijson.js
Other option is using "nashorn:parser.js". This one is in jdk8u as well.
This builtin script can be 'load'-ed and it exposes "parse" function.
The object resulting from parse function looks like the one documented here:
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API
Samples using this script parse APIs
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/parser.js
http://hg.openjdk.java.net/jdk9/dev/nashorn/file/87123e713c92/samples/astviewer.js
-Sundar
On Tuesday 14 July 2015 06:48 PM, BURRIS Thomas wrote:
I'm writing a DSL extension to Javascript and am trying to create Netbeans IDE
support for it. To support syntax highlighting, etc, I need to parse the source
scripts. Right now I'm doing it (as a PoC) using an old JavaCC grammar from
2006. This is insufficient since it's outdated, but also because it doesn't
support the Nashorn extensions, which are crucial to my purpose. So ... my
questions for the list are these:
* Is there a grammar that I can use (i.e., is open source) that supports the
Nashorn extensions?
* If so, where can I get it? And what tool leverages it (i.e., Javacc, antlr,
etc)?
Any other links / suggestions / prior art are welcome...
thanks!
This email and any attachments are intended solely for the use of the
individual or entity to whom it is addressed and may be confidential and/or
privileged.
If you are not one of the named recipients or have received this email in error,
(i) you should not read, disclose, or copy it,
(ii) please notify sender of your receipt by reply email and delete this email
and all attachments,
(iii) Dassault Systemes does not accept or assume any liability or
responsibility for any use of or reliance on this email.
For other languages, go to http://www.3ds.com/terms/email-disclaimer