Search in sources :

Example 1 with GrammarElementTitleSwitch

use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch 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 GrammarElementTitleSwitch

use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch 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 GrammarElementTitleSwitch

use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.

the class HiddenTokenSequencerTest method getNodeSequence.

@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
    List<String> result = Lists.newArrayList();
    GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
    // System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
    org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model), null, true, true);
    while (ni.hasNext()) {
        INode next = ni.next();
        if (next instanceof ILeafNode)
            result.add(titleSwitch.doSwitch(next.getGrammarElement()) + " -> " + next.getText());
        if (next instanceof ICompositeNode)
            result.add(titleSwitch.doSwitch(next.getGrammarElement()));
    }
    return result;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 4 with GrammarElementTitleSwitch

use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.

the class AbstractFormatter2 method createCommentReplacer.

public ITextReplacer createCommentReplacer(IComment comment) {
    EObject grammarElement = comment.getGrammarElement();
    if (grammarElement instanceof AbstractRule) {
        String ruleName = ((AbstractRule) grammarElement).getName();
        if (ruleName.startsWith("ML"))
            return new MultilineCommentReplacer(comment, '*');
        if (ruleName.startsWith("SL")) {
            if (comment.getLineRegions().get(0).getIndentation().getLength() > 0)
                return new SinglelineDocCommentReplacer(comment, "//");
            else
                return new SinglelineCodeCommentReplacer(comment, "//");
        }
    }
    String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement);
    throw new IllegalStateException("No " + ITextReplacer.class.getSimpleName() + " configured for " + elementName);
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) MultilineCommentReplacer(org.eclipse.xtext.formatting2.internal.MultilineCommentReplacer) EObject(org.eclipse.emf.ecore.EObject) SinglelineCodeCommentReplacer(org.eclipse.xtext.formatting2.internal.SinglelineCodeCommentReplacer) SinglelineDocCommentReplacer(org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 5 with GrammarElementTitleSwitch

use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.

the class SyntacticSequencerDiagnosticProvider method createInvalidFollowingAbsorberDiagnostic.

@Override
public ISerializationDiagnostic createInvalidFollowingAbsorberDiagnostic(ISerializationContext context, EObject semanticObject, ISynAbsorberState from, AbstractElement to) {
    GrammarElementTitleSwitch fmt = new GrammarElementTitleSwitch().showAssignments().showQualified();
    String fromName = from.toString(fmt);
    String toName = to == null ? "stop" : fmt.doSwitch(to);
    List<String> targets = Lists.newArrayList();
    for (ISynTransition trans : from.getOutTransitions()) targets.add(trans.getTarget().toString(fmt));
    StringBuilder msg = new StringBuilder();
    msg.append("State '" + toName + "' may not follow '" + fromName + "'.\n");
    msg.append("Valid followers are: " + Joiner.on(", ").join(targets));
    return new SerializationDiagnostic(INVALID_FOLLOWING_ABSORBER, semanticObject, context, grammarAccess.getGrammar(), msg.toString());
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) ISynTransition(org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition)

Aggregations

GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)13 AbstractElement (org.eclipse.xtext.AbstractElement)4 RuleCall (org.eclipse.xtext.RuleCall)4 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)3 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)3 INode (org.eclipse.xtext.nodemodel.INode)3 ISerState (org.eclipse.xtext.serializer.analysis.ISerState)3 PdaListFormatter (org.eclipse.xtext.util.formallang.PdaListFormatter)3 EObject (org.eclipse.emf.ecore.EObject)2 Grammar (org.eclipse.xtext.Grammar)2 Pda (org.eclipse.xtext.util.formallang.Pda)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 CrossReference (org.eclipse.xtext.CrossReference)1 MultilineCommentReplacer (org.eclipse.xtext.formatting2.internal.MultilineCommentReplacer)1 SinglelineCodeCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineCodeCommentReplacer)1 SinglelineDocCommentReplacer (org.eclipse.xtext.formatting2.internal.SinglelineDocCommentReplacer)1 ContentAssistContext (org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext)1 SyntaxErrorMessage (org.eclipse.xtext.nodemodel.SyntaxErrorMessage)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1