Search in sources :

Example 16 with ANTLRStringStream

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

the class AbstractSmokeTest method testSkipTokensInBetweenWithoutResourceSet.

@Test
public void testSkipTokensInBetweenWithoutResourceSet() 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);
            doParseAndCheckForSmokeWithoutResourceSet(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 17 with ANTLRStringStream

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

the class SmokeTest method testResourceUpdateSkipTokensInBetween.

@Test
public void testResourceUpdateSkipTokensInBetween() 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();
            }
        }
        LazyLinkingResource resource = createResource(string);
        CommonToken prev = null;
        for (CommonToken token : tokenList) {
            logProgress(token);
            if (prev == null) {
                compareWithNewResource(resource, 0, token.getText().length(), "");
            } else {
                int offset = prev.getStartIndex();
                int length = token.getText().length();
                if (offset + length < string.length())
                    compareWithNewResource(resource, offset, length, prev.getText());
            }
            prev = token;
        }
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) Token(org.antlr.runtime.Token) CommonToken(org.antlr.runtime.CommonToken) CommonToken(org.antlr.runtime.CommonToken) Test(org.junit.Test)

Example 18 with ANTLRStringStream

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

the class LexingTest method assertLexing.

protected void assertLexing(String input, Pair<String, String>... expectedTokens) {
    Lexer lexer = new InternalXtendLexer(null);
    CharStream stream = new ANTLRStringStream(input);
    lexer.setCharStream(stream);
    XtextTokenStream tokenStream = new XtextTokenStream(lexer, tokenDefProvider);
    List<?> tokens = tokenStream.getTokens();
    assertEquals(input + " / " + tokens, expectedTokens.length, tokens.size());
    for (int i = 0; i < tokens.size(); i++) {
        Token token = (Token) tokens.get(i);
        assertEquals(token.toString(), expectedTokens[i].getFirst(), token.getText());
        final String expected = expectedTokens[i].getSecond();
        String actual = tokenDefProvider.getTokenDefMap().get(token.getType());
        assertEquals("expected " + expected + " but was " + actual, expected, actual);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) XtextTokenStream(org.eclipse.xtext.parser.antlr.XtextTokenStream) Token(org.antlr.runtime.Token) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) CharStream(org.antlr.runtime.CharStream)

Example 19 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project SQLWindowing by hbutani.

the class WindowingShell method checkQuery.

public void checkQuery(String query) throws WindowingException {
    Windowing2Lexer lexer;
    CommonTokenStream tokens;
    Windowing2Parser parser = null;
    @SuppressWarnings("unused") CommonTree t;
    // CommonTreeNodeStream nodes;
    String err;
    try {
        lexer = new Windowing2Lexer(new ANTLRStringStream(query));
        tokens = new CommonTokenStream(lexer);
        parser = new Windowing2Parser(tokens);
        parser.setTreeAdaptor(TranslateUtils.adaptor);
        t = (CommonTree) parser.query().getTree();
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
    } catch (Throwable te) {
        err = parser.getWindowingParseErrors();
        if (err != null) {
            throw new WindowingException(err);
        }
        throw new WindowingException("Parse Error:" + te.toString(), te);
    }
}
Also used : Windowing2Lexer(com.sap.hadoop.windowing.parser.Windowing2Lexer) ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) Windowing2Parser(com.sap.hadoop.windowing.parser.Windowing2Parser) WindowingException(com.sap.hadoop.windowing.WindowingException)

Example 20 with ANTLRStringStream

use of org.antlr.runtime.ANTLRStringStream in project Palladio-Editors-Sirius by PalladioSimulator.

the class PCMServices method validExpression.

/**
 * Parses an stochastic expression to determine whether it is valid.
 *
 * @param the
 *            expressionString
 * @return the validity
 */
private boolean validExpression(final String expressionString) {
    final MyPCMStoExLexer lexer = new MyPCMStoExLexer(new ANTLRStringStream(expressionString));
    final MyPCMStoExParser parser = new MyPCMStoExParser(new CommonTokenStream(lexer));
    try {
        parser.expression();
    } catch (final RecognitionException e1) {
        return false;
    }
    if (lexer.hasErrors() || parser.hasErrors()) {
        return false;
    }
    return true;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) MyPCMStoExParser(org.palladiosimulator.pcm.stochasticexpressions.parser.MyPCMStoExParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) MyPCMStoExLexer(org.palladiosimulator.pcm.stochasticexpressions.parser.MyPCMStoExLexer) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)60 CommonTokenStream (org.antlr.runtime.CommonTokenStream)36 Test (org.junit.Test)20 CommonToken (org.antlr.runtime.CommonToken)15 Token (org.antlr.runtime.Token)13 CharStream (org.antlr.runtime.CharStream)11 Lexer (org.eclipse.xtext.parser.antlr.Lexer)10 RecognitionException (org.antlr.runtime.RecognitionException)9 InternalSimpleExpressionsTestLanguageLexer (org.eclipse.xtext.testlanguages.parser.antlr.internal.InternalSimpleExpressionsTestLanguageLexer)8 CommonTree (org.antlr.runtime.tree.CommonTree)6 ActionSplitter (org.antlr.v4.parse.ActionSplitter)6 TokenStream (org.antlr.runtime.TokenStream)5 InternalXtendLexer (org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)4 WindowingException (com.sap.hadoop.windowing.WindowingException)3 ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)3 ExprParser (org.apache.drill.common.expression.parser.ExprParser)3 CeylonLexer (com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer)2 CeylonParser (com.redhat.ceylon.compiler.typechecker.parser.CeylonParser)2 LineMap (com.sun.tools.javac.util.Position.LineMap)2 File (java.io.File)2