本文整理汇总了Java中jdk.nashorn.internal.parser.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于jdk.nashorn.internal.parser包,在下文中一共展示了Parser类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: scan
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
private void scan(File root, File file) throws Exception {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
String ext = FilenameUtils.getExtension(child.getName());
if (child.isFile() && !"js".equals(ext)) {
continue;
}
if ("C:\\websites\\studio.zenplanner.local\\zenplanner\\studio\\js\\lib".equals(child.getPath())) {
continue; // TODO: Un hard code
}
scan(root, child);
}
} else {
Source source = (Source) cons.invoke(null, file.getName(), file);
Parser parser = new Parser(context.getEnv(), source, errors);
FunctionNode functionNode = parser.parse();
new StatementScanner(graph, map, root, file).scan(functionNode); // TODO: better OO
}
}
开发者ID:bgard6977,项目名称:js-parser,代码行数:21,代码来源:FileScanner.java
示例2: checkFunctionParameters
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
private static void checkFunctionParameters(final String params) {
final Parser parser = getParser(params);
try {
parser.parseFormalParameterList();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:NativeFunction.java
示例3: checkFunctionBody
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
private static void checkFunctionBody(final String funcBody) {
final Parser parser = getParser(funcBody);
try {
parser.parseFunctionBody();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:NativeFunction.java
示例4: reparse
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
FunctionNode reparse() {
if (isSerialized()) {
return deserialize();
}
final int descPosition = Token.descPosition(token);
final Context context = Context.getContextTrusted();
final Parser parser = new Parser(
context.getEnv(),
source,
new Context.ThrowErrorManager(),
isStrict(),
// source starts at line 0, so even though lineNumber is the correct declaration line, back off
// one to make it exclusive
lineNumber - 1,
context.getLogger(Parser.class));
if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) {
parser.setFunctionName(functionName);
}
parser.setReparsedFunction(this);
final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition,
Token.descLength(token), true);
// Parser generates a program AST even if we're recompiling a single function, so when we are only
// recompiling a single function, extract it from the program.
return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:RecompilableScriptFunctionData.java
示例5: parse
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
/**
* Returns AST as JSON compatible string.
*
* @param context context
* @param code code to be parsed
* @param name name of the code source (used for location)
* @param includeLoc tells whether to include location information for nodes or not
* @return JSON string representation of AST of the supplied code
*/
public static String parse(final Context context, final String code, final String name, final boolean includeLoc) {
final Parser parser = new Parser(context.getEnv(), sourceFor(name, code), new Context.ThrowErrorManager(), context.getEnv()._strict, context.getLogger(Parser.class));
final JSONWriter jsonWriter = new JSONWriter(includeLoc);
try {
final FunctionNode functionNode = parser.parse(); //symbol name is ":program", default
functionNode.accept(jsonWriter);
return jsonWriter.getString();
} catch (final ParserException e) {
e.throwAsEcmaException();
return null;
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:JSONWriter.java
示例6: getLastExpressionStart
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
/**
* Parse potentially partial code and keep track of the start of last expression.
* This 'partial' parsing support is meant to be used for code-completion.
*
* @param context the nashorn context
* @param code code that is to be parsed
* @return the start index of the last expression parsed in the (incomplete) code.
*/
@Override
public final int getLastExpressionStart(final Context context, final String code) {
final int[] exprStart = { -1 };
final Parser p = new Parser(context.getEnv(), sourceFor("<partial_code>", code),new Context.ThrowErrorManager()) {
@Override
protected Expression expression() {
exprStart[0] = this.start;
return super.expression();
}
@Override
protected Expression assignmentExpression(final boolean noIn) {
exprStart[0] = this.start;
return super.assignmentExpression(noIn);
}
};
try {
p.parse();
} catch (final Exception ignored) {
// throw any parser exception, but we are partial parsing anyway
}
return exprStart[0];
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:Shell.java
示例7: reparse
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
FunctionNode reparse() {
if (isSerialized()) {
return deserialize();
}
final int descPosition = Token.descPosition(token);
final Context context = Context.getContextTrusted();
final Parser parser = new Parser(
context.getEnv(),
source,
new Context.ThrowErrorManager(),
isStrict(),
// source starts at line 0, so even though lineNumber is the correct declaration line, back off
// one to make it exclusive
lineNumber - 1,
context.getLogger(Parser.class));
if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) {
parser.setFunctionName(functionName);
}
parser.setReparsedFunction(this);
final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition,
Token.descLength(token), isPropertyAccessor());
// Parser generates a program AST even if we're recompiling a single function, so when we are only
// recompiling a single function, extract it from the program.
return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName);
}
开发者ID:malaporte,项目名称:kaziranga,代码行数:29,代码来源:RecompilableScriptFunctionData.java
示例8: checkFunctionParameters
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
private static void checkFunctionParameters(final String params) {
final Source src = new Source("<function>", params);
final Parser parser = new Parser(Global.getEnv(), src, new Context.ThrowErrorManager());
try {
parser.parseFormalParameterList();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:10,代码来源:NativeFunction.java
示例9: checkFunctionBody
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
private static void checkFunctionBody(final String funcBody) {
final Source src = new Source("<function>", funcBody);
final Parser parser = new Parser(Global.getEnv(), src, new Context.ThrowErrorManager());
try {
parser.parseFunctionBody();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:10,代码来源:NativeFunction.java
示例10: parse
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
/**
* Returns AST as JSON compatible string.
*
* @param env script environment to use
* @param code code to be parsed
* @param name name of the code source (used for location)
* @param includeLoc tells whether to include location information for nodes or not
* @return JSON string representation of AST of the supplied code
*/
public static String parse(final ScriptEnvironment env, final String code, final String name, final boolean includeLoc) {
final Parser parser = new Parser(env, new Source(name, code), new Context.ThrowErrorManager(), env._strict);
final JSONWriter jsonWriter = new JSONWriter(includeLoc);
try {
final FunctionNode functionNode = parser.parse(CompilerConstants.RUN_SCRIPT.symbolName());
functionNode.accept(jsonWriter);
return jsonWriter.getString();
} catch (final ParserException e) {
e.throwAsEcmaException();
return null;
}
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:22,代码来源:JSONWriter.java
示例11: compileScripts
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
/**
* Compiles the given script files in the command line
*
* @param context the nashorn context
* @param global the global scope
* @param files the list of script files to compile
*
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private static int compileScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
final ScriptEnvironment env = context.getEnv();
try {
if (globalChanged) {
Context.setGlobal(global);
}
final ErrorManager errors = context.getErrorManager();
// For each file on the command line.
for (final String fileName : files) {
final FunctionNode functionNode = new Parser(env, new Source(fileName, new File(fileName)), errors).parse();
if (errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
if (env._print_ast) {
context.getErr().println(new ASTWriter(functionNode));
}
if (env._print_parse) {
context.getErr().println(new PrintVisitor(functionNode));
}
//null - pass no code installer - this is compile only
new Compiler(env).compile(functionNode);
}
} finally {
env.getOut().flush();
env.getErr().flush();
if (globalChanged) {
Context.setGlobal(oldGlobal);
}
}
return SUCCESS;
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:50,代码来源:Shell.java
示例12: main
import jdk.nashorn.internal.parser.Parser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Options options = new Options("nashorn");
options.set("anon.functions", true);
options.set("parse.only", true);
options.set("scripting", true);
ErrorManager errors = new ErrorManager();
Context context = new Context(options, errors, Thread.currentThread().getContextClassLoader());
Source source = Source.sourceFor("test",
new File("/Users/tudesheng/projects/static/bms-fs/src/ibms/wsa/stock/stockIn/stockManage.js"),
Charsets.UTF_8);
Parser parser = new Parser(context.getEnv(), source, errors);
FunctionNode functionNode = parser.parse();
Block block = functionNode.getBody();
List<Statement> statements = block.getStatements();
for (Statement statement : statements) {
statement.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
@Override
public boolean enterLiteralNode(LiteralNode<?> literalNode) {
if (literalNode.isString())
System.out.println(literalNode.getString());
return super.enterLiteralNode(literalNode);
}
});
}
}
开发者ID:haogrgr,项目名称:haogrgr-test,代码行数:28,代码来源:JavaScriptAst.java
注:本文中的jdk.nashorn.internal.parser.Parser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论