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));
}
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));
}
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();
}
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));
}
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();
}
Aggregations