Search in sources :

Example 56 with RuleCall

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

the class BaseContentAssistParser method getEntryGrammarElement.

protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
    EObject grammarElement = entryPoint.getGrammarElement();
    if (grammarElement instanceof RuleCall) {
        AbstractRule rule = ((RuleCall) grammarElement).getRule();
        if (rule instanceof ParserRule) {
            if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
                grammarElement = rule.getAlternatives();
            }
        }
    } else if (grammarElement instanceof ParserRule) {
        grammarElement = ((ParserRule) grammarElement).getAlternatives();
    } else if (grammarElement instanceof CrossReference) {
        grammarElement = GrammarUtil.containingAssignment(grammarElement);
    }
    AbstractElement result = (AbstractElement) grammarElement;
    if (result instanceof Action) {
        return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
    }
    return result;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 57 with RuleCall

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

the class FirstSetComputationTest method assertFirstSet.

protected void assertFirstSet(String expectation, AbstractRule rule) {
    RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
    ruleCall.setRule(rule);
    List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall);
    StringBuilder actual = new StringBuilder();
    GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch();
    for (int i = 0; i < firstSet.size(); i++) {
        if (i != 0)
            actual.append(", ");
        actual.append(stringifier.apply(firstSet.get(i)));
    }
    assertEquals(expectation, actual.toString());
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) AbstractElement(org.eclipse.xtext.AbstractElement) RuleCall(org.eclipse.xtext.RuleCall)

Example 58 with RuleCall

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

the class ContextPDAProvider method collectExtracted.

protected void collectExtracted(ISerState orig, Collection<? extends ISerState> precedents, SerializerPDAState copy, Map<Pair<AbstractElement, SerStateType>, SerializerPDAState> oldToNew, final CallStack inTop, SerializerPDAState start) {
    for (ISerState pre : precedents) {
        CallStack top = inTop;
        AbstractElement element = pre.getGrammarElement();
        switch(pre.getType()) {
            case START:
                if (top.call == null)
                    connect(start, copy);
                continue;
            case POP:
                top = new CallStack(top, (RuleCall) element);
                if (top.isLoop())
                    continue;
                break;
            case PUSH:
                if (top.call == null) {
                    connect(start, copy);
                    continue;
                } else if (top.call == element) {
                    top = top.parent;
                } else {
                    continue;
                }
            default:
                break;
        }
        Pair<AbstractElement, SerStateType> key = Tuples.create(element, pre.getType());
        SerializerPDAState pre2 = oldToNew.get(key);
        if (pre2 == null) {
            pre2 = new SerializerPDAState(element, pre.getType());
            oldToNew.put(key, pre2);
        }
        if (GrammarUtil.isAssignedAction(pre.getGrammarElement())) /* && pre.getType() != STOP */
        {
            Set<ISerState> entries = collectPushForAction(pre);
            collectExtracted(pre, entries, pre2, oldToNew, top, start);
        } else {
            if (top.visited.add(pre))
                collectExtracted(pre, pre.getPrecedents(), pre2, oldToNew, top, start);
        }
        connect(pre2, copy);
    }
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) SerializerPDAState(org.eclipse.xtext.serializer.analysis.SerializerPDA.SerializerPDAState) RuleCall(org.eclipse.xtext.RuleCall) SerStateType(org.eclipse.xtext.serializer.analysis.ISerState.SerStateType)

Example 59 with RuleCall

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

the class AbstractSyntacticSequencer method accept.

@SuppressWarnings("deprecation")
protected void accept(ISynState emitter, INode node, RuleCallStack stack) {
    switch(emitter.getType()) {
        case UNASSIGNED_PARSER_RULE_ENTER:
            RuleCall rc1 = (RuleCall) emitter.getGrammarElement();
            delegate.enterUnassignedParserRuleCall(rc1);
            stack.push(rc1);
            return;
        case UNASSIGNED_PARSER_RULE_EXIT:
            RuleCall rc2 = (RuleCall) emitter.getGrammarElement();
            delegate.leaveUnssignedParserRuleCall(rc2);
            RuleCall lastRc = stack.pop();
            if (lastRc != rc2) {
                if (errorAcceptor != null)
                    errorAcceptor.accept(diagnosticProvider.createUnexpectedStackStateDiagnostic(contexts.get(contexts.size() - 1).semanticObject, stack, lastRc, emitter));
            }
            return;
        case UNASSIGEND_ACTION_CALL:
            delegate.acceptUnassignedAction((Action) emitter.getGrammarElement());
            return;
        case UNASSIGEND_KEYWORD:
            Keyword keyword = (Keyword) emitter.getGrammarElement();
            String token = node != null ? node.getText() : keyword.getValue();
            delegate.acceptUnassignedKeyword(keyword, token, (ILeafNode) node);
            return;
        case UNASSIGNED_DATATYPE_RULE_CALL:
            RuleCall rc3 = (RuleCall) emitter.getGrammarElement();
            String value3 = getUnassignedRuleCallToken(rc3, node);
            delegate.acceptUnassignedDatatype(rc3, value3, (ICompositeNode) node);
            return;
        case UNASSIGNED_TERMINAL_RULE_CALL:
            RuleCall rc4 = (RuleCall) emitter.getGrammarElement();
            String value4 = getUnassignedRuleCallToken(rc4, node);
            delegate.acceptUnassignedTerminal(rc4, value4, (ILeafNode) node);
            return;
        case ASSIGNED_ACTION_CALL:
        case ASSIGNED_BOOLEAN_KEYWORD:
        case ASSIGNED_CROSSREF_DATATYPE_RULE_CALL:
        case ASSIGNED_CROSSREF_ENUM_RULE_CALL:
        case ASSIGNED_CROSSREF_KEYWORD:
        case ASSIGNED_CROSSREF_TERMINAL_RULE_CALL:
        case ASSIGNED_DATATYPE_RULE_CALL:
        case ASSIGNED_ENUM_RULE_CALL:
        case ASSIGNED_KEYWORD:
        case ASSIGNED_PARSER_RULE_CALL:
        case ASSIGNED_TERMINAL_RULE_CALL:
        case START:
        case STOP:
        case TRANSITION:
    }
    throw new RuntimeException("invalid state for emitting: " + emitter + " (" + emitter.getType() + ")");
}
Also used : Keyword(org.eclipse.xtext.Keyword) RuleCall(org.eclipse.xtext.RuleCall)

Example 60 with RuleCall

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

the class NodeModelSemanticSequencer method createSequence.

@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
    SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
    while (ni.hasNext()) {
        Triple<INode, AbstractElement, EObject> node = ni.next();
        if (node.getSecond() instanceof RuleCall) {
            RuleCall rc = (RuleCall) node.getSecond();
            TypeRef ruleType = rc.getRule().getType();
            if (ruleType == null || ruleType.getClassifier() instanceof EClass)
                acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
            else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
                EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass());
                acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
            } else {
                String strVal = NodeModelUtils.getTokenText(node.getFirst());
                Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst());
                acceptSemantic(semanticObject, rc, val, node.getFirst());
            }
        } else if (node.getSecond() instanceof Keyword)
            acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
        else if (node.getSecond() instanceof Action) {
            acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Action(org.eclipse.xtext.Action) AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword) TypeRef(org.eclipse.xtext.TypeRef) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) RuleCall(org.eclipse.xtext.RuleCall) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)95 ParserRule (org.eclipse.xtext.ParserRule)41 AbstractRule (org.eclipse.xtext.AbstractRule)36 EObject (org.eclipse.emf.ecore.EObject)33 Test (org.junit.Test)33 Grammar (org.eclipse.xtext.Grammar)28 AbstractElement (org.eclipse.xtext.AbstractElement)26 Assignment (org.eclipse.xtext.Assignment)22 TerminalRule (org.eclipse.xtext.TerminalRule)19 Action (org.eclipse.xtext.Action)17 CrossReference (org.eclipse.xtext.CrossReference)13 Group (org.eclipse.xtext.Group)13 TypeRef (org.eclipse.xtext.TypeRef)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 ArrayList (java.util.ArrayList)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 InternalEObject (org.eclipse.emf.ecore.InternalEObject)10 Keyword (org.eclipse.xtext.Keyword)10 EClass (org.eclipse.emf.ecore.EClass)9 EnumRule (org.eclipse.xtext.EnumRule)9