Search in sources :

Example 36 with Tree

use of org.antlr.v4.runtime.tree.Tree in project nikita-noark5-core by HiOA-ABI.

the class OdataTest method testOdata.

@RequestMapping(method = RequestMethod.GET, value = "arkivstruktur/{\\w*}")
public ResponseEntity<String> testOdata(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String uqueryString = request.getQueryString();
    String decoded = URLDecoder.decode(uqueryString, UTF_8);
    StringBuffer originalRequest = request.getRequestURL();
    originalRequest.append("?" + decoded);
    CharStream stream = CharStreams.fromString(originalRequest.toString());
    ODataLexer lexer = new ODataLexer(stream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ODataParser parser = new ODataParser(tokens);
    ParseTree tree = parser.odataURL();
    ParseTreeWalker walker = new ParseTreeWalker();
    // Make the HQL Statement
    NikitaODataToHQLWalker hqlWalker = new NikitaODataToHQLWalker();
    walker.walk(hqlWalker, tree);
    Session session = entityManager.unwrap(org.hibernate.Session.class);
    Query query = hqlWalker.getHqlStatment(session);
    String queryString = query.getQueryString();
    System.out.println(queryString);
    List<NoarkEntity> list = query.getResultList();
    return ResponseEntity.status(HttpStatus.CREATED).body(list.toString());
}
Also used : ODataParser(nikita.webapp.odata.ODataParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Query(org.hibernate.query.Query) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) CharStream(org.antlr.v4.runtime.CharStream) ODataLexer(nikita.webapp.odata.ODataLexer) NikitaODataToHQLWalker(nikita.webapp.odata.NikitaODataToHQLWalker) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Session(org.hibernate.Session) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Tree

use of org.antlr.v4.runtime.tree.Tree in project oxTrust by GluuFederation.

the class ScimFilterParserService method walkTree.

private void walkTree(String filter, ScimFilterBaseListener listener) throws SCIMException {
    ScimFilterErrorListener errorListener = new ScimFilterErrorListener();
    ParseTree tree = getParseTree(filter, errorListener);
    checkParsingErrors(errorListener);
    ParseTreeWalker.DEFAULT.walk(listener, tree);
}
Also used : ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 38 with Tree

use of org.antlr.v4.runtime.tree.Tree in project oxTrust by GluuFederation.

the class ScimFilterParserService method getParseTree.

public ParseTree getParseTree(String filter) throws Exception {
    ScimFilterErrorListener errorListener = new ScimFilterErrorListener();
    ParseTree tree = getParseTree(filter, errorListener);
    checkParsingErrors(errorListener);
    return tree;
}
Also used : ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 39 with Tree

use of org.antlr.v4.runtime.tree.Tree in project grakn by graknlabs.

the class TemplateParser method parseTemplate.

/**
 * Parse and resolve a graql template.
 * @param templateString a string representing a graql template
 * @param data data to use in template
 * @return resolved graql query string
 */
public String parseTemplate(String templateString, Map<String, Object> data) {
    GraqlErrorListener errorListener = GraqlErrorListener.of(templateString);
    CommonTokenStream tokens = lexGraqlTemplate(templateString, errorListener);
    ParseTree tree = parseGraqlTemplate(tokens, errorListener);
    TemplateVisitor visitor = new TemplateVisitor(tokens, data, macros);
    return visitor.visit(tree).toString();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) GraqlErrorListener(ai.grakn.graql.internal.parser.GraqlErrorListener) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 40 with Tree

use of org.antlr.v4.runtime.tree.Tree in project drools by kiegroup.

the class FEELParserTest method parse.

private BaseNode parse(String input, Map<String, Type> inputTypes) {
    FEEL_1_1Parser parser = FEELParser.parse(null, input, inputTypes, Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
    ParseTree tree = parser.expression();
    ASTBuilderVisitor v = new ASTBuilderVisitor(inputTypes);
    BaseNode expr = v.visit(tree);
    return expr;
}
Also used : BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)30 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)21 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)15 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)12 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)9 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)6 Tree (org.antlr.v4.runtime.tree.Tree)6 IOException (java.io.IOException)5 Tree (org.antlr.runtime.tree.Tree)4 ParserInterpreter (org.antlr.v4.runtime.ParserInterpreter)4 RecognitionException (org.antlr.v4.runtime.RecognitionException)4 Rectangle2D (java.awt.geom.Rectangle2D)3 FileInputStream (java.io.FileInputStream)3 Method (java.lang.reflect.Method)3 Map (java.util.Map)3 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)3