• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ParserException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:Parser.java


示例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;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:JSONWriter.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:AbstractParser.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:AbstractParser.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:AbstractParser.java


示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:AbstractParser.java


示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:NativeFunction.java


示例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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:NativeFunction.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:NativeRegExp.java


示例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());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:JdkRegExp.java


示例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());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:JoniRegExp.java


示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:AssignSymbols.java


示例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;
}
 
开发者ID:CarveLang,项目名称:Carve,代码行数:13,代码来源:CarveNode.java


示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:JSONParser.java


示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:NativeRegExp.java



注:本文中的jdk.nashorn.internal.runtime.ParserException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodeClient类代码示例发布时间:2022-05-21
下一篇:
Java SharedEntityManagerCreator类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap