Search in sources :

Example 96 with ANTLRStringStream

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

the class AbstractSmokeTest method testSkipTokensInBetween.

@Test
public void testSkipTokensInBetween() throws Exception {
    for (String string : smokeTestModels) {
        List<CommonToken> tokenList = Lists.newArrayList();
        {
            Lexer lexer = lexerProvider.get();
            lexer.setCharStream(new ANTLRStringStream(string));
            Token token = lexer.nextToken();
            while (token != Token.EOF_TOKEN) {
                tokenList.add((CommonToken) token);
                token = lexer.nextToken();
            }
        }
        for (CommonToken token : tokenList) {
            int start = token.getStartIndex();
            int length = token.getText().length();
            logProgress(token);
            doParseAndCheckForSmoke(string.substring(0, start) + string.substring(start + length));
        }
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 97 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project alfresco-remote-api by Alfresco.

the class WhereCompiler method compileWhereClause.

public static CommonTree compileWhereClause(String expression) throws RecognitionException {
    // lexer splits input into tokens
    ANTLRStringStream input = new ANTLRStringStream(expression);
    TokenStream tokens = new CommonTokenStream(new WhereClauseLexer(input));
    // parser generates abstract syntax tree
    WhereClauseParser parser = new WhereClauseParser(tokens);
    WhereClauseParser.whereclause_return ret = parser.whereclause();
    // acquire parse result
    CommonTree ast = (CommonTree) ret.getTree();
    if (logger.isDebugEnabled())
        print(ast, 0);
    return ast;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) TokenStream(org.antlr.runtime.TokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) WhereClauseParser(org.alfresco.rest.antlr.WhereClauseParser) WhereClauseLexer(org.alfresco.rest.antlr.WhereClauseLexer)

Example 98 with ANTLRStringStream

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

the class AbstractTemplateProposalConflictHelper method initTokenSource.

@Override
protected void initTokenSource(String text, TokenSource tokenSource, ContentAssistContext context) {
    EObject currentModel = context.getLastCompleteNode().getSemanticElement();
    Variable variable = currentModel != null ? EcoreUtil2.getContainerOfType(currentModel, Variable.class) : null;
    TemplateBody body = currentModel != null ? EcoreUtil2.getContainerOfType(currentModel, TemplateBody.class) : null;
    Lexer lexer = (Lexer) tokenSource;
    CharStream stream = new ANTLRStringStream(text);
    lexer.setCharStream(stream);
    initLexer(lexer, body != null, variable != null);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Lexer(org.eclipse.xtext.parser.antlr.Lexer) Variable(org.eclipse.xtext.ui.codetemplates.templates.Variable) EObject(org.eclipse.emf.ecore.EObject) TemplateBody(org.eclipse.xtext.ui.codetemplates.templates.TemplateBody) CharStream(org.antlr.runtime.CharStream)

Example 99 with ANTLRStringStream

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

the class TemplateBodyHighlighter method doProvideHighlightingFor.

protected void doProvideHighlightingFor(String body, org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor acceptor) {
    lexer.setCharStream(new ANTLRStringStream(body));
    Token token = lexer.nextToken();
    while (token != Token.EOF_TOKEN) {
        String id = tokenIdMapper.getId(token.getType());
        int offset = TokenTool.getOffset(token);
        int length = TokenTool.getLength(token);
        acceptor.addPosition(offset, length, id);
        token = lexer.nextToken();
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Token(org.antlr.runtime.Token)

Example 100 with ANTLRStringStream

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

the class DocumentTokenSource method createLexer.

/**
 * @deprecated use {@link #createTokenSource(String)} instead.
 */
@Deprecated
protected Lexer createLexer(String string) {
    Lexer l = lexer.get();
    l.setCharStream(new ANTLRStringStream(string));
    return l;
}
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