Search in sources :

Example 11 with Lexer

use of org.eclipse.xtext.parser.antlr.Lexer 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 12 with Lexer

use of org.eclipse.xtext.parser.antlr.Lexer in project xtext-xtend by eclipse.

the class PresentationDamagerTest method createDocument.

@Override
public Document createDocument(final String before) throws Exception {
    XtextDocument _xblockexpression = null;
    {
        XtendDocumentTokenSource _xtendDocumentTokenSource = new XtendDocumentTokenSource();
        final Procedure1<XtendDocumentTokenSource> _function = (XtendDocumentTokenSource it) -> {
            AntlrTokenDefProvider _antlrTokenDefProvider = new AntlrTokenDefProvider();
            final Procedure1<AntlrTokenDefProvider> _function_1 = (AntlrTokenDefProvider it_1) -> {
                XtendAntlrTokenFileProvider _xtendAntlrTokenFileProvider = new XtendAntlrTokenFileProvider();
                it_1.setAntlrTokenFileProvider(_xtendAntlrTokenFileProvider);
            };
            AntlrTokenDefProvider _doubleArrow = ObjectExtensions.<AntlrTokenDefProvider>operator_doubleArrow(_antlrTokenDefProvider, _function_1);
            it.setTokenDefProvider(_doubleArrow);
            final Provider<Lexer> _function_2 = () -> {
                return this.createLexer();
            };
            it.setLexer(_function_2);
            it.setFlexerFactory(this.flexerFactory);
        };
        final XtendDocumentTokenSource source = ObjectExtensions.<XtendDocumentTokenSource>operator_doubleArrow(_xtendDocumentTokenSource, _function);
        final XtextDocument document = new XtextDocument(source, null, this.outdatedStateManager, this.operationCanceledManager);
        document.set(before);
        _xblockexpression = document;
    }
    return _xblockexpression;
}
Also used : AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) InternalXtendLexer(org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XtendDocumentTokenSource(org.eclipse.xtend.ide.editor.model.XtendDocumentTokenSource) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtendAntlrTokenFileProvider(org.eclipse.xtend.core.parser.antlr.XtendAntlrTokenFileProvider)

Example 13 with Lexer

use of org.eclipse.xtext.parser.antlr.Lexer 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

Lexer (org.eclipse.xtext.parser.antlr.Lexer)13 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)10 CommonToken (org.antlr.runtime.CommonToken)7 InternalXtendLexer (org.eclipse.xtend.core.parser.antlr.internal.InternalXtendLexer)7 Token (org.antlr.runtime.Token)6 Test (org.junit.Test)5 CharStream (org.antlr.runtime.CharStream)2 XtendAntlrTokenFileProvider (org.eclipse.xtend.core.parser.antlr.XtendAntlrTokenFileProvider)2 XtendDocumentTokenSource (org.eclipse.xtend.ide.editor.model.XtendDocumentTokenSource)2 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)2 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 IFile (org.eclipse.core.resources.IFile)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 DisabledAntlrLexer (org.eclipse.xtend.core.parser.antlr.internal.DisabledAntlrLexer)1 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)1 XtextTokenStream (org.eclipse.xtext.parser.antlr.XtextTokenStream)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 TextRegion (org.eclipse.xtext.util.TextRegion)1