Search in sources :

Example 1 with JPA2Parser

use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.

the class Jpa2GrammarTest method testEscape.

@Test
public void testEscape() throws Exception {
    String query = "c.name like :pattern escape '/'";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.like_expression_return aReturn = jpa2Parser.like_expression();
    Assert.assertNotNull(aReturn);
    query = "c.name like :pattern escape '.'";
    cs = new AntlrNoCaseStringStream(query);
    lexer = new JPA2Lexer(cs);
    tstream = new CommonTokenStream(lexer);
    jpa2Parser = new JPA2Parser(tstream);
    aReturn = jpa2Parser.like_expression();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 2 with JPA2Parser

use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.

the class Parser method parse.

public static CommonTree parse(String input, boolean failOnErrors) throws RecognitionException {
    JPA2Parser parser = createParser(input);
    JPA2Parser.ql_statement_return aReturn = parser.ql_statement();
    CommonTree tree = (CommonTree) aReturn.getTree();
    if (failOnErrors) {
        checkTreeForExceptions(input, tree);
    }
    return tree;
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)

Example 3 with JPA2Parser

use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.

the class Parser method parseSelectionSource.

public static CommonTree parseSelectionSource(String input) throws RecognitionException {
    JPA2Parser parser = createParser(input);
    JPA2Parser.identification_variable_declaration_or_collection_member_declaration_return aReturn = parser.identification_variable_declaration_or_collection_member_declaration();
    CommonTree tree = (CommonTree) aReturn.getTree();
    checkTreeForExceptions(input, tree);
    return tree;
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)

Example 4 with JPA2Parser

use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.

the class Jpa2GrammarTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    String query = "update sec$User u set u.group = :group where u.id = :userId";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.update_statement_return aReturn = jpa2Parser.update_statement();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Example 5 with JPA2Parser

use of com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser in project cuba by cuba-platform.

the class Jpa2GrammarTest method testTypeField.

@Test
public void testTypeField() throws Exception {
    String query = "where e.model.type = :component$filter.model_type89015";
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.where_clause_return aReturn = jpa2Parser.where_clause();
    Assert.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JPA2Lexer(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer) CharStream(org.antlr.runtime.CharStream) Test(org.junit.Test)

Aggregations

JPA2Parser (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)10 CommonTree (org.antlr.runtime.tree.CommonTree)9 JPA2Lexer (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer)6 CharStream (org.antlr.runtime.CharStream)6 CommonTokenStream (org.antlr.runtime.CommonTokenStream)6 TokenStream (org.antlr.runtime.TokenStream)6 Test (org.junit.Test)4 JoinVariableNode (com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)1 Ignore (org.junit.Ignore)1