Search in sources :

Example 86 with AbstractElement

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

the class AbstractAntlrGrammarGenerator method _dataTypeEbnf2.

protected String _dataTypeEbnf2(final UnorderedGroup it, final boolean supportActions) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("(");
    {
        EList<AbstractElement> _elements = it.getElements();
        boolean _hasElements = false;
        for (final AbstractElement e : _elements) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("\n    |", "");
            }
            String _dataTypeEbnf2 = this.dataTypeEbnf2(e, supportActions);
            _builder.append(_dataTypeEbnf2);
        }
    }
    _builder.append(")*");
    _builder.newLineIfNotEmpty();
    return _builder.toString();
}
Also used : EList(org.eclipse.emf.common.util.EList) AbstractElement(org.eclipse.xtext.AbstractElement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 87 with AbstractElement

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

the class AbstractAntlrGrammarWithActionsGenerator method _dataTypeEbnf2.

@Override
protected String _dataTypeEbnf2(final UnorderedGroup it, final boolean supportActions) {
    String _xifexpression = null;
    if (supportActions) {
        String _xblockexpression = null;
        {
            final Function1<AbstractElement, Boolean> _function = (AbstractElement it_1) -> {
                boolean _isOptionalCardinality = GrammarUtil.isOptionalCardinality(it_1);
                return Boolean.valueOf((!_isOptionalCardinality));
            };
            final int mandatoryContent = IterableExtensions.size(IterableExtensions.<AbstractElement>filter(it.getElements(), _function));
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("(");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("{ ");
            _builder.newLine();
            _builder.append("\t  ");
            _builder.append("getUnorderedGroupHelper().enter(grammarAccess.");
            UnorderedGroup _originalElement = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
            String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement));
            _builder.append(_gaRuleElementAccessor, "\t  ");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("(");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("(");
            _builder.newLine();
            {
                Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
                boolean _hasElements = false;
                for (final Pair<Integer, AbstractElement> element : _indexed) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate("|", "");
                    }
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
                    UnorderedGroup _originalElement_1 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_1));
                    _builder.append(_gaRuleElementAccessor_1, "\t");
                    _builder.append(", ");
                    Integer _key = element.getKey();
                    _builder.append(_key, "\t");
                    _builder.append(")}?=>(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{");
                    _builder.newLine();
                    _builder.append("\t\t\t");
                    _builder.append("getUnorderedGroupHelper().select(grammarAccess.");
                    UnorderedGroup _originalElement_2 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_2));
                    _builder.append(_gaRuleElementAccessor_2, "\t\t\t");
                    _builder.append(", ");
                    Integer _key_1 = element.getKey();
                    _builder.append(_key_1, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t\t\t\t\t");
                    _builder.append("({true}?=>(");
                    String _dataTypeEbnf2 = this.dataTypeEbnf2(element.getValue(), supportActions);
                    _builder.append(_dataTypeEbnf2, "\t\t\t\t\t");
                    _builder.append("))");
                    {
                        boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
                        if (_isMultipleCardinality) {
                            _builder.append("+");
                        }
                    }
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{ ");
                    _builder.newLine();
                    _builder.append("\t\t\t");
                    _builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
                    UnorderedGroup _originalElement_3 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_3 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_3));
                    _builder.append(_gaRuleElementAccessor_3, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(")");
                    _builder.newLine();
                    _builder.append(")");
                    _builder.newLine();
                }
            }
            _builder.append("\t\t");
            _builder.append(")");
            {
                if ((mandatoryContent != 0)) {
                    _builder.append("+");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{getUnorderedGroupHelper().canLeave(grammarAccess.");
                    UnorderedGroup _originalElement_4 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_4 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_4));
                    _builder.append(_gaRuleElementAccessor_4, "\t\t");
                    _builder.append(")}?");
                } else {
                    _builder.append("*");
                }
            }
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("{ ");
            _builder.newLine();
            _builder.append("\t  ");
            _builder.append("getUnorderedGroupHelper().leave(grammarAccess.");
            UnorderedGroup _originalElement_5 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
            String _gaRuleElementAccessor_5 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_5));
            _builder.append(_gaRuleElementAccessor_5, "\t  ");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _xblockexpression = _builder.toString();
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = super._dataTypeEbnf2(it, supportActions);
    }
    return _xifexpression;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 88 with AbstractElement

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

the class AbstractNFAState method getIncommingWithoutRuleCalls.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<T> getIncommingWithoutRuleCalls() {
    List<T> result = Lists.newArrayList();
    AbstractElement rootEle = containingRule(element).getAlternatives();
    ((AbstractNFAState) builder.getState(rootEle)).collectReferencesToThis(this, Sets.newHashSet(), result);
    return result;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement)

Example 89 with AbstractElement

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

the class AbstractNFAState method collectOutgoingByContainer.

protected void collectOutgoingByContainer(AbstractElement element, Set<AbstractElement> visited, boolean isRuleCall, AbstractElement loopCenter) {
    EObject container = element.eContainer();
    if (container instanceof Group || container instanceof UnorderedGroup) {
        CompoundElement compoundContainer = (CompoundElement) container;
        List<AbstractElement> siblings = compoundContainer.getElements();
        int i = siblings.indexOf(element);
        switch(builder.getDirection()) {
            case FORWARD:
                if ((i + 1) >= siblings.size()) {
                    if (GrammarUtil.isMultipleCardinality(compoundContainer))
                        addOutgoing(compoundContainer, visited, isRuleCall, compoundContainer);
                    collectOutgoingByContainer(compoundContainer, visited, isRuleCall, loopCenter);
                } else {
                    AbstractElement next = siblings.get(i + 1);
                    addOutgoing(next, visited, isRuleCall, loopCenter);
                    if (GrammarUtil.isOptionalCardinality(next))
                        collectOutgoingByContainer(next, visited, isRuleCall, loopCenter);
                }
                break;
            case BACKWARD:
                if (i <= 0) {
                    if (GrammarUtil.isMultipleCardinality(compoundContainer))
                        addOutgoing(compoundContainer, visited, isRuleCall, compoundContainer);
                    collectOutgoingByContainer(compoundContainer, visited, isRuleCall, loopCenter);
                } else {
                    AbstractElement next = siblings.get(i - 1);
                    addOutgoing(next, visited, isRuleCall, loopCenter);
                    if (GrammarUtil.isOptionalCardinality(next))
                        collectOutgoingByContainer(next, visited, isRuleCall, loopCenter);
                }
                break;
        }
    } else if (container instanceof AbstractRule)
        endState = true;
    else if (container instanceof AbstractElement) {
        AbstractElement elementContainer = (AbstractElement) container;
        if (GrammarUtil.isMultipleCardinality(elementContainer))
            addOutgoing(elementContainer, visited, isRuleCall, elementContainer);
        collectOutgoingByContainer(elementContainer, visited, isRuleCall, loopCenter);
    } else
        throw new IllegalStateException("Unknown container: " + container);
}
Also used : UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Group(org.eclipse.xtext.Group) AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) EObject(org.eclipse.emf.ecore.EObject) CompoundElement(org.eclipse.xtext.CompoundElement) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 90 with AbstractElement

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

the class GrammarElementTitleSwitch method addQualified.

protected String addQualified(String result, AbstractElement ele) {
    if (!showQualified && !showRule)
        return result;
    AbstractRule rule = GrammarUtil.containingRule(ele);
    if (rule == null)
        return "<AbstractElement not contained in AbstractRule!>:" + result;
    if (!showQualified)
        return result + ":" + rule.getName();
    GrammarElementTitleSwitch others = copy();
    others.showQualified = false;
    others.showRule = false;
    List<AbstractElement> elementsWithSameName = Lists.newArrayList();
    for (AbstractElement candidate : EcoreUtil2.getAllContentsOfType(rule, ele.getClass())) if (candidate == ele || result.equals(others.doSwitch(candidate)))
        elementsWithSameName.add(candidate);
    if (elementsWithSameName.size() < 2) {
        if (showRule)
            return rule.getName() + ":" + result;
        return result;
    }
    Map<CompoundElement, Node> nodes = Maps.newHashMap();
    for (AbstractElement collision : elementsWithSameName) {
        EObject current = EcoreUtil2.getContainerOfType(collision, CompoundElement.class);
        Node node = new Node(null, collision == ele ? result : "");
        while (current instanceof CompoundElement) {
            CompoundElement container = (CompoundElement) current;
            Node cntNode = nodes.get(container);
            if (cntNode == null)
                nodes.put(container, cntNode = new Node(container, null));
            if (!cntNode.children.contains(node))
                cntNode.children.add(node);
            node = cntNode;
            current = current.eContainer();
        }
    }
    if (showRule)
        return rule.getName() + ":" + nodes.get(rule.getAlternatives());
    return nodes.get(rule.getAlternatives()).toString();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) AbstractRule(org.eclipse.xtext.AbstractRule) CompoundElement(org.eclipse.xtext.CompoundElement)

Aggregations

AbstractElement (org.eclipse.xtext.AbstractElement)126 EObject (org.eclipse.emf.ecore.EObject)39 AbstractRule (org.eclipse.xtext.AbstractRule)34 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)31 RuleCall (org.eclipse.xtext.RuleCall)26 ParserRule (org.eclipse.xtext.ParserRule)18 Grammar (org.eclipse.xtext.Grammar)17 EList (org.eclipse.emf.common.util.EList)15 Assignment (org.eclipse.xtext.Assignment)15 Test (org.junit.Test)14 Group (org.eclipse.xtext.Group)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 List (java.util.List)12 ArrayList (java.util.ArrayList)11 XtextResource (org.eclipse.xtext.resource.XtextResource)11 Action (org.eclipse.xtext.Action)10 TerminalRule (org.eclipse.xtext.TerminalRule)10 Alternatives (org.eclipse.xtext.Alternatives)9 EClassifier (org.eclipse.emf.ecore.EClassifier)8 InternalEObject (org.eclipse.emf.ecore.InternalEObject)8