Search in sources :

Example 1 with SerializationContextMap

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();
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ParserRule(org.eclipse.xtext.ParserRule) EClass(org.eclipse.emf.ecore.EClass) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Grammar(org.eclipse.xtext.Grammar)

Example 2 with SerializationContextMap

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);
    }
}
Also used : Grammar(org.eclipse.xtext.Grammar) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) ISerState(org.eclipse.xtext.serializer.analysis.ISerState) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List)

Example 3 with SerializationContextMap

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);
}
Also used : SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) Grammar(org.eclipse.xtext.Grammar)

Example 4 with SerializationContextMap

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;
}
Also used : NamedSerializationContexts(org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts) EClass(org.eclipse.emf.ecore.EClass) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)4 Grammar (org.eclipse.xtext.Grammar)3 List (java.util.List)2 EClass (org.eclipse.emf.ecore.EClass)2 ArrayList (java.util.ArrayList)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 ParserRule (org.eclipse.xtext.ParserRule)1 RuleCall (org.eclipse.xtext.RuleCall)1 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 IGrammarConstraintProvider (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider)1 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)1 ISerState (org.eclipse.xtext.serializer.analysis.ISerState)1 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)1 ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)1 Pda (org.eclipse.xtext.util.formallang.Pda)1 NamedSerializationContexts (org.eclipse.xtext.xtext.generator.serializer.NamedSerializationContexts)1