Search in sources :

Example 86 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project drools by kiegroup.

the class JavaExprAnalyzer method parse.

private JavaParser parse(final String expr) {
    final CharStream charStream = new ANTLRStringStream(expr);
    final JavaLexer lexer = new JavaLexer(charStream);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    return new JavaParser(tokenStream);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) JavaParser(org.drools.compiler.rule.builder.dialect.java.parser.JavaParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) JavaLexer(org.drools.compiler.rule.builder.dialect.java.parser.JavaLexer) CharStream(org.antlr.runtime.CharStream)

Example 87 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project drools by kiegroup.

the class RuleParserTest method testChunkWithParens.

@Test
public void testChunkWithParens() throws Exception {
    String input = "(fnord())";
    createParser(new ANTLRStringStream(input));
    String returnData = parser.chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
    assertEquals("fnord()", returnData);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Test(org.junit.Test)

Example 88 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project drools by kiegroup.

the class RuleParserTest method testChunkWithParensAndQuotedString.

@Test
public void testChunkWithParensAndQuotedString() throws Exception {
    String input = "( fnord( \"cheese\" ) )";
    createParser(new ANTLRStringStream(input));
    String returnData = parser.chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
    assertEquals("fnord( \"cheese\" )", returnData);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Test(org.junit.Test)

Example 89 with ANTLRStringStream

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

the class PartialContentAssistContextFactory method createContextsForLastCompleteNode.

@Override
protected void createContextsForLastCompleteNode(EObject previousModel, boolean strict) {
    String currentNodePrefix = getPrefix(currentNode);
    if (!Strings.isEmpty(currentNodePrefix) && !currentNode.getText().equals(currentNodePrefix)) {
        lexer.setCharStream(new ANTLRStringStream(currentNodePrefix));
        Token token = lexer.nextToken();
        if (token == Token.EOF_TOKEN) {
            return;
        }
        while (token != Token.EOF_TOKEN) {
            if (isErrorToken(token)) {
                return;
            }
            token = lexer.nextToken();
        }
    }
    String prefix = "";
    Collection<FollowElement> followElements = parseFollowElements(completionOffset, strict);
    doCreateContexts(lastCompleteNode, currentNode, prefix, previousModel, followElements);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Token(org.antlr.runtime.Token)

Example 90 with ANTLRStringStream

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

the class AbstractLexerBasedConverter method getTokenSource.

protected TokenSource getTokenSource(String escapedValue) {
    Lexer result = getLexer();
    if (result == null)
        return null;
    result.setCharStream(new ANTLRStringStream(escapedValue));
    return result;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Lexer(org.eclipse.xtext.parser.antlr.Lexer)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)117 CommonTokenStream (org.antlr.runtime.CommonTokenStream)63 Token (org.antlr.runtime.Token)30 Test (org.junit.Test)28 CharStream (org.antlr.runtime.CharStream)24 CommonToken (org.antlr.runtime.CommonToken)20 RecognitionException (org.antlr.runtime.RecognitionException)18 Lexer (org.eclipse.xtext.parser.antlr.Lexer)16 ActionSplitter (org.antlr.v4.parse.ActionSplitter)12 TokenStream (org.antlr.runtime.TokenStream)10 CommonTree (org.antlr.runtime.tree.CommonTree)10 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)10 ExprParser (org.apache.drill.common.expression.parser.ExprParser)10 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 File (java.io.File)4 ArrayList (java.util.ArrayList)4 CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)4 Tree (org.antlr.runtime.tree.Tree)4 ExprParser.parse_return (org.apache.drill.common.expression.parser.ExprParser.parse_return)4 ApexLexer (apex.jorje.parser.impl.ApexLexer)3