本文整理汇总了Java中jdk.nashorn.internal.runtime.ParserException类的典型用法代码示例。如果您正苦于以下问题:Java ParserException类的具体用法?Java ParserException怎么用?Java ParserException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParserException类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ParserException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleParseException
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
private void handleParseException(final Exception e) {
// Extract message from exception. The message will be in error
// message format.
String message = e.getMessage();
// If empty message.
if (message == null) {
message = e.toString();
}
// Issue message.
if (e instanceof ParserException) {
errors.error((ParserException)e);
} else {
errors.error(message);
}
if (env._dump_on_error) {
e.printStackTrace(env.getErr());
}
}
示例2: parse
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的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;
}
}
示例3: error
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Report an error.
*
* @param errorType The error type
* @param message Error message.
* @return ParserException upon failure. Caller should throw and not ignore
*/
protected final ParserException error(final JSErrorType errorType, final String message) {
// TODO - column needs to account for tabs.
final int position = Token.descPosition(token);
final int column = position - linePosition;
final String formatted = ErrorManager.format(message, source, line, column, token);
return new ParserException(errorType, formatted, source, line, column, token);
}
示例4: expectValue
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Check next token, get its value and advance.
*
* @param expected Expected tokenType.
* @return The JavaScript value of the token
* @throws ParserException on unexpected token type
*/
protected final Object expectValue(final TokenType expected) throws ParserException {
if (type != expected) {
throw error(expectMessage(expected));
}
final Object value = getValue();
next();
return value;
}
示例5: getValue
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Get the value of a specific token
*
* @param valueToken the token
*
* @return JavaScript value of the token
*/
protected final Object getValue(final long valueToken) {
try {
return lexer.getValueOf(valueToken, isStrictMode);
} catch (final ParserException e) {
errors.error(e);
}
return null;
}
示例6: getLiteral
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Create a LiteralNode from the current token
*
* @return LiteralNode representing the current token
* @throws ParserException if any literals fails to parse
*/
protected final LiteralNode<?> getLiteral() throws ParserException {
// Capture LITERAL token.
final long literalToken = token;
// Create literal node.
final Object value = getValue();
// Advance to have a correct finish
next();
LiteralNode<?> node = null;
if (value == null) {
node = LiteralNode.newInstance(literalToken, finish);
} else if (value instanceof Number) {
node = LiteralNode.newInstance(literalToken, finish, (Number)value);
} else if (value instanceof String) {
node = LiteralNode.newInstance(literalToken, finish, (String)value);
} else if (value instanceof LexerToken) {
if (value instanceof RegexToken) {
final RegexToken regex = (RegexToken)value;
try {
RegExpFactory.validate(regex.getExpression(), regex.getOptions());
} catch (final ParserException e) {
throw error(e.getMessage());
}
}
node = LiteralNode.newInstance(literalToken, finish, (LexerToken)value);
} else {
assert false : "unknown type for LiteralNode: " + value.getClass();
}
return node;
}
示例7: checkFunctionParameters
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
private static void checkFunctionParameters(final String params) {
final Parser parser = getParser(params);
try {
parser.parseFormalParameterList();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
示例8: checkFunctionBody
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
private static void checkFunctionBody(final String funcBody) {
final Parser parser = getParser(funcBody);
try {
parser.parseFunctionBody();
} catch (final ParserException pe) {
pe.throwAsEcmaException();
}
}
示例9: NativeRegExp
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
NativeRegExp(final String input, final String flagString, final Global global) {
this(global);
try {
this.regexp = RegExpFactory.create(input, flagString);
} catch (final ParserException e) {
// translate it as SyntaxError object and throw it
e.throwAsEcmaException();
throw new AssertionError(); //guard against null warnings below
}
this.setLastIndex(0);
}
示例10: JdkRegExp
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Construct a Regular expression from the given {@code source} and {@code flags} strings.
*
* @param source RegExp source string
* @param flags RegExp flag string
* @throws ParserException if flags is invalid or source string has syntax error.
*/
public JdkRegExp(final String source, final String flags) throws ParserException {
super(source, flags);
int intFlags = 0;
if (isIgnoreCase()) {
intFlags |= CASE_INSENSITIVE | UNICODE_CASE;
}
if (isMultiline()) {
intFlags |= MULTILINE;
}
try {
RegExpScanner parsed;
try {
parsed = RegExpScanner.scan(source);
} catch (final PatternSyntaxException e) {
// refine the exception with a better syntax error, if this
// passes, just rethrow what we have
Pattern.compile(source, intFlags);
throw e;
}
if (parsed != null) {
this.pattern = Pattern.compile(parsed.getJavaPattern(), intFlags);
this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
}
} catch (final PatternSyntaxException e2) {
throwParserException("syntax", e2.getMessage());
}
}
示例11: JoniRegExp
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
/**
* Construct a Regular expression from the given {@code pattern} and {@code flags} strings.
*
* @param pattern RegExp pattern string
* @param flags RegExp flag string
* @throws ParserException if flags is invalid or pattern string has syntax error.
*/
public JoniRegExp(final String pattern, final String flags) throws ParserException {
super(pattern, flags);
int option = Option.SINGLELINE;
if (this.isIgnoreCase()) {
option |= Option.IGNORECASE;
}
if (this.isMultiline()) {
option &= ~Option.SINGLELINE;
option |= Option.NEGATE_SINGLELINE;
}
try {
RegExpScanner parsed;
try {
parsed = RegExpScanner.scan(pattern);
} catch (final PatternSyntaxException e) {
// refine the exception with a better syntax error, if this
// passes, just rethrow what we have
Pattern.compile(pattern, 0);
throw e;
}
if (parsed != null) {
final char[] javaPattern = parsed.getJavaPattern().toCharArray();
this.regex = new Regex(javaPattern, 0, javaPattern.length, option, Syntax.JAVASCRIPT);
this.groupsInNegativeLookahead = parsed.getGroupsInNegativeLookahead();
}
} catch (final PatternSyntaxException | JOniException e2) {
throwParserException("syntax", e2.getMessage());
}
}
示例12: throwParserException
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
private void throwParserException(final String message, final Node origin) {
if (origin == null) {
throw new ParserException(message);
}
final Source source = compiler.getSource();
final long token = origin.getToken();
final int line = source.getLine(origin.getStart());
final int column = source.getColumn(origin.getStart());
final String formatted = ErrorManager.format(message, source, line, column, token);
throw new ParserException(JSErrorType.SYNTAX_ERROR, formatted, source, line, column, token);
}
示例13: childGet
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends CarveNode> T childGet(int index) {
if (childExists(index)) {
Node node = jjtGetChild(index);
try {
return (T) node;
} catch (ClassCastException e) {
throw new ParserException("Cannot cast child #" + index + " to expected type.");
}
}
return null;
}
示例14: error
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
ParserException error(final String message, final int start, final int length) throws ParserException {
final long token = Token.toDesc(STRING, start, length);
final int pos = Token.descPosition(token);
final Source src = Source.sourceFor("<json>", source);
final int lineNum = src.getLine(pos);
final int columnNum = src.getColumn(pos);
final String formatted = ErrorManager.format(message, src, lineNum, columnNum, token);
return new ParserException(JSErrorType.SYNTAX_ERROR, formatted, src, lineNum, columnNum, token);
}
示例15: NativeRegExp
import jdk.nashorn.internal.runtime.ParserException; //导入依赖的package包/类
NativeRegExp(final String input, final String flagString, final Global global, final ScriptObject proto) {
super(proto, $nasgenmap$);
try {
this.regexp = RegExpFactory.create(input, flagString);
} catch (final ParserException e) {
// translate it as SyntaxError object and throw it
e.throwAsEcmaException();
throw new AssertionError(); //guard against null warnings below
}
this.globalObject = global;
this.setLastIndex(0);
}