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