Search in sources :

Example 26 with Assignment

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

the class SequenceFeeder method accept.

public void accept(Keyword keyword, Object value, int index, ILeafNode node) {
    Assignment ass = getAssignment(keyword);
    EStructuralFeature feature = getFeature(ass.getFeature());
    assertIndex(feature, index);
    assertValue(feature, value);
    String token = getToken(keyword, value, node);
    acceptKeyword(ass, keyword, value, token, index, node);
}
Also used : Assignment(org.eclipse.xtext.Assignment) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 27 with Assignment

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

the class SyntacticSequencerPDAProvider method getType.

protected SynStateType getType(ISerState state) {
    switch(state.getType()) {
        case ELEMENT:
            AbstractElement ele = state.getGrammarElement();
            Assignment ass;
            if (ele instanceof Action) {
                if (((Action) ele).getFeature() == null)
                    return SynStateType.UNASSIGEND_ACTION_CALL;
                else
                    return SynStateType.ASSIGNED_ACTION_CALL;
            } else if (GrammarUtil.containingCrossReference(ele) != null) {
                if (ele instanceof RuleCall) {
                    RuleCall rc = (RuleCall) ele;
                    if (rc.getRule() instanceof ParserRule)
                        return SynStateType.ASSIGNED_CROSSREF_DATATYPE_RULE_CALL;
                    if (rc.getRule() instanceof TerminalRule)
                        return SynStateType.ASSIGNED_CROSSREF_TERMINAL_RULE_CALL;
                    if (rc.getRule() instanceof EnumRule)
                        return SynStateType.ASSIGNED_CROSSREF_ENUM_RULE_CALL;
                } else if (ele instanceof Keyword)
                    return SynStateType.ASSIGNED_CROSSREF_KEYWORD;
            } else if ((ass = GrammarUtil.containingAssignment(ele)) != null) {
                if (ele instanceof RuleCall) {
                    RuleCall rc = (RuleCall) ele;
                    if (rc.getRule() instanceof ParserRule) {
                        if (rc.getRule().getType().getClassifier() instanceof EClass)
                            return SynStateType.ASSIGNED_PARSER_RULE_CALL;
                        return SynStateType.ASSIGNED_DATATYPE_RULE_CALL;
                    }
                    if (rc.getRule() instanceof TerminalRule)
                        return SynStateType.ASSIGNED_TERMINAL_RULE_CALL;
                    if (rc.getRule() instanceof EnumRule)
                        return SynStateType.ASSIGNED_ENUM_RULE_CALL;
                } else if (ele instanceof Keyword) {
                    if (GrammarUtil.isBooleanAssignment(ass))
                        return SynStateType.ASSIGNED_BOOLEAN_KEYWORD;
                    else
                        return SynStateType.ASSIGNED_KEYWORD;
                }
            } else {
                if (ele instanceof RuleCall) {
                    RuleCall rc = (RuleCall) ele;
                    if (rc.getRule() instanceof ParserRule)
                        return SynStateType.UNASSIGNED_DATATYPE_RULE_CALL;
                    if (rc.getRule() instanceof TerminalRule)
                        return SynStateType.UNASSIGNED_TERMINAL_RULE_CALL;
                } else if (ele instanceof Keyword)
                    return SynStateType.UNASSIGEND_KEYWORD;
            }
            break;
        case PUSH:
            return SynStateType.UNASSIGNED_PARSER_RULE_ENTER;
        case POP:
            return SynStateType.UNASSIGNED_PARSER_RULE_EXIT;
        case START:
            return SynStateType.START;
        case STOP:
            return SynStateType.STOP;
    }
    throw new RuntimeException("no type found for " + state);
}
Also used : Assignment(org.eclipse.xtext.Assignment) ParserRule(org.eclipse.xtext.ParserRule) EnumRule(org.eclipse.xtext.EnumRule) Action(org.eclipse.xtext.Action) EClass(org.eclipse.emf.ecore.EClass) AbstractElement(org.eclipse.xtext.AbstractElement) Keyword(org.eclipse.xtext.Keyword) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall)

Example 28 with Assignment

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

the class NodeModelSemanticSequencer method acceptSemantic.

protected boolean acceptSemantic(EObject semanticObject, AbstractElement ele, Object value, INode node) {
    Assignment ass = GrammarUtil.containingAssignment(ele);
    int index = -2;
    if (ass != null) {
        EStructuralFeature feat = semanticObject.eClass().getEStructuralFeature(ass.getFeature());
        if (feat != null) {
            if (feat.isMany())
                index = ((List<?>) semanticObject.eGet(feat)).indexOf(value);
            else
                index = -1;
        }
    }
    String token = node.getText().trim();
    if (ele instanceof Action) {
        if (((Action) ele).getFeature() != null) {
            if (sequenceAcceptor.enterAssignedAction((Action) ele, (EObject) value, (ICompositeNode) node)) {
                createSequence(ele, (EObject) value);
                sequenceAcceptor.leaveAssignedAction((Action) ele, (EObject) value);
            }
            return true;
        }
    } else if (GrammarUtil.containingCrossReference(ele) != null) {
        if (ele instanceof RuleCall) {
            RuleCall rc = (RuleCall) ele;
            if (rc.getRule() instanceof ParserRule) {
                sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, (ICompositeNode) node);
                return true;
            }
            if (rc.getRule() instanceof TerminalRule) {
                sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, (ILeafNode) node);
                return true;
            }
            if (rc.getRule() instanceof EnumRule) {
                sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, (ICompositeNode) node);
                return true;
            }
        // } else if (ele instanceof Keyword) {
        // acceptor.acceptAssignedCrossRefKeyword((Keyword) ele, token, (EObject) value, index,(ILeafNode) node);
        // return true;
        }
    } else if (ass != null) {
        if (ele instanceof RuleCall) {
            RuleCall rc = (RuleCall) ele;
            if (rc.getRule() instanceof ParserRule) {
                if (rc.getRule().getType().getClassifier() instanceof EClass) {
                    if (sequenceAcceptor.enterAssignedParserRuleCall(rc, (EObject) value, (ICompositeNode) node)) {
                        createSequence(rc.getRule(), (EObject) value);
                        sequenceAcceptor.leaveAssignedParserRuleCall(rc, (EObject) value);
                    }
                } else
                    sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, (ICompositeNode) node);
                return true;
            }
            if (rc.getRule() instanceof TerminalRule) {
                sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, (ILeafNode) node);
                return true;
            }
            if (rc.getRule() instanceof EnumRule) {
                sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, (ICompositeNode) node);
                return true;
            }
        } else if (ele instanceof Keyword) {
            if (GrammarUtil.isBooleanAssignment(ass))
                sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, true, index, (ILeafNode) node);
            else
                sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, (String) value, index, (ILeafNode) node);
            return true;
        }
    }
    return false;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Keyword(org.eclipse.xtext.Keyword) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) EnumRule(org.eclipse.xtext.EnumRule) EClass(org.eclipse.emf.ecore.EClass) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) List(java.util.List) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 29 with Assignment

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

the class LazyLinkerTest method newCrossReferenceAssignmentNode.

private INode newCrossReferenceAssignmentNode(final String feature) {
    final LeafNode leafNode = new LeafNode();
    final Assignment assignment = XtextFactory.eINSTANCE.createAssignment();
    assignment.setFeature(feature);
    final CrossReference crossReference = XtextFactory.eINSTANCE.createCrossReference();
    assignment.setTerminal(crossReference);
    leafNode.basicSetGrammarElement(crossReference);
    return leafNode;
}
Also used : Assignment(org.eclipse.xtext.Assignment) LeafNode(org.eclipse.xtext.nodemodel.LeafNode) CrossReference(org.eclipse.xtext.CrossReference)

Example 30 with Assignment

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

the class EntryPointFinder method shouldUseParent.

protected boolean shouldUseParent(ICompositeNode result, int offset, ILeafNode leaf) {
    if (leaf.getTotalEndOffset() == offset) {
        return true;
    }
    if (result.getGrammarElement() instanceof RuleCall) {
        RuleCall rc = (RuleCall) result.getGrammarElement();
        if (!rc.getArguments().isEmpty()) {
            return true;
        }
        Assignment assignment = GrammarUtil.containingAssignment(rc);
        if (assignment != null && (GrammarUtil.isMultipleCardinality(assignment) || (assignment.eContainer() instanceof AbstractElement && GrammarUtil.isMultipleCardinality((AbstractElement) assignment.eContainer())))) {
            return true;
        }
    }
    return false;
}
Also used : Assignment(org.eclipse.xtext.Assignment) AbstractElement(org.eclipse.xtext.AbstractElement) RuleCall(org.eclipse.xtext.RuleCall)

Aggregations

Assignment (org.eclipse.xtext.Assignment)60 EObject (org.eclipse.emf.ecore.EObject)27 Test (org.junit.Test)25 RuleCall (org.eclipse.xtext.RuleCall)22 Grammar (org.eclipse.xtext.Grammar)21 AbstractElement (org.eclipse.xtext.AbstractElement)15 ParserRule (org.eclipse.xtext.ParserRule)15 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)14 Action (org.eclipse.xtext.Action)13 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)12 AbstractRule (org.eclipse.xtext.AbstractRule)12 Group (org.eclipse.xtext.Group)11 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)9 Alternatives (org.eclipse.xtext.Alternatives)8 CrossReference (org.eclipse.xtext.CrossReference)7 ArrayList (java.util.ArrayList)6 EClass (org.eclipse.emf.ecore.EClass)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)6 NamedArgument (org.eclipse.xtext.NamedArgument)6 LiteralCondition (org.eclipse.xtext.LiteralCondition)5