Search in sources :

Example 56 with Parameter

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

the class Bug250313SemanticSequencer 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 == Bug250313Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Bug250313Package.CHILD1:
                sequence_Child1(context, (Child1) semanticObject);
                return;
            case Bug250313Package.CHILD2:
                sequence_Child2(context, (Child2) semanticObject);
                return;
            case Bug250313Package.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) Model(org.eclipse.xtext.valueconverter.bug250313.Model) Parameter(org.eclipse.xtext.Parameter) Child2(org.eclipse.xtext.valueconverter.bug250313.Child2) Child1(org.eclipse.xtext.valueconverter.bug250313.Child1) EPackage(org.eclipse.emf.ecore.EPackage)

Example 57 with Parameter

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

the class TerminalsSemanticSequencer 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 (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage)

Example 58 with Parameter

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

the class AntlrGrammarGenUtil method getArgumentList.

/**
 * @since 2.9
 */
public static String getArgumentList(final RuleCall ruleCall, boolean passCurrentIntoFragment, boolean isPredicate) {
    final List<NamedArgument> arguments = ruleCall.getArguments();
    AbstractRule abstractRule = ruleCall.getRule();
    boolean needsCurrent = passCurrentIntoFragment && GrammarUtil.isEObjectFragmentRule(abstractRule) && !GrammarUtil.isDatatypeRule((ParserRule) getOriginalElement(abstractRule));
    if (arguments.isEmpty()) {
        if (needsCurrent) {
            return isPredicate ? "[null]" : "[$current]";
        }
        return "";
    }
    ParserRule rule = (ParserRule) abstractRule;
    StringBuilder result = new StringBuilder();
    result.append("[");
    if (needsCurrent) {
        if (isPredicate) {
            result.append("null, ");
        } else {
            result.append("$current, ");
        }
    }
    Joiner.on(", ").appendTo(result, Iterables.transform(rule.getParameters(), new Function<Parameter, String>() {

        @Override
        public String apply(Parameter input) {
            for (NamedArgument argument : arguments) {
                if (argument.getParameter() == input) {
                    return conditionToAntlr(argument.getValue(), true);
                }
            }
            throw new IllegalStateException("Cannot find argument for parameter: " + input.getName());
        }
    }));
    result.append("]");
    return result.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Function(com.google.common.base.Function) Parameter(org.eclipse.xtext.Parameter) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 59 with Parameter

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

the class ParameterReferenceImpl method setParameter.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setParameter(Parameter newParameter) {
    Parameter oldParameter = parameter;
    parameter = newParameter;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.PARAMETER_REFERENCE__PARAMETER, oldParameter, parameter));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Parameter(org.eclipse.xtext.Parameter)

Example 60 with Parameter

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

the class ContextPDAProvider method getContextPDAs.

@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getContextPDAs(Grammar grammar) {
    Builder<Pda<ISerState, RuleCall>> result = SerializationContextMap.<Pda<ISerState, RuleCall>>builder();
    SerializationContextMap<Pda<ISerState, RuleCall>> grammarPDAs = grammarPdaProvider.getGrammarPDAs(grammar);
    Multimap<Action, SerializerPDA> actionPdas = ArrayListMultimap.create();
    Multimap<Action, ISerializationContext> actionContexts = LinkedHashMultimap.create();
    Map<ParserRule, Integer> indexedRules = indexRules(grammar);
    for (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> e : grammarPDAs.values()) {
        List<ISerializationContext> contexts = e.getContexts();
        Pda<ISerState, RuleCall> pda = e.getValue();
        List<ISerState> actions = Lists.newArrayList();
        for (ISerState state : nfaUtil.collect(pda)) {
            if (GrammarUtil.isAssignedAction(state.getGrammarElement())) {
                actions.add(state);
            }
        }
        if (actions.isEmpty()) {
            Pda<ISerState, RuleCall> filtered = filterUnneededUnassignedRuleCalls(pda, indexedRules);
            result.put(contexts, filtered);
        } else {
            try {
                SerializerPDA rulePda = extract(pda.getStop());
                Pda<ISerState, RuleCall> filtered = filterUnneededUnassignedRuleCalls(rulePda, indexedRules);
                result.put(contexts, filtered);
                for (ISerState state : actions) {
                    Action action = (Action) state.getGrammarElement();
                    SerializerPDA actionPda = extract(state);
                    actionPdas.put(action, actionPda);
                    actionContexts.putAll(action, contexts);
                }
            } catch (Exception x) {
                LOG.error("Error extracting PDA for action in context '" + contexts + "': " + x.getMessage(), x);
            }
        }
    }
    for (Map.Entry<Action, Collection<SerializerPDA>> action : actionPdas.asMap().entrySet()) {
        SerializerPDA merged = merge(new ActionContext(null, action.getKey()), action.getValue());
        Set<Set<Parameter>> parameterPermutations = Sets.newLinkedHashSet();
        for (ISerializationContext container : actionContexts.get(action.getKey())) {
            parameterPermutations.add(container.getEnabledBooleanParameters());
        }
        // for (IContext container : actionContexts.get(action.getKey())) {
        for (Set<Parameter> parameters : parameterPermutations) {
            ISerializationContext context = new ActionContext(/* container */
            null, action.getKey());
            if (!parameters.isEmpty())
                context = new SerializationContext.ParameterValueContext(context, parameters);
            Pda<ISerState, RuleCall> filtered = filterUnneededUnassignedRuleCalls(merged, indexedRules);
            result.put(context, filtered);
        }
    // }
    }
    return result.create();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) ActionContext(org.eclipse.xtext.serializer.analysis.SerializationContext.ActionContext) Collection(java.util.Collection) Parameter(org.eclipse.xtext.Parameter) HashMap(java.util.HashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

Parameter (org.eclipse.xtext.Parameter)146 ParserRule (org.eclipse.xtext.ParserRule)137 Action (org.eclipse.xtext.Action)127 EPackage (org.eclipse.emf.ecore.EPackage)123 NamedArgument (org.eclipse.xtext.NamedArgument)7 EClass (org.eclipse.emf.ecore.EClass)6 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)6 AbstractElement (org.eclipse.xtext.AbstractElement)5 AbstractRule (org.eclipse.xtext.AbstractRule)5 RuleCall (org.eclipse.xtext.RuleCall)5 EObject (org.eclipse.emf.ecore.EObject)4 ParserRuleParameters (org.eclipse.xtext.parser.parameters.parametersTestLanguage.ParserRuleParameters)4 Scenario (org.eclipse.xtext.parser.parameters.parametersTestLanguage.Scenario)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Group (org.eclipse.xtext.Group)3 ConditionEvaluator (org.eclipse.xtext.xtext.ConditionEvaluator)3 Set (java.util.Set)2 Assignment (org.eclipse.xtext.Assignment)2 EnumRule (org.eclipse.xtext.EnumRule)2 Grammar (org.eclipse.xtext.Grammar)2