Search in sources :

Example 1 with LookAheadTerminalRuleCall

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

the class AbstractInternalContentAssistParser method createLookAheadTerminal.

@Override
public LookAheadTerminal createLookAheadTerminal(Token token) {
    Grammar grammar = getGrammar();
    String tokenName = getTokenNames()[token.getType()];
    tokenName = getValueForTokenName(tokenName);
    if (tokenName.charAt(0) == '\'') {
        LookaheadKeyword result = new LookaheadKeyword();
        result.setKeyword(tokenName.substring(1, tokenName.length() - 1));
        result.setToken(token);
        return result;
    }
    LookAheadTerminalRuleCall result = new LookAheadTerminalRuleCall();
    result.setToken(token);
    String ruleName = TokenTool.getLexerRuleName(tokenName);
    if (terminalRules == null)
        terminalRules = GrammarUtil.allTerminalRules(grammar);
    for (TerminalRule rule : terminalRules) {
        if (rule.getName().equalsIgnoreCase(ruleName)) {
            result.setRule(rule);
            return result;
        }
    }
    throw new IllegalArgumentException("tokenType " + token.getType() + " seems to be invalid.");
}
Also used : LookaheadKeyword(org.eclipse.xtext.ide.editor.contentassist.antlr.LookaheadKeyword) LookAheadTerminalRuleCall(org.eclipse.xtext.ide.editor.contentassist.antlr.LookAheadTerminalRuleCall) Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 2 with LookAheadTerminalRuleCall

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

the class FlexerBasedInternalContentAssistParser method createLookAheadTerminal.

@Override
public LookAheadTerminal createLookAheadTerminal(Token token) {
    Grammar grammar = getGrammar();
    String tokenName = getTokenDefMap().get(token.getType());
    if (tokenName.charAt(0) == '\'') {
        LookaheadKeyword result = new LookaheadKeyword();
        result.setKeyword(tokenName.substring(1, tokenName.length() - 1));
        result.setToken(token);
        return result;
    }
    LookAheadTerminalRuleCall result = new LookAheadTerminalRuleCall();
    result.setToken(token);
    String ruleName = tokenName.substring(5);
    if (terminalRules == null)
        terminalRules = GrammarUtil.allTerminalRules(grammar);
    for (TerminalRule rule : terminalRules) {
        if (rule.getName().equalsIgnoreCase(ruleName)) {
            result.setRule(rule);
            return result;
        }
    }
    throw new IllegalArgumentException("tokenType " + token.getType() + " seems to be invalid.");
}
Also used : LookaheadKeyword(org.eclipse.xtext.ide.editor.contentassist.antlr.LookaheadKeyword) LookAheadTerminalRuleCall(org.eclipse.xtext.ide.editor.contentassist.antlr.LookAheadTerminalRuleCall) Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule)

Aggregations

Grammar (org.eclipse.xtext.Grammar)2 TerminalRule (org.eclipse.xtext.TerminalRule)2 LookAheadTerminalRuleCall (org.eclipse.xtext.ide.editor.contentassist.antlr.LookAheadTerminalRuleCall)2 LookaheadKeyword (org.eclipse.xtext.ide.editor.contentassist.antlr.LookaheadKeyword)2