use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class ContentAssistContextTestHelper method firstSetGrammarElementsToString.
public String firstSetGrammarElementsToString(final ContentAssistContextFactory factory) {
final int offset = this.document.indexOf(this.cursor);
Preconditions.checkArgument((offset >= 0), "you forgot to provide a cursor");
final String doc = this.document.replace(this.cursor, "");
final XtextResource res = this.parse(doc);
factory.setPool(Executors.newCachedThreadPool());
TextRegion _textRegion = new TextRegion(0, 0);
final ContentAssistContext[] ctxs = factory.create(doc, _textRegion, offset, res);
final GrammarElementTitleSwitch f = new GrammarElementTitleSwitch().showAssignments().showQualified().showRule();
StringConcatenation _builder = new StringConcatenation();
{
Iterable<Pair<Integer, ContentAssistContext>> _indexed = IterableExtensions.<ContentAssistContext>indexed(((Iterable<? extends ContentAssistContext>) Conversions.doWrapArray(ctxs)));
for (final Pair<Integer, ContentAssistContext> ctx : _indexed) {
_builder.append("context");
Integer _key = ctx.getKey();
_builder.append(_key);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
ImmutableList<AbstractElement> _firstSetGrammarElements = ctx.getValue().getFirstSetGrammarElements();
for (final AbstractElement ele : _firstSetGrammarElements) {
_builder.append("\t");
String _name = ele.eClass().getName();
_builder.append(_name, "\t");
_builder.append(": ");
String _apply = f.apply(ele);
_builder.append(_apply, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
}
}
return _builder.toString();
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class FirstSetComputationTest method assertFirstSet.
protected void assertFirstSet(String expectation, AbstractRule rule) {
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
ruleCall.setRule(rule);
List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall);
StringBuilder actual = new StringBuilder();
GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch();
for (int i = 0; i < firstSet.size(); i++) {
if (i != 0)
actual.append(", ");
actual.append(stringifier.apply(firstSet.get(i)));
}
assertEquals(expectation, actual.toString());
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class SyntacticSequencerDiagnosticProvider method createUnexpectedStackStateDiagnostic.
@Override
public ISerializationDiagnostic createUnexpectedStackStateDiagnostic(EObject semanticObject, RuleCallStack stack, RuleCall popped, ISynState toConsume) {
String poppedStr = popped == null ? "null" : new GrammarElementTitleSwitch().showAssignments().doSwitch(popped);
StringBuilder buf = new StringBuilder();
buf.append("Unexpected stack state.\n");
buf.append("Found on top of the stack: " + poppedStr + "\n");
buf.append("Expected: " + toConsume + "\n");
buf.append("Rest of the stack: " + stack + "\n");
return new SerializationDiagnostic(UNEXPECTED_STACK_TRACE, semanticObject, (ISerializationContext) null, grammarAccess.getGrammar(), buf.toString());
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch in project xtext-core by eclipse.
the class NodeModelUtils method compactDump.
private static void compactDump(INode node, boolean showHidden, String prefix, Appendable result) throws IOException {
if (!showHidden && node instanceof ILeafNode && ((ILeafNode) node).isHidden())
return;
if (prefix.length() != 0) {
result.append("\n");
result.append(prefix);
}
if (node instanceof ICompositeNode) {
if (node.getGrammarElement() != null)
result.append(new GrammarElementTitleSwitch().showAssignments().doSwitch(node.getGrammarElement()));
else
result.append("(unknown)");
String newPrefix = prefix + " ";
result.append(" {");
BidiIterator<INode> children = ((ICompositeNode) node).getChildren().iterator();
while (children.hasNext()) {
INode child = children.next();
compactDump(child, showHidden, newPrefix, result);
}
result.append("\n");
result.append(prefix);
result.append("}");
SyntaxErrorMessage error = node.getSyntaxErrorMessage();
if (error != null)
result.append(" SyntaxError: [" + error.getIssueCode() + "] " + error.getMessage());
} else if (node instanceof ILeafNode) {
if (((ILeafNode) node).isHidden())
result.append("hidden ");
if (node.getGrammarElement() != null)
result.append(new GrammarElementTitleSwitch().showAssignments().doSwitch(node.getGrammarElement()));
else
result.append("(unknown)");
result.append(" => '");
result.append(node.getText());
result.append("'");
SyntaxErrorMessage error = node.getSyntaxErrorMessage();
if (error != null)
result.append(" SyntaxError: [" + error.getIssueCode() + "] " + error.getMessage());
} else if (node == null) {
result.append("(null)");
} else {
result.append("unknown type ");
result.append(node.getClass().getName());
}
}
use of org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch 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");
}
Aggregations