use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class ContextTypePDAProvider method getContextTypePDAs.
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getContextTypePDAs(Grammar grammar) {
SerializationContextMap<Pda<ISerState, RuleCall>> cached = cache.get(grammar);
if (cached != null)
return cached;
SerializationContextMap.Builder<Pda<ISerState, RuleCall>> builder = SerializationContextMap.builder();
SerializationContextMap<Pda<ISerState, RuleCall>> contextPDAs = pdaProvider.getContextPDAs(grammar);
for (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> e : contextPDAs.values()) {
List<ISerializationContext> parents = e.getContexts();
Pda<ISerState, RuleCall> contextPDA = e.getValue();
try {
Map<ISerState, Integer> distances = nfaUtil.distanceToFinalStateMap(contextPDA);
Set<EClass> types = collectTypes(contextPDA, distances);
if (types.size() == 1) {
for (ISerializationContext parent : parents) {
TypeContext ctx = new TypeContext(parent, types.iterator().next());
builder.put(ctx, contextPDA);
}
} else {
for (EClass type : types) {
Pda<ISerState, RuleCall> filtered = filterByType(contextPDA, type, distances);
for (ISerializationContext parent : parents) {
TypeContext typeContext = new TypeContext(parent, type);
builder.put(typeContext, filtered);
}
}
}
} catch (Exception x) {
LOG.error("Error extracting PDAs for types for context '" + parents + "': " + x.getMessage(), x);
}
}
SerializationContextMap<Pda<ISerState, RuleCall>> result = builder.create();
cache.put(grammar, result);
return result;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class GrammarConstraintProvider method collectAllParameterValues.
protected Multimap<Parameter, Boolean> collectAllParameterValues(IConstraint constraint) {
Set<Parameter> all = Sets.newLinkedHashSet();
List<ISerializationContext> contexts = constraint.getContexts();
for (ISerializationContext context : contexts) {
all.addAll(((SerializationContext) context).getDeclaredParameters());
}
Multimap<Parameter, Boolean> values = LinkedHashMultimap.create();
for (ISerializationContext ctx : contexts) {
Set<Parameter> params = ctx.getEnabledBooleanParameters();
for (Parameter param : all) values.put(param, params != null && params.contains(param));
}
return values;
}
use of org.eclipse.xtext.serializer.ISerializationContext in project xtext-core by eclipse.
the class GrammarPDAProvider method getGrammarPDAs.
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getGrammarPDAs(Grammar grammar) {
RuleNames names = RuleNames.getRuleNames(grammar, true);
RuleFilter filter = new RuleFilter();
filter.setDiscardTerminalRules(true);
filter.setDiscardUnreachableRules(false);
filter.setDiscardRuleTypeRef(false);
Grammar flattened = new FlattenedGrammarAccess(names, filter).getFlattenedGrammar();
Builder<Pda<ISerState, RuleCall>> result = SerializationContextMap.<Pda<ISerState, RuleCall>>builder();
for (ParserRule rule : GrammarUtil.allParserRules(flattened)) {
RuleWithParameterValues withParams = RuleWithParameterValues.findInEmfObject(rule);
AbstractRule original = withParams.getOriginal();
if (original instanceof ParserRule && isValidRule((ParserRule) original)) {
ISerializationContext context = createContext((ParserRule) original, withParams.getParamValues());
try {
Pda<ISerState, RuleCall> pda = createPDA(grammar, rule);
result.put(context, pda);
} catch (Exception e) {
LOG.error("Error creating PDA for context '" + context + "': " + e.getMessage(), e);
}
}
}
return result.create();
}
use of org.eclipse.xtext.serializer.ISerializationContext 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.xtext.serializer.ISerializationContext 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;
}
Aggregations