Search in sources :

Example 71 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project cuba by cuba-platform.

the class Jpa2GrammarTest method testMemberOf.

@Test
@Disabled
public void testMemberOf() throws Exception {
    String query = "where p.owner.id = :userParam or (select u from tamsy$User u where u.id = :userParam) member of p.developers";
    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();
    Assertions.assertTrue(isValid((CommonTree) aReturn.getTree()));
    testQuery("SELECT d FROM app$Department d WHERE (select e from app$Employee e where e.id = :eParam) MEMBER OF e.employees");
    testQuery("SELECT e FROM app$Employee e WHERE 'write code' MEMBER OF e.codes");
    testQuery("SELECT e FROM app$Employee e WHERE 'write code' NOT MEMBER OF e.codes");
}
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.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 72 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream 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();
    Assertions.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.jupiter.api.Test)

Example 73 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project cuba by cuba-platform.

the class Jpa2GrammarTest method testQuery.

private void testQuery(String query) throws RecognitionException {
    CharStream cs = new AntlrNoCaseStringStream(query);
    JPA2Lexer lexer = new JPA2Lexer(cs);
    TokenStream tstream = new CommonTokenStream(lexer);
    JPA2Parser jpa2Parser = new JPA2Parser(tstream);
    JPA2Parser.ql_statement_return aReturn = jpa2Parser.ql_statement();
    Assertions.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)

Example 74 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project xtext-core by eclipse.

the class LexerSLComment method testSlComment.

@Test
public void testSlComment() {
    String model = "//sl comment\na";
    InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
    lexer.setCharStream(new ANTLRStringStream(model));
    CommonTokenStream stream = new CommonTokenStream(lexer);
    Object inLineComment = stream.getTokens().get(0);
    assertTrue(inLineComment instanceof CommonToken);
    assertEquals(InternalSimpleExpressionsTestLanguageLexer.RULE_SL_COMMENT, ((CommonToken) inLineComment).getType());
}
Also used : InternalSimpleExpressionsTestLanguageLexer(org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 75 with CommonTokenStream

use of org.antlr.runtime.CommonTokenStream in project xtext-core by eclipse.

the class LexerSLComment method testSlCommentEOF.

/**
 * see BUG 234135: Comments on EOF not detected
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=234135
 */
@Test
public void testSlCommentEOF() {
    String model = "a\n//sl comment";
    InternalSimpleExpressionsTestLanguageLexer lexer = new InternalSimpleExpressionsTestLanguageLexer();
    lexer.setCharStream(new ANTLRStringStream(model));
    CommonTokenStream stream = new CommonTokenStream(lexer);
    Object eofLineComment = stream.getTokens().get(2);
    assertTrue(eofLineComment instanceof CommonToken);
    CommonToken commonToken = (CommonToken) eofLineComment;
    int type = commonToken.getType();
    assertEquals(InternalSimpleExpressionsTestLanguageLexer.RULE_SL_COMMENT, type);
}
Also used : InternalSimpleExpressionsTestLanguageLexer(org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Aggregations

CommonTokenStream (org.antlr.runtime.CommonTokenStream)93 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)62 RecognitionException (org.antlr.runtime.RecognitionException)25 CharStream (org.antlr.runtime.CharStream)22 CommonTree (org.antlr.runtime.tree.CommonTree)21 TokenStream (org.antlr.runtime.TokenStream)17 File (java.io.File)12 Test (org.junit.Test)12 CommonToken (org.antlr.runtime.CommonToken)10 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)10 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)10 ExprParser (org.apache.drill.common.expression.parser.ExprParser)10 FileInputStream (java.io.FileInputStream)9 InputStream (java.io.InputStream)8 ANTLRInputStream (org.antlr.runtime.ANTLRInputStream)8 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 InputStreamReader (java.io.InputStreamReader)6 Token (org.antlr.runtime.Token)6 JPA2Lexer (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Lexer)5 JPA2Parser (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)5