List of usage examples for org.antlr.v4.runtime CommonTokenStream CommonTokenStream
public CommonTokenStream(TokenSource tokenSource)
From source file:notaql.engines.hbase.parser.path.HBaseOutputPathParser.java
License:Apache License
@Override public OutputPath parse(String enginePath, boolean relative) { final NotaQL2ColumnOutLexer lexer = new NotaQL2ColumnOutLexer(new ANTLRInputStream(enginePath)); final NotaQL2ColumnOutParser parser = new NotaQL2ColumnOutParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2ColumnOutParser.OutputPathContext outputPathContext = parser.outputPath(); return new HBaseOutputPathVisitor(this.transformationParser, relative).visit(outputPathContext); }
From source file:notaql.engines.json.path.JSONInputPathParser.java
License:Apache License
@Override public InputPath parse(String enginePath, boolean relative) { final NotaQL2DocumentInLexer lexer = new NotaQL2DocumentInLexer(new ANTLRInputStream(enginePath)); final NotaQL2DocumentInParser parser = new NotaQL2DocumentInParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2DocumentInParser.InputPathContext inputPathContext = parser.inputPath(); final List<InputPathStep> steps = inputPathContext.inputPathStep().stream() .map(s -> new JSONInputPathStepVisitor(this.transformationParser).visit(s)) .collect(Collectors.toList()); return new InputPath(relative, steps); }
From source file:notaql.engines.mongodb.parser.path.MongoDBInputPathParser.java
License:Apache License
@Override public InputPath parse(String enginePath, boolean relative) { final NotaQL2DocumentInLexer lexer = new NotaQL2DocumentInLexer(new ANTLRInputStream(enginePath)); final NotaQL2DocumentInParser parser = new NotaQL2DocumentInParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2DocumentInParser.InputPathContext inputPathContext = parser.inputPath(); final List<InputPathStep> steps = inputPathContext.inputPathStep().stream() .map(s -> new MongoDBInputPathStepVisitor(this.transformationParser).visit(s)) .collect(Collectors.toList()); return new InputPath(relative, steps); }
From source file:notaql.engines.mongodb.parser.path.MongoDBOutputPathParser.java
License:Apache License
@Override public OutputPath parse(String enginePath, boolean relative) { final NotaQL2DocumentOutLexer lexer = new NotaQL2DocumentOutLexer(new ANTLRInputStream(enginePath)); final NotaQL2DocumentOutParser parser = new NotaQL2DocumentOutParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2DocumentOutParser.OutputPathContext outputPathContext = parser.outputPath(); final List<OutputPathStep> steps = outputPathContext.outputPathStep().stream() .map(s -> new MongoDBOutputPathStepVisitor(this.transformationParser).visit(s)) .collect(Collectors.toList()); return new OutputPath(steps); }
From source file:notaql.engines.redis.parser.path.RedisInputPathParser.java
License:Apache License
@Override public InputPath parse(String enginePath, boolean relative) { final NotaQL2KeyValueInLexer lexer = new NotaQL2KeyValueInLexer(new ANTLRInputStream(enginePath)); final NotaQL2KeyValueInParser parser = new NotaQL2KeyValueInParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2KeyValueInParser.InputPathContext inputPathContext = parser.inputPath(); final RedisInputPathVisitor pathVisitor = new RedisInputPathVisitor(transformationParser, relative); final List<InputPathStep> steps = new LinkedList<>(pathVisitor.visit(inputPathContext).getPathSteps()); return new InputPath(relative, steps); }
From source file:notaql.engines.redis.parser.path.RedisOutputPathParser.java
License:Apache License
@Override public OutputPath parse(String enginePath, boolean relative) { final NotaQL2KeyValueOutLexer lexer = new NotaQL2KeyValueOutLexer(new ANTLRInputStream(enginePath)); final NotaQL2KeyValueOutParser parser = new NotaQL2KeyValueOutParser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2KeyValueOutParser.OutputPathContext outputPathContext = parser.outputPath(); return new RedisOutputPathVisitor(this.transformationParser).visit(outputPathContext); }
From source file:notaql.parser.NotaQLExpressionParser.java
License:Apache License
public static NotaQLExpression parse(String expression) { final NotaQL2Lexer lexer = new NotaQL2Lexer(new ANTLRInputStream(expression)); final NotaQL2Parser parser = new NotaQL2Parser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); // evaluate all transformations final NotaQL2Parser.NotaqlContext notaql = parser.notaql(); final List<NotaQL2Parser.TransformationContext> transformationContexts = notaql.transformation(); final List<Transformation> transformations = transformationContexts.stream() .map(ctx -> new TransformationParser(ctx).parse()).collect(Collectors.toList()); // join them to a complete notaql expression return new NotaQLExpression(transformations); }
From source file:notaql.parser.PredicateVisitor.java
License:Apache License
public Predicate evaluate(String predicate) { final NotaQL2Lexer lexer = new NotaQL2Lexer(new ANTLRInputStream(predicate)); final NotaQL2Parser parser = new NotaQL2Parser(new CommonTokenStream(lexer)); parser.addErrorListener(new NotaQLErrorListener(parser)); final NotaQL2Parser.PredicateContext predicateContext = parser.standalonePredicate().predicate(); return visit(predicateContext); }
From source file:ole.OLEModel.java
License:Open Source License
/** * Makes an OLEModel from OLE text//w w w. j av a2 s . c o m * @param text The OLE text * @return The resulting OLEModel */ public static OLEModel fromText(String text) { OLEModel model = new OLEModel(); CharStream cs = new ANTLRInputStream(text); OLELexer lexer = new OLELexer(cs); CommonTokenStream cts = new CommonTokenStream(lexer); OLEParser parser = new OLEParser(cts); parser.addErrorListener(new OLErrorListener()); ParseTreeWalker ptw = new ParseTreeWalker(); ParserRuleContext ctx = parser.start(); ptw.walk(new OLEWalkerListener(model), ctx); POWConsole.printInfo("Parsed entities: " + model.getEntities().toString()); return model; }
From source file:omc.corba.ScriptingHelper.java
License:Open Source License
/** Turns the given modelica expression - which should be an array - * into a flat List of Strings.//from w ww . ja va 2s . c om */ public static List<String> fromNestedArray(String modelicaExpr) { List<String> list = new ArrayList<>(); try { ListParser p = new ListParser(new CommonTokenStream( new ListLexer(new ANTLRInputStream(new ByteArrayInputStream(modelicaExpr.getBytes()))))); ListParser.ListContext listContext = p.list(); if (listContext != null) return fromNestedArray(listContext.listElement()); } catch (IOException e) { e.printStackTrace(); } return list; }