use of org.eclipse.xtext.serializer.analysis.SerializationContextMap in project xtext-core by eclipse.
the class SyntacticSequencerPDAProviderNavigatorTest method getParserRule.
protected ISynAbsorberState getParserRule(String body, String name, String typeName) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
// SyntacticSequencerPDA2SimpleDot.drawGrammar("pdf/" + getName(),
// grammar);
// SyntacticSequencerPDA2ExtendedDot.drawGrammar(createSequenceParserPDAProvider(),
// "pdf/" + getName(), grammar);
ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
for (SerializationContextMap.Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
for (ISerializationContext context : e.getContexts()) {
if (context.getAssignedAction() != null)
continue;
ISynAbsorberState pda = e.getValue();
ParserRule rule = context.getParserRule();
EClass type = context.getType();
boolean nameMatches = rule == null || name == null || rule.getName().equals(name);
boolean typeMatches = type == null || typeName == null || typeName.equals(type.getName());
if (nameMatches && typeMatches)
return pda;
}
}
throw new IllegalStateException();
}
use of org.eclipse.xtext.serializer.analysis.SerializationContextMap in project xtext-core by eclipse.
the class GrammarPDAProviderTest method toPda.
private String toPda(final CharSequence rulesText) {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar org.eclipse.xtext.serializer.GrammarPDAProviderTestLanguage with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.newLine();
_builder.append("generate GrammarPDAProviderTest \"http://www.eclipse.org/2010/tmf/xtext/GrammarPDAProviderTestLanguage\"");
_builder.newLine();
_builder.newLine();
_builder.append(rulesText);
_builder.newLineIfNotEmpty();
final Grammar grammar = this.parser.parse(_builder);
this.validator.assertNoErrors(grammar);
final SerializationContextMap<Pda<ISerState, RuleCall>> pdas = this.pdaProvider.getGrammarPDAs(grammar);
final Consumer<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>> _function = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
this.assertNoLeakedGrammarElements(grammar, it.getValue());
};
pdas.values().forEach(_function);
final Function1<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>> _function_1 = (SerializationContextMap.Entry<Pda<ISerState, RuleCall>> it) -> {
return it.getContexts();
};
final Function1<ISerializationContext, String> _function_2 = (ISerializationContext it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(it);
_builder_1.append(":");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
String _listString = this.toListString(pdas.get(it));
_builder_1.append(_listString, "\t");
_builder_1.newLineIfNotEmpty();
return _builder_1.toString();
};
return IterableExtensions.join(ListExtensions.<ISerializationContext, String>map(IterableExtensions.<ISerializationContext>sort(Iterables.<ISerializationContext>concat(ListExtensions.<SerializationContextMap.Entry<Pda<ISerState, RuleCall>>, List<ISerializationContext>>map(pdas.values(), _function_1))), _function_2));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.serializer.analysis.SerializationContextMap in project xtext-core by eclipse.
the class GrammarConstraintProviderAssignedActionTest method getParserRule.
private String getParserRule(String body) throws Exception {
Grammar grammar = (Grammar) getModel(HEADER + body);
IGrammarConstraintProvider gcp = get(IGrammarConstraintProvider.class);
// try {
// new ActionFilter2Dot().draw(grammar, getName() + ".pdf", "-T pdf");
// } catch (IOException e) {
// if (log.isDebugEnabled())
// log.debug(e.getMessage(), e);
// }
SerializationContextMap<IConstraint> constraints = gcp.getConstraints(grammar);
List<String> result = Lists.newArrayList();
for (SerializationContextMap.Entry<IConstraint> r : constraints.sortedCopy().values()) {
result.add(Joiner.on(", ").join(r.getContexts()) + ":");
result.add(" " + r.getValue());
}
return Joiner.on("\n").join(result);
}
use of org.eclipse.xtext.serializer.analysis.SerializationContextMap in project xtext-core by eclipse.
the class NamedSerializationContextProvider method getNamedContexts.
public <T extends Object> List<NamedSerializationContexts<T>> getNamedContexts(final SerializationContextMap<T> map) {
final ArrayList<NamedSerializationContexts<T>> result = CollectionLiterals.<NamedSerializationContexts<T>>newArrayList();
final HashMap<String, Integer> names = CollectionLiterals.<String, Integer>newHashMap();
List<SerializationContextMap.Entry<T>> _values = map.values();
for (final SerializationContextMap.Entry<T> e : _values) {
Set<EClass> _types = e.getTypes();
for (final EClass t : _types) {
{
final List<ISerializationContext> ctx = e.getContexts(t);
String _xifexpression = null;
if ((t == null)) {
_xifexpression = "";
} else {
_xifexpression = t.getName();
}
String _plus = (_xifexpression + "_");
String _significantGrammarElement = this.getSignificantGrammarElement(ctx);
final String name = (_plus + _significantGrammarElement);
final Integer dup = names.get(name);
String _xifexpression_1 = null;
if ((dup == null)) {
String _xblockexpression = null;
{
names.put(name, Integer.valueOf(1));
_xblockexpression = name;
}
_xifexpression_1 = _xblockexpression;
} else {
String _xblockexpression_1 = null;
{
names.put(name, Integer.valueOf(((dup).intValue() + 1)));
_xblockexpression_1 = ((name + "_") + dup);
}
_xifexpression_1 = _xblockexpression_1;
}
final String unique = _xifexpression_1;
T _value = e.getValue();
NamedSerializationContexts<T> _namedSerializationContexts = new NamedSerializationContexts<T>(unique, t, ctx, _value);
result.add(_namedSerializationContexts);
}
}
}
return result;
}
Aggregations