Search in sources :

Example 6 with ISerState

use of org.eclipse.xtext.serializer.analysis.ISerState 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)

Example 7 with ISerState

use of org.eclipse.xtext.serializer.analysis.ISerState in project xtext-core by eclipse.

the class GrammarPDAProviderTest method toListString.

private String toListString(final Pda<ISerState, RuleCall> pda) {
    final GrammarElementTitleSwitch ts = new GrammarElementTitleSwitch().showAssignments().hideCardinality().showQualified();
    final PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
    final Function<ISerState, String> _function = (ISerState it) -> {
        String _switchResult = null;
        ISerState.SerStateType _type = it.getType();
        if (_type != null) {
            switch(_type) {
                case START:
                    _switchResult = "start";
                    break;
                case STOP:
                    _switchResult = "stop";
                    break;
                default:
                    _switchResult = ts.apply(it.getGrammarElement());
                    break;
            }
        } else {
            _switchResult = ts.apply(it.getGrammarElement());
        }
        return _switchResult;
    };
    formatter.setStateFormatter(_function);
    formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
    formatter.sortFollowers();
    String _format = formatter.format(pda);
    return (_format + "\n");
}
Also used : ISerState(org.eclipse.xtext.serializer.analysis.ISerState) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) PdaListFormatter(org.eclipse.xtext.util.formallang.PdaListFormatter) RuleCall(org.eclipse.xtext.RuleCall)

Example 8 with ISerState

use of org.eclipse.xtext.serializer.analysis.ISerState in project xtext-core by eclipse.

the class GrammarPDAProviderTest method assertNoLeakedGrammarElements.

private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
    final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
        return it.getGrammarElement();
    };
    Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
    for (final AbstractElement ele : _filterNull) {
        {
            final Grammar actual = GrammarUtil.getGrammar(ele);
            if ((actual != grammar)) {
                String _objPath = EmfFormatter.objPath(ele);
                String _plus = ("Element " + _objPath);
                String _plus_1 = (_plus + " leaked!");
                Assert.fail(_plus_1);
            }
        }
    }
}
Also used : ISerState(org.eclipse.xtext.serializer.analysis.ISerState) AbstractElement(org.eclipse.xtext.AbstractElement) NfaUtil(org.eclipse.xtext.util.formallang.NfaUtil) Grammar(org.eclipse.xtext.Grammar)

Aggregations

ISerState (org.eclipse.xtext.serializer.analysis.ISerState)8 RuleCall (org.eclipse.xtext.RuleCall)5 Grammar (org.eclipse.xtext.Grammar)4 Pda (org.eclipse.xtext.util.formallang.Pda)4 AbstractElement (org.eclipse.xtext.AbstractElement)3 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)3 PdaListFormatter (org.eclipse.xtext.util.formallang.PdaListFormatter)3 List (java.util.List)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 IAstRegion (org.eclipse.xtext.formatting2.regionaccess.IAstRegion)1 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 IContextPDAProvider (org.eclipse.xtext.serializer.analysis.IContextPDAProvider)1 IContextTypePDAProvider (org.eclipse.xtext.serializer.analysis.IContextTypePDAProvider)1 ISemanticSequencerNfaProvider (org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider)1 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)1 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1 Nfa (org.eclipse.xtext.util.formallang.Nfa)1 NfaUtil (org.eclipse.xtext.util.formallang.NfaUtil)1