Search in sources :

Example 66 with Action

use of org.eclipse.xtext.Action 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 67 with Action

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

the class NamedSerializationContextProvider method getSignificantGrammarElement.

public String getSignificantGrammarElement(final Iterable<ISerializationContext> contexts) {
    ParserRule rule = null;
    int index = Integer.MAX_VALUE;
    for (final ISerializationContext ctx : contexts) {
        {
            ParserRule pr = ctx.getParserRule();
            if ((pr == null)) {
                final Action action = ctx.getAssignedAction();
                if ((action != null)) {
                    pr = GrammarUtil.containingParserRule(action);
                }
            }
            if ((pr != null)) {
                final Integer i = this.rules.get(pr);
                if (((i).intValue() < index)) {
                    index = (i).intValue();
                    rule = pr;
                }
            }
        }
    }
    if ((rule != null)) {
        return rule.getName();
    }
    return "unknown";
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext)

Example 68 with Action

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

the class SerializerFragment2 method getContextObject.

private EObject getContextObject(final ISerializationContext context) {
    EObject _elvis = null;
    Action _assignedAction = context.getAssignedAction();
    if (_assignedAction != null) {
        _elvis = _assignedAction;
    } else {
        ParserRule _parserRule = context.getParserRule();
        _elvis = _parserRule;
    }
    return _elvis;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) EObject(org.eclipse.emf.ecore.EObject)

Example 69 with Action

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

the class IndentationAwareTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == IndentLangPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case IndentLangPackage.NODE:
                sequence_Node(context, (Node) semanticObject);
                return;
            case IndentLangPackage.NODE_LIST:
                sequence_NodeList(context, (NodeList) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Node(org.eclipse.xtext.testlanguages.indent.indentLang.Node) NodeList(org.eclipse.xtext.testlanguages.indent.indentLang.NodeList) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 70 with Action

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

the class Bug302128TestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == Bug302128Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Bug302128Package.ELEMENT:
                sequence_Element(context, (Element) semanticObject);
                return;
            case Bug302128Package.MODEL:
                sequence_Model(context, (Model) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Element(org.eclipse.xtext.parsetree.reconstr.bug302128.Element) Model(org.eclipse.xtext.parsetree.reconstr.bug302128.Model) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Aggregations

Action (org.eclipse.xtext.Action)161 ParserRule (org.eclipse.xtext.ParserRule)145 Parameter (org.eclipse.xtext.Parameter)128 EPackage (org.eclipse.emf.ecore.EPackage)124 EObject (org.eclipse.emf.ecore.EObject)17 RuleCall (org.eclipse.xtext.RuleCall)17 Assignment (org.eclipse.xtext.Assignment)13 AbstractElement (org.eclipse.xtext.AbstractElement)10 EClass (org.eclipse.emf.ecore.EClass)8 INode (org.eclipse.xtext.nodemodel.INode)8 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)7 AbstractRule (org.eclipse.xtext.AbstractRule)6 Alternatives (org.eclipse.xtext.Alternatives)6 Group (org.eclipse.xtext.Group)6 Keyword (org.eclipse.xtext.Keyword)6 TerminalRule (org.eclipse.xtext.TerminalRule)6 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)6 TypeRef (org.eclipse.xtext.TypeRef)5 CrossReference (org.eclipse.xtext.CrossReference)4 ParserRuleParameters (org.eclipse.xtext.parser.parameters.parametersTestLanguage.ParserRuleParameters)4