Search in sources :

Example 86 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.

the class SemanticSequencerNfaProvider method getSemanticSequencerNFAs.

@Override
public SerializationContextMap<Nfa<ISemState>> getSemanticSequencerNFAs(Grammar grammar) {
    SerializationContextMap<Nfa<ISemState>> cached = cache.get(grammar);
    if (cached != null)
        return cached;
    SerializationContextMap.Builder<Nfa<ISemState>> builder = SerializationContextMap.builder();
    SerializationContextMap<ISynAbsorberState> PDAs = pdaProvider.getSyntacticSequencerPDAs(grammar);
    for (SerializationContextMap.Entry<ISynAbsorberState> e : PDAs.values()) {
        ISynAbsorberState synState = e.getValue();
        for (EClass type : e.getTypes()) {
            List<ISerializationContext> contexts = e.getContexts(type);
            try {
                SemNfa nfa = createNfa(grammar, synState, type);
                builder.put(contexts, nfa);
            } catch (Exception x) {
                LOG.error("Error during static analysis of context '" + contexts + "': " + x.getMessage(), x);
            }
        }
    }
    SerializationContextMap<Nfa<ISemState>> result = builder.create();
    cache.put(grammar, result);
    return result;
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) Nfa(org.eclipse.xtext.util.formallang.Nfa)

Example 87 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.

the class SerializationContext method forChild.

public static ISerializationContext forChild(ISerializationContext container, Action assignedAction, EObject sem) {
    EClass type = sem == null ? null : sem.eClass();
    // RuleContext ruleContext = new RuleContext(null, container.getParserRule());
    ISerializationContext context = new TypeContext(new ActionContext(/*ruleContext*/
    null, assignedAction), type);
    if (container != null) {
        Set<Parameter> params = container.getEnabledBooleanParameters();
        if (!params.isEmpty())
            context = new ParameterValueContext(context, params);
    }
    return context;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) Parameter(org.eclipse.xtext.Parameter)

Example 88 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.

the class SerializationContext method forChild.

public static ISerializationContext forChild(ISerializationContext container, RuleCall ruleCall, EObject sem) {
    EClass type = sem == null ? null : sem.eClass();
    ISerializationContext result = new TypeContext(new RuleContext(null, (ParserRule) ruleCall.getRule()), type);
    EList<NamedArgument> arguments = ruleCall.getArguments();
    if (!arguments.isEmpty() && container != null) {
        Set<Parameter> params = Sets.newLinkedHashSet();
        ConditionEvaluator evaluator = new ConditionEvaluator(container.getEnabledBooleanParameters());
        for (NamedArgument argument : arguments) {
            if (evaluator.evaluate(argument.getValue())) {
                params.add(argument.getParameter());
            }
        }
        result = new SerializationContext.ParameterValueContext(result, params);
    }
    return result;
}
Also used : ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) ConditionEvaluator(org.eclipse.xtext.xtext.ConditionEvaluator) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) Parameter(org.eclipse.xtext.Parameter) NamedArgument(org.eclipse.xtext.NamedArgument)

Example 89 with EClass

use of org.eclipse.emf.ecore.EClass 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 90 with EClass

use of org.eclipse.emf.ecore.EClass in project xtext-core by eclipse.

the class SyntacticSequencerPDAProvider method getSyntacticSequencerPDAs.

@Override
public SerializationContextMap<ISynAbsorberState> getSyntacticSequencerPDAs(Grammar grammar) {
    SerializationContextMap<ISynAbsorberState> cached = cache.get(grammar);
    if (cached != null)
        return cached;
    SerializationContextMap.Builder<ISynAbsorberState> builder = SerializationContextMap.builder();
    SerializationContextMap<Pda<ISerState, RuleCall>> typePDAs = pdaProvider.getContextTypePDAs(grammar);
    for (Entry<Pda<ISerState, RuleCall>> e : typePDAs.values()) {
        Pda<ISerState, RuleCall> pda = e.getValue();
        List<ISerializationContext> contexts = e.getContexts();
        try {
            EClass type = contexts.get(0).getType();
            Map<ISerState, SynAbsorberState> absorbers = Maps.newLinkedHashMap();
            Map<SynAbsorberState, Map<ISerState, SynState>> emitters = Maps.newLinkedHashMap();
            SynAbsorberState state = createAbsorberState(pda.getStart(), absorbers, emitters, type);
            builder.put(contexts, state);
        } catch (Exception x) {
            String ctxs = Joiner.on(", ").join(contexts);
            LOG.error("Error creating PDA for syntactic sequencer for contexts: " + ctxs + ": " + x.getMessage(), x);
        }
    }
    SerializationContextMap<ISynAbsorberState> result = builder.create();
    cache.put(grammar, result);
    return result;
}
Also used : Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) Map(java.util.Map)

Aggregations

EClass (org.eclipse.emf.ecore.EClass)205 Test (org.junit.Test)99 EPackage (org.eclipse.emf.ecore.EPackage)70 EClassifier (org.eclipse.emf.ecore.EClassifier)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)43 EObject (org.eclipse.emf.ecore.EObject)35 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)27 Resource (org.eclipse.emf.ecore.resource.Resource)23 EReference (org.eclipse.emf.ecore.EReference)22 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)16 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)13 ParserRule (org.eclipse.xtext.ParserRule)12 QualifiedName (org.eclipse.xtext.naming.QualifiedName)12 InternalEObject (org.eclipse.emf.ecore.InternalEObject)11 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)11 IScope (org.eclipse.xtext.scoping.IScope)11 ArrayList (java.util.ArrayList)10 AbstractRule (org.eclipse.xtext.AbstractRule)10 List (java.util.List)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)9