EnhancedPainlessLexer.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:elasticsearch_my 作者:
@Override
public void recover(final LexerNoViableAltException lnvae) {
    final CharStream charStream = lnvae.getInputStream();
    final int startIndex = lnvae.getStartIndex();
    final String text = charStream.getText(Interval.of(startIndex, charStream.index()));

    Location location = new Location(sourceName, _tokenStartCharIndex);
    String message = "unexpected character [" + getErrorDisplay(text) + "].";
    char firstChar = text.charAt(0);
    if ((firstChar == '\'' || firstChar == '"') && text.length() - 2 > 0 && text.charAt(text.length() - 2) == '\\') {
        /* Use a simple heuristic to guess if the unrecognized characters were trying to be a string but has a broken escape sequence.
         * If it was add an extra message about valid string escape sequences. */
        message += " The only valid escape sequences in strings starting with [" + firstChar + "] are [\\\\] and [\\"
                + firstChar + "].";
    }
    throw location.createError(new IllegalArgumentException(message, lnvae));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号