Search in sources :

Example 1 with ISyntacticSequencerPDAProvider

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

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

the class SyntacticSequencerPDAProviderTest method getParserRule.

// public void drawGrammar(String path, Grammar grammar) {
// try {
// IContextPDAProvider contexts = get(IContextPDAProvider.class);
// IContextTypePDAProvider types = get(IContextTypePDAProvider.class);
// SyntacticSequencerPDA2ExtendedDot seq2dot = get(SyntacticSequencerPDA2ExtendedDot.class);
// for (EObject ctx : contexts.getAllContexts(grammar))
// for (EClass type : types.getTypesForContext(grammar, ctx))
// seq2dot.draw(new Pair<EObject, EClass>(ctx, type),
// path + "-" + new Context2NameFunction().toFunction(grammar).apply(ctx) + "_"
// + (type == null ? "null" : type.getName()) + "-PDA.pdf",
// "-T pdf");
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
protected String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    // StackTraceElement ele = Thread.currentThread().getStackTrace()[2];
    // drawGrammar("pdf/" + ele.getMethodName(), grammar);
    ISyntacticSequencerPDAProvider pdaProvider = get(ISyntacticSequencerPDAProvider.class);
    SerializationContextMap<ISynAbsorberState> pdas = pdaProvider.getSyntacticSequencerPDAs(grammar);
    List<String> result = Lists.newArrayList();
    for (Entry<ISynAbsorberState> e : pdas.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(e.getContexts()) + ":");
        result.addAll(pda2lines2(e.getValue()));
    }
    return Joiner.on("\n").join(result);
}
Also used : ISynAbsorberState(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState) ISyntacticSequencerPDAProvider(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider) Grammar(org.eclipse.xtext.Grammar)

Aggregations

Grammar (org.eclipse.xtext.Grammar)2 ISyntacticSequencerPDAProvider (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider)2 ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)2 EClass (org.eclipse.emf.ecore.EClass)1 ParserRule (org.eclipse.xtext.ParserRule)1 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1