use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class PsiAntlrGrammarGenerator method compileParserMembers.
@Override
protected String compileParserMembers(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("@parser::members {");
_builder.newLine();
_builder.newLine();
{
boolean _isBacktrack = options.isBacktrack();
if (_isBacktrack) {
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("This grammar contains a lot of empty actions to work around a bug in ANTLR.");
_builder.newLine();
_builder.append(" ");
_builder.append("Otherwise the ANTLR tool will create synpreds that cannot be compiled in some rare cases.");
_builder.newLine();
_builder.append("*/");
_builder.newLine();
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("protected ");
String _simpleName = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
_builder.append(_simpleName, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
String _simpleName_1 = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it)).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append(" elementTypeProvider;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_2 = this._ideaPluginClassNames.getPsiInternalParser(GrammarUtil.getGrammar(it)).getSimpleName();
_builder.append(_simpleName_2, "\t");
_builder.append("(PsiBuilder builder, TokenStream input, ");
String _simpleName_3 = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it)).getSimpleName();
_builder.append(_simpleName_3, "\t");
_builder.append(" elementTypeProvider, ");
String _simpleName_4 = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
_builder.append(_simpleName_4, "\t");
_builder.append(" grammarAccess) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("this(input);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("setPsiBuilder(builder);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this.grammarAccess = grammarAccess;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this.elementTypeProvider = elementTypeProvider;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected String getFirstRuleName() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"");
ParserRule _originalElement = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(IterableExtensions.<ParserRule>head(GrammarUtil.allParserRules(it)));
String _name = ((AbstractRule) _originalElement).getName();
_builder.append(_name, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class AbstractAntlrGrammarGenerator method _assignmentEbnf.
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
String _switchResult = null;
AbstractRule _rule = it.getRule();
final AbstractRule rule = _rule;
boolean _matched = false;
if (rule instanceof EnumRule) {
_matched = true;
}
if (!_matched) {
if (rule instanceof ParserRule) {
_matched = true;
}
}
if (!_matched) {
if (rule instanceof TerminalRule) {
_matched = true;
}
}
if (_matched) {
_switchResult = this._grammarAccessExtensions.ruleName(rule);
}
if (!_matched) {
throw new IllegalStateException(("assignmentEbnf is not supported for " + rule));
}
return _switchResult;
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class GrammarElementTitleSwitch method caseRuleCall.
@Override
public String caseRuleCall(RuleCall object) {
AbstractRule rule = object.getRule();
String ruleName;
if (rule != null && !rule.eIsProxy())
ruleName = rule.getName();
else
ruleName = "unresolved_rule";
return addCrossRefOrAssignemnt(ruleName, object) + card(object);
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class Linker method ensureLinked.
private void ensureLinked(EObject obj, IDiagnosticProducer producer, ICompositeNode node, Set<EReference> handledReferences, boolean dontCheckParent) {
for (INode abstractNode = node.getFirstChild(); abstractNode != null; abstractNode = abstractNode.getNextSibling()) {
EObject grammarElement = abstractNode.getGrammarElement();
if (grammarElement instanceof CrossReference) {
CrossReference ref = (CrossReference) grammarElement;
producer.setNode(abstractNode);
ensureIsLinked(obj, abstractNode, ref, handledReferences, producer);
} else if (grammarElement instanceof RuleCall && abstractNode instanceof ICompositeNode) {
RuleCall ruleCall = (RuleCall) grammarElement;
AbstractRule calledRule = ruleCall.getRule();
if (calledRule instanceof ParserRule && ((ParserRule) calledRule).isFragment()) {
ensureLinked(obj, producer, (ICompositeNode) abstractNode, handledReferences, true);
}
}
}
if (!dontCheckParent && shouldCheckParentNode(node)) {
ensureLinked(obj, producer, node.getParent(), handledReferences, false);
}
}
use of org.eclipse.xtext.AbstractRule in project xtext-core by eclipse.
the class AbstractFormattingConfig method getAbstractElements.
protected List<AbstractElement> getAbstractElements(EObject obj) {
if (obj instanceof AbstractElement)
return Collections.singletonList((AbstractElement) obj);
if (obj instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) obj;
if (rule.getType().getClassifier() instanceof EClass)
return Collections.singletonList(rule.getAlternatives());
List<AbstractElement> result = Lists.newArrayList();
for (RuleCall rc : grammarAccess.findRuleCalls(rule)) {
CrossReference cr = GrammarUtil.containingCrossReference(rc);
result.add(cr == null ? rc : cr);
}
return result;
}
return null;
}
Aggregations