Search in sources :

Example 1 with IContextTypePDAProvider

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

Aggregations

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