Search in sources :

Example 1 with DSWrapperLexer

use of queryserver.parser.DSWrapperLexer in project java by wavefrontHQ.

the class AbstractIngesterFormatter method getQueue.

protected Queue<Token> getQueue(String input) {
    DSWrapperLexer lexer = dsWrapperLexerThreadLocal.get();
    lexer.setInputStream(new ANTLRInputStream(input));
    CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
    commonTokenStream.fill();
    List<Token> tokens = commonTokenStream.getTokens();
    if (tokens.isEmpty()) {
        throw new RuntimeException("Could not parse: " + input);
    }
    // this is sensitive to the grammar in DSQuery.g4. We could just use the visitor but doing so
    // means we need to be creating the AST and instead we could just use the lexer. in any case,
    // we don't expect the graphite format to change anytime soon.
    // filter all EOF tokens first.
    Queue<Token> queue = tokens.stream().filter(t -> t.getType() != Lexer.EOF).collect(Collectors.toCollection(ArrayDeque::new));
    return queue;
}
Also used : ReportSourceTag(wavefront.report.ReportSourceTag) Token(org.antlr.v4.runtime.Token) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Supplier(java.util.function.Supplier) BaseErrorListener(org.antlr.v4.runtime.BaseErrorListener) ArrayList(java.util.ArrayList) Lexer(org.antlr.v4.runtime.Lexer) Lists(com.google.common.collect.Lists) DateUtils(org.apache.commons.lang.time.DateUtils) Matcher(java.util.regex.Matcher) Map(java.util.Map) ReportPoint(wavefront.report.ReportPoint) Nullable(javax.annotation.Nullable) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) Recognizer(org.antlr.v4.runtime.Recognizer) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) DSWrapperLexer(queryserver.parser.DSWrapperLexer) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) RecognitionException(org.antlr.v4.runtime.RecognitionException) Preconditions(com.google.common.base.Preconditions) Queue(java.util.Queue) Pattern(java.util.regex.Pattern) ArrayDeque(java.util.ArrayDeque) Histogram(wavefront.report.Histogram) HistogramType(wavefront.report.HistogramType) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) DSWrapperLexer(queryserver.parser.DSWrapperLexer) Token(org.antlr.v4.runtime.Token) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 BaseErrorListener (org.antlr.v4.runtime.BaseErrorListener)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Lexer (org.antlr.v4.runtime.Lexer)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 Recognizer (org.antlr.v4.runtime.Recognizer)1