Java 类org.antlr.v4.runtime.BufferedTokenStream 实例源码

项目:ftc    文件:QueryHandler.java   
private List<SyntaxElement> addNonSyntaxTokens(List<SyntaxElement> syntaxElements, BufferedTokenStream tokens) {

        StackLight<SyntaxElement> regularElements = new StackLight<SyntaxElement>(syntaxElements);

        List<SyntaxElement> result = new LinkedList<SyntaxElement>();

        for (Token t : tokens.getTokens()) {
            if (!regularElements.empty() && regularElements.peek().tokenIndex == t.getTokenIndex())
                result.add(regularElements.pop());
            else {
                SyntaxElementType type = getIrregularType(t);
                if (type != SyntaxElementType.unknown)
                    result.add(SyntaxElement.create(t, type));
            }
        }

        return result;
    }
项目:adl2-core    文件:AdlDeserializer.java   
public Archetype parse(Reader reader) throws IOException {
    try {
        CharStream charStream = new ANTLRInputStream(reader);
        Lexer lexer = new adlLexer(charStream);
        adlParser parser = new adlParser(new BufferedTokenStream(lexer));
        AccumulatingErrorListener errorHandler = new AccumulatingErrorListener();
        parser.removeErrorListeners();
        parser.addErrorListener(errorHandler);
        adlParser.AdlContext context = parser.adl();
        if (!errorHandler.getErrors().isEmpty()) {
            throw new AdlParserException(Joiner.on("\n").join(errorHandler.getErrors()));
        }
        AdlTreeParser treeParser = new AdlTreeParser();
        return treeParser.parseAdl(context);

    } finally {
        reader.close();
    }
}
项目:jarn    文件:YarnTreeParser.java   
private void parseNodeContent(String nodeContent) throws IOException {
    YarnLexer yarnLexer = new YarnLexer(new ANTLRInputStream(nodeContent));
    YarnParser yarnParser = new YarnParser(new BufferedTokenStream(yarnLexer));
    NodeContext nodeContext = yarnParser.node();

    ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
    parseTreeWalker.walk(this, nodeContext);
}
项目:jarn    文件:YarnParserTest.java   
private void runTest(String filename) throws Exception {
    System.out.println("------------- " + filename + " -------------");
    YarnLexer yarnLexer = new YarnLexer(new ANTLRInputStream(YarnParserTest.class.getResourceAsStream("/" + filename)));
    YarnParser yarnParser = new YarnParser(new BufferedTokenStream(yarnLexer));
    yarnParser.setTrace(true);

    NodeContext nodeContext = yarnParser.node();

    ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
    parseTreeWalker.walk(this, nodeContext);
}
项目:monsoon    文件:ParserSupport.java   
public Configuration configuration() throws IOException, ConfigurationException {
    final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();
    final ConfigTokenizer lexer = new ConfigTokenizer(CharStreams.fromReader(reader_));
    lexer.removeErrorListeners();
    lexer.addErrorListener(error_listener);
    final ConfigParser parser = new ConfigParser(new BufferedTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(error_listener);
    dir_.ifPresent(parser::setDir);

    final ConfigParser.ExprContext expr;
    try {
        expr = parser.expr();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
        if (!error_listener.errors.isEmpty())
            throw new ConfigurationException(error_listener.errors, ex);
        else
            throw ex;
    }

    if (!error_listener.errors.isEmpty()) {
        if (expr.exception != null)
            throw new ConfigurationException(error_listener.errors, expr.exception);
        throw new ConfigurationException(error_listener.errors);
    } else if (expr.exception != null) {
        throw new ConfigurationException(expr.exception);
    }
    return expr.s;
}
项目:ftc    文件:NameToIDSubstitution.java   
public NameToIDSubstitution(FusionTablesSqlParser parser, BufferedTokenStream tokens,
        TableNameToIdMapper namesToIds, Map<String, String> tableAliasToName) {
    Check.notNull(tokens);
    Check.notNull(namesToIds);
    Check.notNull(tableAliasToName);

    this.mapper = namesToIds;
    rewriter = new TokenStreamRewriter(tokens);
}
项目:ftc    文件:CursorContextListener.java   
public CursorContextListener(int cursorIndex, FusionTablesSqlParser parser, BufferedTokenStream tokens) {
    super(parser, tokens);
    this.cursorIndex = cursorIndex;
    this.parser = parser;

    printDebug(String.format("\ngetting context at position %d", cursorIndex));
}
项目:Objc2Lua    文件:ParserObjcListener.java   
ParserObjcListener(ClassDescription classDescription,
                   BufferedTokenStream tokens, ParseOptions options) {
    super();
    this.classDescription = classDescription;
    this.options = options;
    this.tokens = tokens;
    this.classDeclarations = classDescription.getmFiles();
}
项目:JavaSharp    文件:SyntaxTreeXmlFilter.java   
@Override
public void parse(String javaSourcePath) throws SAXException, IOException {
    // parse the Java file(s) with the ANTLR generated parser
    JavaParser.CompilationUnitContext ctx = readSourceFile(javaSourcePath);
    // visit the AST with the XmlEmittingVisitor, which generates SAX events
    startDocument();
    XmlEmittingVisitor visitor = new XmlEmittingVisitor(this, (BufferedTokenStream) parser.getTokenStream());
    visitor.visit(ctx);
    endDocument();
}
项目:monsoon    文件:PathMatcher.java   
/**
 * Read path matcher from reader.
 *
 * @param reader A reader supplying the input of a path expression.
 * @return A PathMatcher corresponding to the parsed input
 * from the reader.
 * @throws IOException on IO errors from the reader.
 * @throws
 * com.groupon.lex.metrics.PathMatcher.ParseException
 * on invalid path expression.
 */
public static PathMatcher valueOf(Reader reader) throws IOException, ParseException {
    class DescriptiveErrorListener extends BaseErrorListener {
        public List<String> errors = new ArrayList<>();

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
                                int line, int charPositionInLine,
                                String msg, org.antlr.v4.runtime.RecognitionException e) {
            LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg});
            errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg));
        }
    }

    final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();

    final PathMatcherLexer lexer = new PathMatcherLexer(CharStreams.fromReader(reader));
    lexer.removeErrorListeners();
    lexer.addErrorListener(error_listener);

    final PathMatcherGrammar parser = new PathMatcherGrammar(new BufferedTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(error_listener);

    final PathMatcherGrammar.ExprContext expr;
    try {
        expr = parser.expr();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
        if (!error_listener.errors.isEmpty())
            throw new ParseException(error_listener.errors, ex);
        else
            throw ex;
    }

    if (!error_listener.errors.isEmpty()) {
        if (expr.exception != null)
            throw new ParseException(error_listener.errors, expr.exception);
        throw new ParseException(error_listener.errors);
    } else if (expr.exception != null) {
        throw new ParseException(expr.exception);
    }
    return expr.s;
}
项目:monsoon    文件:TimeSeriesMetricExpression.java   
/**
 * Read expression from reader.
 *
 * @param reader A reader supplying the input of an expression.
 * @return A TimeSeriesMetricExpression corresponding to the parsed input
 * from the reader.
 * @throws IOException on IO errors from the reader.
 * @throws
 * com.groupon.lex.metrics.timeseries.TimeSeriesMetricExpression.ParseException
 * on invalid expression.
 */
public static TimeSeriesMetricExpression valueOf(Reader reader) throws IOException, ParseException {
    final Logger LOG = Logger.getLogger(TimeSeriesMetricExpression.class.getName());

    class DescriptiveErrorListener extends BaseErrorListener {
        public List<String> errors = new ArrayList<>();

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
                                int line, int charPositionInLine,
                                String msg, org.antlr.v4.runtime.RecognitionException e) {
            LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg});
            errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg));
        }
    }

    final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();

    final ExpressionLexer lexer = new ExpressionLexer(CharStreams.fromReader(reader));
    lexer.removeErrorListeners();
    lexer.addErrorListener(error_listener);

    final Expression parser = new Expression(new BufferedTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(error_listener);

    final Expression.ExprContext expr;
    try {
        expr = parser.expr();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
        if (!error_listener.errors.isEmpty())
            throw new ParseException(error_listener.errors, ex);
        else
            throw ex;
    }

    if (!error_listener.errors.isEmpty()) {
        if (expr.exception != null)
            throw new ParseException(error_listener.errors, expr.exception);
        throw new ParseException(error_listener.errors);
    } else if (expr.exception != null) {
        throw new ParseException(expr.exception);
    }
    return expr.s;
}
项目:ftc    文件:SyntaxElementListener.java   
public SyntaxElementListener(FusionTablesSqlParser parser, BufferedTokenStream tokens)
{
    super(tokens);
    this.parser = parser;
}
项目:ftc    文件:BaseFtListener.java   
public BaseFtListener(BufferedTokenStream tokens) {
    this.tokens = tokens;
}
项目:protostuff-compiler    文件:ServiceParseListener.java   
protected ServiceParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
}
项目:protostuff-compiler    文件:ProtoParseListener.java   
ProtoParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
    this.tokens = tokens;
}
项目:protostuff-compiler    文件:OptionParseListener.java   
protected OptionParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
}
项目:protostuff-compiler    文件:MessageParseListener.java   
public MessageParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
}
项目:protostuff-compiler    文件:EnumParseListener.java   
protected EnumParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
}
项目:protostuff-compiler    文件:AbstractProtoParserListener.java   
protected AbstractProtoParserListener(BufferedTokenStream tokens, ProtoContext context) {
    this.context = context;
    this.tokens = tokens;
    usedComments = new BitSet();
}
项目:tailor    文件:BlankLineListener.java   
public BlankLineListener(Printer printer, BufferedTokenStream tokenStream) {
    this.printer = printer;
    this.tokenStream = tokenStream;
}
项目:tailor    文件:BraceStyleListener.java   
public BraceStyleListener(Printer printer, BufferedTokenStream tokenStream) {
    this.printer = printer;
    this.tokenStream = tokenStream;
}
项目:EditorPotigol    文件:PrinterListener.java   
public PrinterListener(BufferedTokenStream tokens) {
    this.tokens = tokens;
}
项目:EditorPotigol    文件:PrettyListener.java   
public PrettyListener(BufferedTokenStream tokens) {
    this.tokens = tokens;
}
项目:org.pshdl    文件:ParserToModelExtension.java   
public ParserToModelExtension(final BufferedTokenStream tokens) {
  this.tokens = tokens;
}
项目:org.pshdl    文件:ParserToModelExtension.java   
public static HDLPackage toHDL(final BufferedTokenStream tokens, final PSHDLLang.PsModelContext ctx, final String libURI, final String src) {
  return new ParserToModelExtension(tokens).toHDLPkg(ctx, libURI, src);
}
项目:org.pshdl    文件:ParserToModelExtension.java   
public static HDLExpression toHDLExpression(final BufferedTokenStream tokens, final PSHDLLang.PsExpressionContext ctx) {
  IHDLObject _hDL = new ParserToModelExtension(tokens).toHDL(ctx, false);
  return ((HDLExpression) _hDL);
}
项目:adl2-core    文件:AdlParserTest.java   
private static adlParser createAdlParser(String text) throws IOException {
    char[] chars = text.toCharArray();
    CharStream charStream = new ANTLRInputStream(chars, chars.length);
    Lexer lexer = new adlLexer(charStream);
    return new adlParser(new BufferedTokenStream(lexer));
}
项目:JavaSharp    文件:XmlEmittingVisitor.java   
XmlEmittingVisitor(ContentHandler contentHandler, BufferedTokenStream bufferedTokenStream) {
    this.contentHandler = contentHandler;
    this.bufferedTokenStream = bufferedTokenStream;
    cursor = -1;
}
项目:checkstyle-backport-jre6    文件:JavadocDetailNodeParser.java   
/**
 * Method to get the missed HTML tag to generate more informative error message for the user.
 * This method doesn't concern itself with
 * <a href="https://www.w3.org/TR/html51/syntax.html#void-elements">void elements</a>
 * since it is forbidden to close them.
 * Missed HTML tags for the following tags will <i>not</i> generate an error message from ANTLR:
 * {@code
 * <p>
 * <li>
 * <tr>
 * <td>
 * <th>
 * <body>
 * <colgroup>
 * <dd>
 * <dt>
 * <head>
 * <html>
 * <option>
 * <tbody>
 * <thead>
 * <tfoot>
 * }
 * @param exception {@code NoViableAltException} object catched while parsing javadoc
 * @return returns appropriate {@link Token} if a HTML close tag is missed;
 *     null otherwise
 */
private static Token getMissedHtmlTag(RecognitionException exception) {
    Token htmlTagNameStart = null;
    final Interval sourceInterval = exception.getCtx().getSourceInterval();
    final List<Token> tokenList = ((BufferedTokenStream) exception.getInputStream())
            .getTokens(sourceInterval.a, sourceInterval.b);
    final Deque<Token> stack = new ArrayDeque<Token>();
    for (int i = 0; i < tokenList.size(); i++) {
        final Token token = tokenList.get(i);
        if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME
                && tokenList.get(i - 1).getType() == JavadocTokenTypes.START) {
            stack.push(token);
        }
        else if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME && !stack.isEmpty()) {
            if (stack.peek().getText().equals(token.getText())) {
                stack.pop();
            }
            else {
                htmlTagNameStart = stack.pop();
            }
        }
    }
    if (htmlTagNameStart == null) {
        htmlTagNameStart = stack.pop();
    }
    return htmlTagNameStart;
}
项目:checkstyle    文件:JavadocDetailNodeParser.java   
/**
 * Method to get the missed HTML tag to generate more informative error message for the user.
 * This method doesn't concern itself with
 * <a href="https://www.w3.org/TR/html51/syntax.html#void-elements">void elements</a>
 * since it is forbidden to close them.
 * Missed HTML tags for the following tags will <i>not</i> generate an error message from ANTLR:
 * {@code
 * <p>
 * <li>
 * <tr>
 * <td>
 * <th>
 * <body>
 * <colgroup>
 * <dd>
 * <dt>
 * <head>
 * <html>
 * <option>
 * <tbody>
 * <thead>
 * <tfoot>
 * }
 * @param exception {@code NoViableAltException} object catched while parsing javadoc
 * @return returns appropriate {@link Token} if a HTML close tag is missed;
 *     null otherwise
 */
private static Token getMissedHtmlTag(RecognitionException exception) {
    Token htmlTagNameStart = null;
    final Interval sourceInterval = exception.getCtx().getSourceInterval();
    final List<Token> tokenList = ((BufferedTokenStream) exception.getInputStream())
            .getTokens(sourceInterval.a, sourceInterval.b);
    final Deque<Token> stack = new ArrayDeque<>();
    for (int i = 0; i < tokenList.size(); i++) {
        final Token token = tokenList.get(i);
        if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME
                && tokenList.get(i - 1).getType() == JavadocTokenTypes.START) {
            stack.push(token);
        }
        else if (token.getType() == JavadocTokenTypes.HTML_TAG_NAME && !stack.isEmpty()) {
            if (stack.peek().getText().equals(token.getText())) {
                stack.pop();
            }
            else {
                htmlTagNameStart = stack.pop();
            }
        }
    }
    if (htmlTagNameStart == null) {
        htmlTagNameStart = stack.pop();
    }
    return htmlTagNameStart;
}