Search in sources :

Example 1 with FollowElement

use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project xtext-eclipse by eclipse.

the class Bug303200Test method testBug303200_02.

@Test
public void testBug303200_02() throws Exception {
    Bug303200TestLanguageParser parser = get(Bug303200TestLanguageParser.class);
    Collection<FollowElement> elements = parser.getFollowElements("function f() {", false);
    for (FollowElement element : elements) {
        recursiveTestFollowElements(parser, element);
    }
}
Also used : Bug303200TestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.Bug303200TestLanguageParser) FollowElement(org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement) Test(org.junit.Test)

Example 2 with FollowElement

use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project xtext-eclipse by eclipse.

the class Bug303200Test method testBug303200_01.

@Test
public void testBug303200_01() throws Exception {
    Bug303200TestLanguageParser parser = get(Bug303200TestLanguageParser.class);
    Collection<FollowElement> followElements = parser.getFollowElements("function f() {", false);
    assertEquals(4, followElements.size());
}
Also used : Bug303200TestLanguageParser(org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.Bug303200TestLanguageParser) FollowElement(org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement) Test(org.junit.Test)

Example 3 with FollowElement

use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project xtext-eclipse by eclipse.

the class Bug303200Test method recursiveTestFollowElements.

protected void recursiveTestFollowElements(Bug303200TestLanguageParser parser, FollowElement element) {
    if (element.getLookAhead() > 1) {
        Collection<FollowElement> elements = parser.getFollowElements(element);
        for (FollowElement followElement : elements) {
            assertTrue(followElement.getLookAhead() < element.getLookAhead());
            recursiveTestFollowElements(parser, followElement);
        }
    }
}
Also used : FollowElement(org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement)

Example 4 with FollowElement

use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project xtext-xtend by eclipse.

the class FlexerBasedContentAssistContextFactory method createContextsForLastCompleteNode.

@Override
protected void createContextsForLastCompleteNode(EObject previousModel, boolean strict) {
    String currentNodePrefix = getPrefix(currentNode);
    if (!Strings.isEmpty(currentNodePrefix) && !currentNode.getText().equals(currentNodePrefix)) {
        InternalFlexer flexer = flexerFactory.createFlexer(new StringReader(currentNodePrefix));
        try {
            int token = flexer.advance();
            if (token == Token.EOF) {
                // error case - nothing could be parsed
                return;
            }
            while (token != Token.EOF) {
                if (isErrorToken(token))
                    return;
                token = flexer.advance();
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            return;
        }
    }
    String prefix = "";
    Collection<FollowElement> followElements = parseFollowElements(completionOffset, strict);
    // String completeInput = viewer.getDocument().get(0, completionOffset);
    // Collection<FollowElement> followElements = parser.getFollowElements(completeInput, strict);
    doCreateContexts(lastCompleteNode, currentNode, prefix, previousModel, followElements);
}
Also used : StringReader(java.io.StringReader) InternalFlexer(org.eclipse.xtend.core.parser.InternalFlexer) IOException(java.io.IOException) FollowElement(org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement)

Example 5 with FollowElement

use of org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement in project n4js by eclipse.

the class ContentAssistContextFactory 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) {
            // error case - nothing could be parsed
            return;
        }
        while (token != Token.EOF_TOKEN) {
            if (isErrorToken(token))
                return;
            token = lexer.nextToken();
        }
    }
    String prefix = "";
    Collection<FollowElement> followElements = getParser().getFollowElements(rootNode, 0, completionOffset, strict);
    doCreateContexts(lastCompleteNode, currentNode, prefix, previousModel, followElements);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) Token(org.antlr.runtime.Token) FollowElement(org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement)

Aggregations

FollowElement (org.eclipse.xtext.ide.editor.contentassist.antlr.FollowElement)13 AbstractElement (org.eclipse.xtext.AbstractElement)3 Bug303200TestLanguageParser (org.eclipse.xtext.ui.tests.editor.contentassist.ide.contentassist.antlr.Bug303200TestLanguageParser)3 Test (org.junit.Test)3 Token (org.antlr.runtime.Token)2 TokenSource (org.antlr.runtime.TokenSource)2 EObject (org.eclipse.emf.ecore.EObject)2 ParserRule (org.eclipse.xtext.ParserRule)2 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)2 INode (org.eclipse.xtext.nodemodel.INode)2 IUnorderedGroupHelper (org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 BaseRecognizer (org.antlr.runtime.BaseRecognizer)1 CommonToken (org.antlr.runtime.CommonToken)1 InternalFlexer (org.eclipse.xtend.core.parser.InternalFlexer)1 Assignment (org.eclipse.xtext.Assignment)1 Group (org.eclipse.xtext.Group)1