Example #1
0
  // $ANTLR start "literal"
  // /home/jon/flume/src/antlr/FlumeShell.g:93:1: literal : ( DQuoteLiteral -> ^( DQUOTE
  // DQuoteLiteral ) | SQuoteLiteral -> ^( SQUOTE SQuoteLiteral ) | Argument -> ^( STRING Argument )
  // );
  public final FlumeShellParser.literal_return literal() throws RecognitionException {
    FlumeShellParser.literal_return retval = new FlumeShellParser.literal_return();
    retval.start = input.LT(1);

    Object root_0 = null;

    Token DQuoteLiteral8 = null;
    Token SQuoteLiteral9 = null;
    Token Argument10 = null;

    Object DQuoteLiteral8_tree = null;
    Object SQuoteLiteral9_tree = null;
    Object Argument10_tree = null;
    RewriteRuleTokenStream stream_Argument = new RewriteRuleTokenStream(adaptor, "token Argument");
    RewriteRuleTokenStream stream_DQuoteLiteral =
        new RewriteRuleTokenStream(adaptor, "token DQuoteLiteral");
    RewriteRuleTokenStream stream_SQuoteLiteral =
        new RewriteRuleTokenStream(adaptor, "token SQuoteLiteral");

    try {
      // /home/jon/flume/src/antlr/FlumeShell.g:94:5: ( DQuoteLiteral -> ^( DQUOTE DQuoteLiteral ) |
      // SQuoteLiteral -> ^( SQUOTE SQuoteLiteral ) | Argument -> ^( STRING Argument ) )
      int alt3 = 3;
      switch (input.LA(1)) {
        case DQuoteLiteral:
          {
            alt3 = 1;
          }
          break;
        case SQuoteLiteral:
          {
            alt3 = 2;
          }
          break;
        case Argument:
          {
            alt3 = 3;
          }
          break;
        default:
          NoViableAltException nvae = new NoViableAltException("", 3, 0, input);

          throw nvae;
      }

      switch (alt3) {
        case 1:
          // /home/jon/flume/src/antlr/FlumeShell.g:94:9: DQuoteLiteral
          {
            DQuoteLiteral8 =
                (Token) match(input, DQuoteLiteral, FOLLOW_DQuoteLiteral_in_literal150);
            stream_DQuoteLiteral.add(DQuoteLiteral8);

            // AST REWRITE
            // elements: DQuoteLiteral
            // token labels:
            // rule labels: retval
            // token list labels:
            // rule list labels:
            // wildcard labels:
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval =
                new RewriteRuleSubtreeStream(
                    adaptor, "rule retval", retval != null ? retval.tree : null);

            root_0 = (Object) adaptor.nil();
            // 94:23: -> ^( DQUOTE DQuoteLiteral )
            {
              // /home/jon/flume/src/antlr/FlumeShell.g:94:26: ^( DQUOTE DQuoteLiteral )
              {
                Object root_1 = (Object) adaptor.nil();
                root_1 =
                    (Object) adaptor.becomeRoot((Object) adaptor.create(DQUOTE, "DQUOTE"), root_1);

                adaptor.addChild(root_1, stream_DQuoteLiteral.nextNode());

                adaptor.addChild(root_0, root_1);
              }
            }

            retval.tree = root_0;
          }
          break;
        case 2:
          // /home/jon/flume/src/antlr/FlumeShell.g:95:9: SQuoteLiteral
          {
            SQuoteLiteral9 =
                (Token) match(input, SQuoteLiteral, FOLLOW_SQuoteLiteral_in_literal170);
            stream_SQuoteLiteral.add(SQuoteLiteral9);

            // AST REWRITE
            // elements: SQuoteLiteral
            // token labels:
            // rule labels: retval
            // token list labels:
            // rule list labels:
            // wildcard labels:
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval =
                new RewriteRuleSubtreeStream(
                    adaptor, "rule retval", retval != null ? retval.tree : null);

            root_0 = (Object) adaptor.nil();
            // 95:23: -> ^( SQUOTE SQuoteLiteral )
            {
              // /home/jon/flume/src/antlr/FlumeShell.g:95:26: ^( SQUOTE SQuoteLiteral )
              {
                Object root_1 = (Object) adaptor.nil();
                root_1 =
                    (Object) adaptor.becomeRoot((Object) adaptor.create(SQUOTE, "SQUOTE"), root_1);

                adaptor.addChild(root_1, stream_SQuoteLiteral.nextNode());

                adaptor.addChild(root_0, root_1);
              }
            }

            retval.tree = root_0;
          }
          break;
        case 3:
          // /home/jon/flume/src/antlr/FlumeShell.g:96:9: Argument
          {
            Argument10 = (Token) match(input, Argument, FOLLOW_Argument_in_literal188);
            stream_Argument.add(Argument10);

            // AST REWRITE
            // elements: Argument
            // token labels:
            // rule labels: retval
            // token list labels:
            // rule list labels:
            // wildcard labels:
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval =
                new RewriteRuleSubtreeStream(
                    adaptor, "rule retval", retval != null ? retval.tree : null);

            root_0 = (Object) adaptor.nil();
            // 96:21: -> ^( STRING Argument )
            {
              // /home/jon/flume/src/antlr/FlumeShell.g:96:24: ^( STRING Argument )
              {
                Object root_1 = (Object) adaptor.nil();
                root_1 =
                    (Object) adaptor.becomeRoot((Object) adaptor.create(STRING, "STRING"), root_1);

                adaptor.addChild(root_1, stream_Argument.nextNode());

                adaptor.addChild(root_0, root_1);
              }
            }

            retval.tree = root_0;
          }
          break;
      }
      retval.stop = input.LT(-1);

      retval.tree = (Object) adaptor.rulePostProcessing(root_0);
      adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
      retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);

    } finally {
    }
    return retval;
  }
Example #2
0
  // $ANTLR start "command"
  // /home/jon/flume/src/antlr/FlumeShell.g:90:1: command : ( literal )+ -> ^( CMD ( literal )+ ) ;
  public final FlumeShellParser.command_return command() throws RecognitionException {
    FlumeShellParser.command_return retval = new FlumeShellParser.command_return();
    retval.start = input.LT(1);

    Object root_0 = null;

    FlumeShellParser.literal_return literal7 = null;

    RewriteRuleSubtreeStream stream_literal = new RewriteRuleSubtreeStream(adaptor, "rule literal");
    try {
      // /home/jon/flume/src/antlr/FlumeShell.g:90:9: ( ( literal )+ -> ^( CMD ( literal )+ ) )
      // /home/jon/flume/src/antlr/FlumeShell.g:90:11: ( literal )+
      {
        // /home/jon/flume/src/antlr/FlumeShell.g:90:11: ( literal )+
        int cnt2 = 0;
        loop2:
        do {
          int alt2 = 2;
          int LA2_0 = input.LA(1);

          if (((LA2_0 >= DQuoteLiteral && LA2_0 <= Argument))) {
            alt2 = 1;
          }

          switch (alt2) {
            case 1:
              // /home/jon/flume/src/antlr/FlumeShell.g:90:11: literal
              {
                pushFollow(FOLLOW_literal_in_command122);
                literal7 = literal();

                state._fsp--;

                stream_literal.add(literal7.getTree());
              }
              break;

            default:
              if (cnt2 >= 1) break loop2;
              EarlyExitException eee = new EarlyExitException(2, input);
              throw eee;
          }
          cnt2++;
        } while (true);

        // AST REWRITE
        // elements: literal
        // token labels:
        // rule labels: retval
        // token list labels:
        // rule list labels:
        // wildcard labels:
        retval.tree = root_0;
        RewriteRuleSubtreeStream stream_retval =
            new RewriteRuleSubtreeStream(
                adaptor, "rule retval", retval != null ? retval.tree : null);

        root_0 = (Object) adaptor.nil();
        // 90:20: -> ^( CMD ( literal )+ )
        {
          // /home/jon/flume/src/antlr/FlumeShell.g:90:23: ^( CMD ( literal )+ )
          {
            Object root_1 = (Object) adaptor.nil();
            root_1 = (Object) adaptor.becomeRoot((Object) adaptor.create(CMD, "CMD"), root_1);

            if (!(stream_literal.hasNext())) {
              throw new RewriteEarlyExitException();
            }
            while (stream_literal.hasNext()) {
              adaptor.addChild(root_1, stream_literal.nextTree());
            }
            stream_literal.reset();

            adaptor.addChild(root_0, root_1);
          }
        }

        retval.tree = root_0;
      }

      retval.stop = input.LT(-1);

      retval.tree = (Object) adaptor.rulePostProcessing(root_0);
      adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
      retval.tree = (Object) adaptor.errorNode(input, retval.start, input.LT(-1), re);

    } finally {
    }
    return retval;
  }