public static AbstractRule findRuleForName(Grammar grammar, String ruleName) { if (ruleName == null) return null; List<AbstractRule> rules = allRules(grammar); for (AbstractRule abstractRule : rules) { if (ruleName.equals(abstractRule.getName())) { return abstractRule; } } return null; }
@Override public boolean apply(AbstractElement input) { return input instanceof RuleCall && "NL".equals(((RuleCall) input).getRule().getName()); //$NON-NLS-1$ } };
public String toString(String value) throws ValueConverterException { if (keywords.contains(value)) return value; String result = delegateService.toString(value, delegateRule.getName()); return result; }
public String getId(AbstractRule rule) { if (!(rule instanceof ParserRule)) throw new IllegalArgumentException("Unsupported context rule: " + rule); return GrammarUtil.getGrammar(rule).getName()+"."+rule.getName(); }
protected boolean hasIdRule(final CrossReference crossRef) { AbstractElement _terminal = crossRef.getTerminal(); if ((_terminal instanceof RuleCall)) { AbstractElement _terminal_1 = crossRef.getTerminal(); final String ruleName = ((RuleCall) _terminal_1).getRule().getName(); return ((Objects.equal(ruleName, "IdOrSuper") || Objects.equal(ruleName, "ValidID")) || Objects.equal(ruleName, "FeatureCallID")); } return false; }
protected String getNameRuleName(EObject targetElement, EAttribute nameAttribute) { List<INode> nameNodes = NodeModelUtils.findNodesForFeature(targetElement, nameAttribute); if(nameNodes.size() == 1) { EObject grammarElement = nameNodes.get(0).getGrammarElement(); if(grammarElement instanceof RuleCall) { AbstractRule nameRule = ((RuleCall) grammarElement).getRule(); if(nameRule != null) return nameRule.getName(); } } return null; }
public ISerializationDiagnostic getInvalidEnumValueDiagnostic(EObject semanticObject, RuleCall rc, Object value) { List<String> valid = Lists.newArrayList(); for (EnumLiteralDeclaration eld : org.eclipse.xtext.EcoreUtil2.getAllContentsOfType(rc.getRule(), EnumLiteralDeclaration.class)) valid.add(eld.getEnumLiteral().getInstance().getName()); StringBuilder msg = new StringBuilder(); msg.append("The value '" + value + "' is invalid for enum " + rc.getRule().getName() + "\n"); msg.append("Valid values are: " + Joiner.on(", ").join(valid)); return new SerializationDiagnostic(INVALID_ENUM_VALUE, semanticObject, rc, msg.toString()); }
public String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node) { if (node != null) { Object converted = converter.toValue(serialize(node), ruleCall.getRule().getName(), node); if (converted != null && converted.equals(value)) return ITokenSerializer.KEEP_VALUE_FROM_NODE_MODEL; } return converter.toString(value, ruleCall.getRule().getName()); }
protected String _crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) { boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it)); if (_isDatatypeRule) { return this._grammarAccessExtensions.ruleName(it); } String _name = it.getName(); String _plus = (_name + " is not a datatype rule"); throw new IllegalArgumentException(_plus); }
protected String _localVar(final RuleCall it) { String _name = AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it.getRule()).getName(); String _plus = ("this_" + _name); String _plus_1 = (_plus + "_"); int _indexOf = this.contentsAsList(GrammarUtil.containingParserRule(it)).indexOf(it); return (_plus_1 + Integer.valueOf(_indexOf)); }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
@Override protected Collection<FollowElement> getFollowElements(AbstractInternalContentAssistParser parser) { if (rule == null || rule.eIsProxy()) return Collections.emptyList(); String methodName = "entryRule" + rule.getName(); PolymorphicDispatcher<Collection<FollowElement>> dispatcher = new PolymorphicDispatcher<Collection<FollowElement>>(methodName, 0, 0, Collections.singletonList(parser)); dispatcher.invoke(); return parser.getFollowElements(); }
@Override protected Node newNode(EObject semanticObject, String label) { if (semanticObject.eContainer() instanceof AbstractRule) { AbstractRule rule = (AbstractRule) semanticObject.eContainer(); return new Node(semanticObject, rule.getName() + ":\\n" + label, "record"); } else { return new Node(semanticObject, label); } } }
private CharSequence unassignedCalledTokenRuleName(final AbstractRule rule) { StringConcatenation _builder = new StringConcatenation(); _builder.append("get"); String _name = rule.getName(); _builder.append(_name); _builder.append("Token"); return _builder; }
public boolean equalsOrReplacesNode(EObject context, RuleCall ruleCall, Object value, INode node) { if (ruleCall != node.getGrammarElement()) return false; Assignment ass = GrammarUtil.containingAssignment(ruleCall); if (GrammarUtil.isSingleAssignment(ass)) return true; Object converted = converter.toValue(serialize(node), ruleCall.getRule().getName(), node); return converted != null && converted.equals(value); }
@Override public IParseResult parse(RuleCall ruleCall, Reader reader, int initialLookAhead) { NodeModelBuilder builder = createNodeModelBuilder(); builder.setForcedFirstGrammarElement(ruleCall); IParseResult parseResult = doParse(ruleCall.getRule().getName(), new ReaderCharStream(reader), builder, initialLookAhead); return parseResult; }
private EClassifierInfo findOrCreateEClassifierInfo(AbstractRule rule) throws TransformationException { final TypeRef typeRef = getOrComputeReturnType(rule); if (typeRef == null) throw new TransformationException(TransformationErrorCode.NoSuchTypeAvailable, "Cannot create type for unnamed rule.", rule); if (typeRef.getMetamodel() != null && typeRef.getMetamodel().getEPackage() == null) throw new TransformationException(TransformationErrorCode.UnknownMetaModelAlias, "Cannot create type without declared package.", typeRef); return findOrCreateEClassifierInfo(typeRef, rule.getName(), grammar.getRules().contains(rule)); }