List of usage examples for org.antlr.v4.runtime ListTokenSource ListTokenSource
public ListTokenSource(List<? extends Token> tokens)
From source file:ai.grakn.graql.internal.parser.QueryParser.java
License:Open Source License
/** * Consume a single query from the given token stream. * * @param tokenStream the {@link TokenStream} to consume * @return a new {@link TokenSource} containing the tokens comprising the query *///w w w . j a v a 2 s . co m private TokenSource consumeOneQuery(TokenStream tokenStream) { List<Token> tokens = new ArrayList<>(); boolean startedQuery = false; while (true) { Token token = tokenStream.LT(1); boolean isNewQuery = NEW_QUERY_TOKENS.contains(token.getType()); boolean isEndOfTokenStream = token.getType() == IntStream.EOF; boolean isEndOfFirstQuery = startedQuery && isNewQuery; // Stop parsing tokens after reaching the end of the first query if (isEndOfTokenStream || isEndOfFirstQuery) break; if (isNewQuery) startedQuery = true; tokens.add(token); tokenStream.consume(); } return new ListTokenSource(tokens); }