本文整理了Java中org.mozilla.javascript.Parser
类的一些代码示例,展示了Parser
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser
类的具体详情如下:
包路径:org.mozilla.javascript.Parser
类名称:Parser
[英]This class implements the JavaScript parser.
It is based on the SpiderMonkey C source files jsparse.c and jsparse.h in the jsref package.
The parser generates an AstRoot parse tree representing the source code. No tree rewriting is permitted at this stage, so that the parse tree is a faithful representation of the source for frontend processing tools and IDEs.
This parser implementation is not intended to be reused after a parse finishes, and will throw an IllegalStateException() if invoked again.
[中]此类实现了JavaScript解析器。
它基于SpiderMonkey C源文件jsparse。c和jsparse。jsref包中的h。
解析器生成代表源代码的AstRoot解析树。在此阶段不允许树重写,因此解析树是前端处理工具和IDE源代码的忠实表示。
此解析器实现不打算在解析完成后重用,如果再次调用,将抛出IllegalStateException()。
代码示例来源:origin: pentaho/pentaho-kettle
public static ScriptNode parseVariables( Context cx, Scriptable scope, String source, String sourceName,
int lineno, Object securityDomain ) {
// Interpreter compiler = new Interpreter();
CompilerEnvirons evn = new CompilerEnvirons();
// evn.setLanguageVersion(Context.VERSION_1_5);
evn.setOptimizationLevel( -1 );
evn.setGeneratingSource( true );
evn.setGenerateDebugInfo( true );
ErrorReporter errorReporter = new ToolErrorReporter( false );
Parser p = new Parser( evn, errorReporter );
ScriptNode tree = p.parse( source, "", 0 ); // IOException
new NodeTransformer().transform( tree );
// Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
return tree;
}
}
代码示例来源:origin: geogebra/geogebra
int tt = peekToken(), lineno = ts.lineno;
AstNode pn;
pn = primaryExpr();
} else {
consumeToken();
int pos = ts.tokenBeg;
NewExpression nx = new NewExpression(pos);
AstNode target = memberExpr(false);
int end = getNodeEnd(target);
nx.setTarget(target);
if (matchToken(Token.LP)) {
lp = ts.tokenBeg;
List<AstNode> args = argumentList();
if (args != null && args.size() > ARGC_LIMIT)
reportError("msg.too.many.constructor.args");
int rp = ts.tokenBeg;
end = ts.tokenEnd;
if (matchToken(Token.LC)) {
ObjectLiteral initializer = objectLiteral();
end = getNodeEnd(initializer);
nx.setInitializer(initializer);
AstNode tail = memberExprTail(allowCallSyntax, pn);
return tail;
代码示例来源:origin: io.apigee/rhino
int ttFlagged = nextFlaggedToken();
int tt = ttFlagged & CLEAR_TI_MASK;
return function(FunctionNode.FUNCTION_EXPRESSION);
return arrayLiteral();
return objectLiteral();
return let(false, ts.tokenBeg);
return parenExpr();
mustHaveXML();
return attributeAccess();
return name(ttFlagged, tt);
reportError("msg.no.octal.strict");
return createStringLiteral();
reportError("msg.reserved.id");
break;
reportError("msg.unexpected.eof");
break;
reportError("msg.syntax");
代码示例来源:origin: geogebra/geogebra
if (pn == null) codeBug();
int memberTypeFlags = 0, lineno = ts.lineno, dotPos = ts.tokenBeg;
consumeToken();
mustHaveXML();
memberTypeFlags = Node.DESCENDANTS_FLAG;
int maybeName = nextToken();
if (maybeName != Token.NAME
&& !(compilerEnv.isReservedKeywordAsIdentifier()
&& TokenStream.isKeyword(ts.getString()))) {
reportError("msg.no.name.after.dot");
Name name = createNameNode(true, Token.GETPROP);
PropertyGet pg = new PropertyGet(pn, name, dotPos);
pg.setLineno(lineno);
int token = nextToken();
switch (token) {
case Token.THROW:
saveNameTokenData(ts.tokenBeg, "throw", ts.lineno);
ref = propertyName(-1, "throw", memberTypeFlags);
break;
ref = propertyName(-1, ts.getString(), memberTypeFlags);
break;
saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
代码示例来源:origin: com.sun.phobos/phobos-rhino
int tt = peekToken();
switch (tt) {
consumeToken();
decompiler.addToken(tt);
memberTypeFlags = 0;
if (tt == Token.DOTDOT) {
mustHaveXML();
memberTypeFlags = Node.DESCENDANTS_FLAG;
mustMatchToken(Token.NAME, "msg.no.name.after.dot");
s = ts.getString();
decompiler.addName(s);
tt = nextToken();
switch (tt) {
s = ts.getString();
decompiler.addName(s);
pn = propertyName(pn, s, memberTypeFlags);
break;
pn = propertyName(pn, "*", memberTypeFlags);
break;
pn = attributeAccess(pn, memberTypeFlags);
break;
reportError("msg.no.name.after.dot");
代码示例来源:origin: rhino/js
tt = peekToken();
if (tt == Token.NEW) {
consumeToken();
decompiler.addToken(Token.NEW);
pn = nf.createCallOrNew(Token.NEW, memberExpr(false));
if (matchToken(Token.LP)) {
decompiler.addToken(Token.LP);
argumentList(pn);
tt = peekToken();
if (tt == Token.LC) {
nf.addChildToBack(pn, primaryExpr());
pn = primaryExpr();
return memberExprTail(allowCallSyntax, pn);
代码示例来源:origin: geogebra/geogebra
if (pn == null) codeBug();
int pos = pn.getPosition();
int lineno;
tailLoop:
for (;;) {
int tt = peekToken();
switch (tt) {
case Token.DOT:
case Token.DOTDOT:
lineno = ts.lineno;
pn = propertyAccess(tt, pn);
pn.setLineno(lineno);
break;
consumeToken();
int opPos = ts.tokenBeg, rp = -1;
lineno = ts.lineno;
mustHaveXML();
setRequiresActivation();
AstNode filter = expr();
int end = getNodeEnd(filter);
if (mustMatchToken(Token.RP, "msg.no.paren")) {
rp = ts.tokenBeg;
end = ts.tokenEnd;
consumeToken();
int lb = ts.tokenBeg, rb = -1;
lineno = ts.lineno;
AstNode expr = expr();
代码示例来源:origin: ro.isdc.wro4j/rhino
private AstNode expr()
throws IOException
{
AstNode pn = assignExpr();
int pos = pn.getPosition();
while (matchToken(Token.COMMA)) {
int opPos = ts.tokenBeg;
if (compilerEnv.isStrictMode() && !pn.hasSideEffects())
addStrictWarning("msg.no.side.effects", "",
pos, nodeEnd(pn) - pos);
if (peekToken() == Token.YIELD)
reportError("msg.yield.parenthesized");
pn = new InfixExpression(Token.COMMA, pn, assignExpr(), opPos);
}
return pn;
}
代码示例来源:origin: rhino/js
Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
try {
p.parse(source, null, 1);
} catch (EvaluatorException ee) {
errorseen = true;
if (errorseen && p.eof())
return false;
else
代码示例来源:origin: geogebra/geogebra
private AstNode shiftExpr()
throws IOException
{
AstNode pn = addExpr();
for (;;) {
int tt = peekToken(), opPos = ts.tokenBeg;
switch (tt) {
case Token.LSH:
case Token.URSH:
case Token.RSH:
consumeToken();
pn = new InfixExpression(tt, pn, addExpr(), opPos);
continue;
}
break;
}
return pn;
}
代码示例来源:origin: geogebra/geogebra
private AstNode andExpr()
throws IOException
{
AstNode pn = bitOrExpr();
if (matchToken(Token.AND)) {
int opPos = ts.tokenBeg;
pn = new InfixExpression(Token.AND, pn, andExpr(), opPos);
}
return pn;
}
代码示例来源:origin: org.dojotoolkit/dojo-shrinksafe
public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
CompilerEnvirons compilerEnv = new CompilerEnvirons();
Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());
ScriptOrFnNode tree = parser.parse(source, null, lineno);
String encodedSource = parser.getEncodedSource();
if (encodedSource.length() == 0) { return ""; }
代码示例来源:origin: rhino/js
private Node condExpr(boolean inForInit)
throws IOException, ParserException
{
Node pn = orExpr(inForInit);
if (matchToken(Token.HOOK)) {
decompiler.addToken(Token.HOOK);
Node ifTrue = assignExpr(false);
mustMatchToken(Token.COLON, "msg.no.colon.cond");
decompiler.addToken(Token.COLON);
Node ifFalse = assignExpr(inForInit);
return nf.createCondExpr(pn, ifTrue, ifFalse);
}
return pn;
}
代码示例来源:origin: io.apigee/rhino
private AstNode orExpr()
throws IOException
{
AstNode pn = andExpr();
if (matchToken(Token.OR)) {
int opPos = ts.tokenBeg;
pn = new InfixExpression(Token.OR, pn, orExpr(), opPos);
}
return pn;
}
代码示例来源:origin: rhino/js
public ScriptOrFnNode parse(Reader sourceReader,
String sourceURI, int lineno)
throws IOException
{
this.sourceURI = sourceURI;
this.ts = new TokenStream(this, sourceReader, null, lineno);
return parse();
}
代码示例来源:origin: com.sun.phobos/phobos-rhino
private Node assignExpr(boolean inForInit)
throws IOException, ParserException
{
Node pn = condExpr(inForInit);
int tt = peekToken();
if (Token.FIRST_ASSIGN <= tt && tt <= Token.LAST_ASSIGN) {
consumeToken();
decompiler.addToken(tt);
pn = nf.createAssignment(tt, pn, assignExpr(inForInit));
}
return pn;
}
代码示例来源:origin: ro.isdc.wro4j/rhino
/**
* Builds a parse tree from the given sourcereader.
* @see #parse(String,String,int)
* @throws IOException if the {@link Reader} encounters an error
*/
public AstRoot parse(Reader sourceReader, String sourceURI, int lineno)
throws IOException
{
if (parseFinished) throw new IllegalStateException("parser reused");
if (compilerEnv.isIdeMode()) {
return parse(readFully(sourceReader), sourceURI, lineno);
}
try {
this.sourceURI = sourceURI;
ts = new TokenStream(this, sourceReader, null, lineno);
return parse();
} finally {
parseFinished = true;
}
}
代码示例来源:origin: com.sun.phobos/phobos-rhino
private Node expr(boolean inForInit)
throws IOException, ParserException
{
Node pn = assignExpr(inForInit);
while (matchToken(Token.COMMA)) {
decompiler.addToken(Token.COMMA);
if (compilerEnv.isStrictMode() && !pn.hasSideEffects())
addStrictWarning("msg.no.side.effects", "");
pn = nf.createBinary(Token.COMMA, pn, assignExpr(inForInit));
}
return pn;
}
代码示例来源:origin: rhino/js
private void plainProperty(ObjArray elems, Object property)
throws IOException {
mustMatchToken(Token.COLON, "msg.no.colon.prop");
// OBJLIT is used as ':' in object literal for
// decompilation to solve spacing ambiguity.
decompiler.addToken(Token.OBJECTLIT);
elems.add(property);
elems.add(assignExpr(false));
}
代码示例来源:origin: geogebra/geogebra
private void addWarning(String messageId, String messageArg,
int position, int length,
int line, String lineSource, int lineOffset) {
String message = lookupMessage(messageId, messageArg);
if (compilerEnv.reportWarningAsError()) {
addError(messageId, messageArg, position, length, line, lineSource, lineOffset);
} else if (errorCollector != null) {
errorCollector.warning(message, sourceURI, position, length);
} else {
errorReporter.warning(message, sourceURI, line, lineSource, lineOffset);
}
}
内容来源于网络,如有侵权,请联系作者删除!