Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nashorn Parser API on JDK 8

Looking for a Java/JDK API for parsing JavaScript (including Nashorn Extensions) I stumbled upon this Gist, which according to an inline comment requires JDK 9 to run. Is there a reliable way to accomplish the same on current or planned releases of JDK 8?

like image 783
Gustav Barkefors Avatar asked Mar 19 '15 20:03

Gustav Barkefors


1 Answers

Nashorn Parser API ( http://openjdk.java.net/jeps/236 ) is jdk9 specific API. On jdk8 or jdk8 update, there is support for script parser function.

load("nashorn:parser.js");

and call "parse" function from script. This function returns a JSON object that represents AST of the script parsed.

See this sample: http://hg.openjdk.java.net/jdk8u/jdk8u-dev/nashorn/file/bfea11f8c8f2/samples/astviewer.js

like image 58
A. Sundararajan Avatar answered Sep 30 '22 19:09

A. Sundararajan