Search in sources :

Example 1 with PdaListFormatter

use of org.eclipse.xtext.util.formallang.PdaListFormatter in project xtext-core by eclipse.

the class ContextPDAProviderTest method getParserRule.

protected String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    List<String> result = Lists.newArrayList();
    PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
    formatter.setStateFormatter(new ToStr());
    formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
    formatter.sortFollowers();
    IContextPDAProvider pdaProvider = get(IContextPDAProvider.class);
    SerializationContextMap<Pda<ISerState, RuleCall>> pdas = pdaProvider.getContextPDAs(grammar);
    for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
        Pda<ISerState, RuleCall> pda = ctx.getValue();
        result.add("  " + formatter.format(pda).replace("\n", "\n  "));
    // StackTraceElement ele = Thread.currentThread().getStackTrace()[2];
    // String name = getClass().getSimpleName() + "_" + ele.getMethodName() + "_" + ctx.getSecond() + ".pdf";
    // new PdaToDot<ISerState, RuleCall>().draw(pda, "dot/" + name, "-T pdf");
    }
    return Joiner.on("\n").join(result);
}
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) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) PdaListFormatter(org.eclipse.xtext.util.formallang.PdaListFormatter) IContextPDAProvider(org.eclipse.xtext.serializer.analysis.IContextPDAProvider)

Example 2 with PdaListFormatter

use of org.eclipse.xtext.util.formallang.PdaListFormatter in project xtext-core by eclipse.

the class ContextTypePDAProviderTest method getParserRule.

protected String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    // drawGrammar("pdf/" + getName(), grammar);
    List<String> result = Lists.newArrayList();
    PdaListFormatter<ISerState, RuleCall> formatter = new PdaListFormatter<ISerState, RuleCall>();
    formatter.setStateFormatter(new ToStr());
    formatter.setStackitemFormatter(new GrammarElementTitleSwitch().showAssignments().hideCardinality());
    formatter.sortFollowers();
    IContextTypePDAProvider typePDAProvider = get(IContextTypePDAProvider.class);
    SerializationContextMap<Pda<ISerState, RuleCall>> pdas = typePDAProvider.getContextTypePDAs(grammar);
    for (Entry<Pda<ISerState, RuleCall>> ctx : pdas.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(ctx.getContexts()) + ":");
        result.add("  " + formatter.format(ctx.getValue()).replace("\n", "\n  "));
    }
    return Joiner.on("\n").join(result);
}
Also used : Grammar(org.eclipse.xtext.Grammar) Pda(org.eclipse.xtext.util.formallang.Pda) RuleCall(org.eclipse.xtext.RuleCall) IContextTypePDAProvider(org.eclipse.xtext.serializer.analysis.IContextTypePDAProvider) ISerState(org.eclipse.xtext.serializer.analysis.ISerState) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) PdaListFormatter(org.eclipse.xtext.util.formallang.PdaListFormatter)

Example 3 with PdaListFormatter

use of org.eclipse.xtext.util.formallang.PdaListFormatter 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)

Aggregations

RuleCall (org.eclipse.xtext.RuleCall)3 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)3 ISerState (org.eclipse.xtext.serializer.analysis.ISerState)3 PdaListFormatter (org.eclipse.xtext.util.formallang.PdaListFormatter)3 Grammar (org.eclipse.xtext.Grammar)2 Pda (org.eclipse.xtext.util.formallang.Pda)2 IContextPDAProvider (org.eclipse.xtext.serializer.analysis.IContextPDAProvider)1 IContextTypePDAProvider (org.eclipse.xtext.serializer.analysis.IContextTypePDAProvider)1