Search in sources :

Example 71 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class PsiAntlrGrammarGenerator method compileParserMembers.

@Override
protected String compileParserMembers(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("@parser::members {");
    _builder.newLine();
    _builder.newLine();
    {
        boolean _isBacktrack = options.isBacktrack();
        if (_isBacktrack) {
            _builder.append("/*");
            _builder.newLine();
            _builder.append("  ");
            _builder.append("This grammar contains a lot of empty actions to work around a bug in ANTLR.");
            _builder.newLine();
            _builder.append("  ");
            _builder.append("Otherwise the ANTLR tool will create synpreds that cannot be compiled in some rare cases.");
            _builder.newLine();
            _builder.append("*/");
            _builder.newLine();
            _builder.newLine();
        }
    }
    _builder.append("\t");
    _builder.append("protected ");
    String _simpleName = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
    _builder.append(_simpleName, "\t");
    _builder.append(" grammarAccess;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected ");
    String _simpleName_1 = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it)).getSimpleName();
    _builder.append(_simpleName_1, "\t");
    _builder.append(" elementTypeProvider;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ");
    String _simpleName_2 = this._ideaPluginClassNames.getPsiInternalParser(GrammarUtil.getGrammar(it)).getSimpleName();
    _builder.append(_simpleName_2, "\t");
    _builder.append("(PsiBuilder builder, TokenStream input, ");
    String _simpleName_3 = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it)).getSimpleName();
    _builder.append(_simpleName_3, "\t");
    _builder.append(" elementTypeProvider, ");
    String _simpleName_4 = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
    _builder.append(_simpleName_4, "\t");
    _builder.append(" grammarAccess) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("this(input);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("setPsiBuilder(builder);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.grammarAccess = grammarAccess;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.elementTypeProvider = elementTypeProvider;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected String getFirstRuleName() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return \"");
    ParserRule _originalElement = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(IterableExtensions.<ParserRule>head(GrammarUtil.allParserRules(it)));
    String _name = ((AbstractRule) _originalElement).getName();
    _builder.append(_name, "\t\t");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 72 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class AbstractAntlrGrammarGenerator method _assignmentEbnf.

protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
    String _switchResult = null;
    AbstractRule _rule = it.getRule();
    final AbstractRule rule = _rule;
    boolean _matched = false;
    if (rule instanceof EnumRule) {
        _matched = true;
    }
    if (!_matched) {
        if (rule instanceof ParserRule) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (rule instanceof TerminalRule) {
            _matched = true;
        }
    }
    if (_matched) {
        _switchResult = this._grammarAccessExtensions.ruleName(rule);
    }
    if (!_matched) {
        throw new IllegalStateException(("assignmentEbnf is not supported for " + rule));
    }
    return _switchResult;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 73 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class GrammarElementTitleSwitch method caseRuleCall.

@Override
public String caseRuleCall(RuleCall object) {
    AbstractRule rule = object.getRule();
    String ruleName;
    if (rule != null && !rule.eIsProxy())
        ruleName = rule.getName();
    else
        ruleName = "unresolved_rule";
    return addCrossRefOrAssignemnt(ruleName, object) + card(object);
}
Also used : AbstractRule(org.eclipse.xtext.AbstractRule)

Example 74 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class Linker method ensureLinked.

private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) {
    for (INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
        EObject grammarElement = abstractNode.getGrammarElement();
        if (grammarElement instanceof CrossReference) {
            CrossReference ref = (CrossReference) grammarElement;
            producer.setNode(abstractNode);
            ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
        } else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
            RuleCall ruleCall = (RuleCall) grammarElement;
            AbstractRule calledRule = ruleCall.getRule();
            if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
                ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
            }
        }
    }
    if (!dontCheckParent && shouldCheckParentNode(node)) {
        ensureLinked(obj, producer, node.getParent(), handledReferences, false);
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) INode(org.eclipse.xtext.nodemodel.INode) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 75 with AbstractRule

use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.

the class AbstractFormattingConfig method getAbstractElements.

protected List<AbstractElement> getAbstractElements(EObject obj) {
    if (obj instanceof AbstractElement)
        return Collections.singletonList((AbstractElement) obj);
    if (obj instanceof AbstractRule) {
        AbstractRule rule = (AbstractRule) obj;
        if (rule.getType().getClassifier() instanceof EClass)
            return Collections.singletonList(rule.getAlternatives());
        List<AbstractElement> result = Lists.newArrayList();
        for (RuleCall rc : grammarAccess.findRuleCalls(rule)) {
            CrossReference cr = GrammarUtil.containingCrossReference(rc);
            result.add(cr == null ? rc : cr);
        }
        return result;
    }
    return null;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) AbstractElement(org.eclipse.xtext.AbstractElement) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

AbstractRule (org.eclipse.xtext.AbstractRule)222 Test (org.junit.Test)128 Grammar (org.eclipse.xtext.Grammar)106 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)96 ParserRule (org.eclipse.xtext.ParserRule)94 EObject (org.eclipse.emf.ecore.EObject)59 AbstractXtextRuleInspectorTest (org.eclipse.xtext.xtext.AbstractXtextRuleInspectorTest)49 RuleCall (org.eclipse.xtext.RuleCall)36 AbstractElement (org.eclipse.xtext.AbstractElement)34 TerminalRule (org.eclipse.xtext.TerminalRule)20 XtextResource (org.eclipse.xtext.resource.XtextResource)17 EClassifier (org.eclipse.emf.ecore.EClassifier)14 EnumRule (org.eclipse.xtext.EnumRule)14 ArrayList (java.util.ArrayList)12 Assignment (org.eclipse.xtext.Assignment)12 Group (org.eclipse.xtext.Group)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)11 EClass (org.eclipse.emf.ecore.EClass)10 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)10