use of org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts in project xtext-core by eclipse.
the class DebugGraphGenerator method generateDebugGraphs.
public Iterable<Pair<String, String>> generateDebugGraphs() {
final ArrayList<Pair<String, String>> result = CollectionLiterals.<Pair<String, String>>newArrayList();
@Extension final NamedSerializationContextProvider names = new NamedSerializationContextProvider(this.grammar);
final String dir_context = this.directory("context");
final String dir_context_type = this.directory("context_type");
final String dir_syntactic_sequencer = this.directory("syntactic_sequencer");
final String dir_semantic_sequencer = this.directory("semantic_sequencer");
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextPDAProvider.getContextPDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e : _namedContexts) {
{
String _name = e.getName();
String _plus = (dir_context + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e.getName();
String _plus_2 = (dir_context + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts_1 = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextTypePDAProvider.getContextTypePDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e_1 : _namedContexts_1) {
{
String _name = e_1.getName();
String _plus = (dir_context_type + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e_1.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_1.getName();
String _plus_2 = (dir_context_type + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_1.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState>> _namedContexts_2 = names.<ISyntacticSequencerPDAProvider.ISynAbsorberState>getNamedContexts(this.syntacticSequencerPDAProvider.getSyntacticSequencerPDAs(this.grammar));
for (final NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState> e_2 : _namedContexts_2) {
{
String _name = e_2.getName();
String _plus = (dir_syntactic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.syntacticSequencerPDA2Dot, e_2.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_2.getName();
String _plus_2 = (dir_syntactic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_2.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>>> _namedContexts_3 = names.<Nfa<ISemanticSequencerNfaProvider.ISemState>>getNamedContexts(this.semanticSequencerNFAProvider.getSemanticSequencerNFAs(this.grammar));
for (final NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>> e_3 : _namedContexts_3) {
{
String _name = e_3.getName();
String _plus = (dir_semantic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.nfaToDot, e_3.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_3.getName();
String _plus_2 = (dir_semantic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_3.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
try {
int i = 0;
final HashMap<ISyntacticSequencerPDAProvider.ISynTransition, String> trans2id = CollectionLiterals.<ISyntacticSequencerPDAProvider.ISynTransition, String>newHashMap();
Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.syntacticSequencerUtil.getAllAmbiguousTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
{
final String name = ("ambiguity_" + Integer.valueOf(i));
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + name);
String _plus_1 = (_plus + ".dot");
String _draw = this.nfaToDot.draw(transition.getAmbiguousNfa());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _draw);
result.add(_mappedTo);
trans2id.put(transition, name);
i = (i + 1);
}
}
final StringBuffer ambiguities = new StringBuffer();
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = this.syntacticSequencerUtil.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("id: ");
String _identifier = group.getIdentifier();
_builder.append(_identifier);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Ambiguous syntax:�:");
_builder.newLine();
_builder.append(" ");
String _replace = group.getElementAlias().toString().replace("\n", "\n ");
_builder.append(_replace, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("This ambiguous syntax occurs at:");
_builder.newLine();
{
List<ISyntacticSequencerPDAProvider.ISynTransition> _transitions = group.getTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition trans : _transitions) {
_builder.append("\t");
String _get = trans2id.get(trans);
_builder.append(_get, "\t");
_builder.append(":");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
String _replace_1 = group.ambiguityInsideTransition(trans).replace("\n", "\n ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.newLine();
ambiguities.append(_builder);
}
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + "ambiguities.txt");
String _string = ambiguities.toString();
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus, _string);
result.add(_mappedTo);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e_4 = (Exception) _t;
e_4.printStackTrace();
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
use of org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts 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