Search in sources :

Example 1 with NamedSerializationContextProvider

use of org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContextProvider 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;
}
Also used : Nfa(org.eclipse.xtext.util.formallang.Nfa) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) ISerState(org.eclipse.xtext.serializer.analysis.ISerState) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair) NamedSerializationContextProvider(org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContextProvider) NamedSerializationContexts(org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts) EqualAmbiguousTransitions(org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions) Extension(org.eclipse.xtext.xbase.lib.Extension) ISemanticSequencerNfaProvider(org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 RuleCall (org.eclipse.xtext.RuleCall)1 ISemanticSequencerNfaProvider (org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider)1 ISerState (org.eclipse.xtext.serializer.analysis.ISerState)1 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)1 Nfa (org.eclipse.xtext.util.formallang.Nfa)1 Pda (org.eclipse.xtext.util.formallang.Pda)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1 EqualAmbiguousTransitions (org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions)1 NamedSerializationContextProvider (org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContextProvider)1 NamedSerializationContexts (org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts)1