コード例 #1
0
 /**
  * Answers {@code true} if the given terminal rule is synthetic. That is, the tokens for this rule
  * will not be produced by the generated Antlr lexer but manually in a custom token source.
  */
 public boolean isSyntheticTerminalRule(final TerminalRule rule) {
   AbstractElement _alternatives = rule.getAlternatives();
   if ((_alternatives instanceof Keyword)) {
     AbstractElement _alternatives_1 = rule.getAlternatives();
     String value = ((Keyword) _alternatives_1).getValue();
     TerminalRule _originalElement = AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(rule);
     String _name = _originalElement.getName();
     String _plus = ("synthetic:" + _name);
     return Objects.equal(_plus, value);
   }
   return false;
 }
コード例 #2
0
 public LookAheadTerminal createLookAheadTerminal(Token token) {
   Grammar grammar = getGrammar();
   String tokenName = getTokenNames()[token.getType()];
   tokenName = getValueForTokenName(tokenName);
   if (tokenName.charAt(0) == '\'') {
     LookaheadKeyword result = new LookaheadKeyword();
     result.setKeyword(tokenName.substring(1, tokenName.length() - 1));
     result.setToken(token);
     return result;
   }
   LookAheadTerminalRuleCall result = new LookAheadTerminalRuleCall();
   result.setToken(token);
   String ruleName = TokenTool.getLexerRuleName(tokenName);
   if (terminalRules == null) terminalRules = GrammarUtil.allTerminalRules(grammar);
   for (TerminalRule rule : terminalRules) {
     if (rule.getName().equalsIgnoreCase(ruleName)) {
       result.setRule(rule);
       return result;
     }
   }
   throw new IllegalArgumentException("tokenType " + token.getType() + " seems to be invalid.");
 }
コード例 #3
0
 private ArrayList<AbstractRule> copyRuleStubs(
     final RuleNames names,
     final Map<RuleWithParameterValues, AbstractRule> origToCopy,
     final List<AbstractRule> rulesToCopy,
     final boolean discardTypeRef) {
   final ArrayList<AbstractRule> result = CollectionLiterals.<AbstractRule>newArrayList();
   for (final AbstractRule rule : rulesToCopy) {
     {
       String ruleName = names.getAntlrRuleName(rule);
       boolean _matched = false;
       if (rule instanceof ParserRule) {
         _matched = true;
         List<Parameter> params = ((ParserRule) rule).getParameters();
         boolean _isEmpty = params.isEmpty();
         if (_isEmpty) {
           ParserRule copy = this.<ParserRule>copy(((ParserRule) rule));
           copy.setName(ruleName);
           boolean _isFragment = ((ParserRule) rule).isFragment();
           copy.setFragment(_isFragment);
           boolean _isWildcard = ((ParserRule) rule).isWildcard();
           copy.setWildcard(_isWildcard);
           if ((!discardTypeRef)) {
             TypeRef _type = ((ParserRule) rule).getType();
             TypeRef _copyTypeRef = this.copyTypeRef(_type);
             copy.setType(_copyTypeRef);
           }
           this.attachTo(copy, rule, origToCopy);
           result.add(copy);
         } else {
           ImmutableSet<Parameter> _copyOf = ImmutableSet.<Parameter>copyOf(params);
           Set<Set<Parameter>> _powerSet = Sets.<Parameter>powerSet(_copyOf);
           final Procedure2<Set<Parameter>, Integer> _function =
               (Set<Parameter> parameterConfig, Integer i) -> {
                 RuleWithParameterValues parameterValues =
                     new RuleWithParameterValues(rule, parameterConfig);
                 ParserRule copy_1 = this.<ParserRule>copy(((ParserRule) rule));
                 String _antlrRuleName = names.getAntlrRuleName(rule, (i).intValue());
                 copy_1.setName(_antlrRuleName);
                 boolean _isFragment_1 = ((ParserRule) rule).isFragment();
                 copy_1.setFragment(_isFragment_1);
                 boolean _isWildcard_1 = ((ParserRule) rule).isWildcard();
                 copy_1.setWildcard(_isWildcard_1);
                 if ((!discardTypeRef)) {
                   TypeRef _type_1 = ((ParserRule) rule).getType();
                   TypeRef _copyTypeRef_1 = this.copyTypeRef(_type_1);
                   copy_1.setType(_copyTypeRef_1);
                 }
                 origToCopy.put(parameterValues, copy_1);
                 parameterValues.attachToEmfObject(copy_1);
                 result.add(copy_1);
               };
           IterableExtensions.<Set<Parameter>>forEach(_powerSet, _function);
         }
       }
       if (!_matched) {
         if (rule instanceof TerminalRule) {
           _matched = true;
           TerminalRule orig = ((TerminalRule) rule);
           TerminalRule copy = this.<TerminalRule>copy(orig);
           copy.setName(ruleName);
           boolean _isFragment = orig.isFragment();
           copy.setFragment(_isFragment);
           this.attachTo(copy, orig, origToCopy);
           result.add(copy);
         }
       }
       if (!_matched) {
         if (rule instanceof EnumRule) {
           _matched = true;
           EnumRule copy = this.<EnumRule>copy(((EnumRule) rule));
           copy.setName(ruleName);
           this.attachTo(copy, rule, origToCopy);
           result.add(copy);
         }
       }
     }
   }
   return result;
 }
コード例 #4
0
 protected String _ruleName(final TerminalRule it) {
   String _name = it.getName();
   String _upperCase = _name.toUpperCase();
   return ("RULE_" + _upperCase);
 }