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);
}
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);
}
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;
}
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);
}
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());
}
Aggregations