Пример #1
0
 private String getDefaultAntlrRuleName(AbstractRule rule) {
   if (rule instanceof ParserRule || rule instanceof EnumRule) {
     return "rule" + rule.getName();
   }
   if (rule instanceof TerminalRule) {
     return "RULE_" + rule.getName().toUpperCase();
   }
   throw new IllegalArgumentException(rule.eClass().getName());
 }
Пример #2
0
 private String getInheritedUniqueName(AbstractRule rule, Set<String> usedNames) {
   String grammarName = GrammarUtil.getSimpleName(GrammarUtil.getGrammar(rule));
   String candidate = grammarName + rule.getName();
   int i = 1;
   while (usedNames.contains(candidate)) {
     candidate = grammarName + i + rule.getName();
     i++;
   }
   return candidate;
 }
 protected boolean hasIdRule(final CrossReference crossRef) {
   AbstractElement _terminal = crossRef.getTerminal();
   if ((_terminal instanceof RuleCall)) {
     AbstractElement _terminal_1 = crossRef.getTerminal();
     AbstractRule _rule = ((RuleCall) _terminal_1).getRule();
     final String ruleName = _rule.getName();
     boolean _or = false;
     boolean _or_1 = false;
     boolean _equals = Objects.equal(ruleName, "IdOrSuper");
     if (_equals) {
       _or_1 = true;
     } else {
       boolean _equals_1 = Objects.equal(ruleName, "ValidID");
       _or_1 = _equals_1;
     }
     if (_or_1) {
       _or = true;
     } else {
       boolean _equals_2 = Objects.equal(ruleName, "FeatureCallID");
       _or = _equals_2;
     }
     return _or;
   }
   return false;
 }
 public CharSequence unassignedCalledTokenRuleName(final AbstractRule rule) {
   StringConcatenation _builder = new StringConcatenation();
   _builder.append("get");
   String _name = rule.getName();
   _builder.append(_name, "");
   _builder.append("Token");
   return _builder;
 }
Пример #5
0
 @Inject
 public void computeDirectiveRules() {
   List<AbstractRule> allRules = GrammarUtil.allRules(jstGrammarAccess.getGrammar());
   for (AbstractRule rule : allRules) {
     if (rule instanceof TerminalRule && rule.getName().startsWith("DIRECTIVE")) {
       directiveRules.add((TerminalRule) rule);
     }
   }
 }
Пример #6
0
 protected String _localVar(final RuleCall it) {
   AbstractRule _rule = it.getRule();
   String _name = _rule.getName();
   String _plus = ("this_" + _name);
   String _plus_1 = (_plus + "_");
   ParserRule _containingParserRule = GrammarUtil.containingParserRule(it);
   List<AbstractElement> _contentsAsList = this.contentsAsList(_containingParserRule);
   int _indexOf = _contentsAsList.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();
 }
Пример #8
0
 private String getInheritedAntlrRuleName(AbstractRule rule, Set<String> usedNames) {
   if (rule instanceof ParserRule || rule instanceof EnumRule) {
     String candidate = "super" + rule.getName();
     int i = 1;
     while (usedNames.contains(candidate)) {
       candidate = "super" + i + rule.getName();
       i++;
     }
     return candidate;
   }
   if (rule instanceof TerminalRule) {
     String candidate = "SUPER_" + rule.getName();
     int i = 1;
     while (usedNames.contains(candidate)) {
       candidate = "SUPER_" + i + "_" + rule.getName();
       i++;
     }
     return candidate;
   }
   throw new IllegalArgumentException(rule.eClass().getName());
 }
Пример #9
0
 protected String _toXtext(final RuleCall rc) {
   AbstractRule _rule = rc.getRule();
   String _name = _rule.getName();
   String _elvis = null;
   String _cardinality = rc.getCardinality();
   if (_cardinality != null) {
     _elvis = _cardinality;
   } else {
     _elvis = "";
   }
   return (_name + _elvis);
 }
Пример #10
0
  public RuleNames(Grammar grammar, boolean installAdapter) {
    this.contextGrammar = grammar;
    Adapter adapter = new Adapter(this);
    if (installAdapter) {
      installAdapterIfMissing(adapter, grammar);
    }
    List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
    ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder =
        ImmutableListMultimap.builder();
    ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder();
    ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder();

    Map<String, AbstractRule> names = Maps.newHashMap();
    Set<String> usedAntlrNames = Sets.newHashSet();
    Set<String> usedUniqueNames = Sets.newHashSet();
    for (AbstractRule rule : allRules) {
      String name = rule.getName();
      simpleNameToRulesBuilder.put(name, rule);
      String qualifiedName = getQualifiedName(rule);
      qualifiedNameToRuleBuilder.put(qualifiedName, rule);
      String uniqueName = name;
      String antlrRuleName;
      if (names.containsKey(name)) {
        name = qualifiedName;
        uniqueName = getInheritedUniqueName(rule, usedUniqueNames);
        antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames);
      } else {
        antlrRuleName = getDefaultAntlrRuleName(rule);
      }
      names.put(name, rule);
      if (!usedUniqueNames.add(uniqueName)) {
        throw new IllegalStateException(uniqueName);
      }
      uniqueNameToRuleBuilder.put(uniqueName, rule);
      if (!usedAntlrNames.add(antlrRuleName)) {
        throw new IllegalStateException(antlrRuleName);
      }
      antlrNameToRuleBuilder.put(antlrRuleName, rule);
      if (installAdapter) {
        installAdapterIfMissing(adapter, rule);
      }
    }
    simpleNameToRules = simpleNameToRulesBuilder.build();
    qualifiedNameToRule = qualifiedNameToRuleBuilder.build();
    nameToRule = ImmutableBiMap.copyOf(names);
    uniqueNameToRule = uniqueNameToRuleBuilder.build();
    antlrNameToRule = antlrNameToRuleBuilder.build();
    this.allRules = ImmutableList.copyOf(allRules);
  }
Пример #11
0
 public CharSequence toStringLiteral(final AbstractElement it) {
   CharSequence _switchResult = null;
   boolean _matched = false;
   if (!_matched) {
     if (it instanceof RuleCall) {
       AbstractRule _rule = ((RuleCall) it).getRule();
       boolean _notEquals = (!Objects.equal(_rule, null));
       if (_notEquals) {
         _matched = true;
         StringConcatenation _builder = new StringConcatenation();
         _builder.append("\"");
         AbstractRule _rule_1 = ((RuleCall) it).getRule();
         String _name = _rule_1.getName();
         _builder.append(_name, "");
         _builder.append("\"");
         _switchResult = _builder;
       }
     }
   }
   if (!_matched) {
     if (it instanceof Keyword) {
       _matched = true;
       StringConcatenation _builder = new StringConcatenation();
       _builder.append("\"");
       String _value = ((Keyword) it).getValue();
       String _stringInAntlrAction = AntlrGrammarGenUtil.toStringInAntlrAction(_value);
       _builder.append(_stringInAntlrAction, "");
       _builder.append("\"");
       _switchResult = _builder;
     }
   }
   if (!_matched) {
     _switchResult = "null";
   }
   return _switchResult;
 }
Пример #12
0
 public String getQualifiedName(AbstractRule rule) {
   return GrammarUtil.getGrammar(rule).getName() + "." + rule.getName();
 }
Пример #13
0
 protected String toString(AbstractRule rule) {
   return rule == null ? "null" : rule.getName();
 }