public final AntlrPilarParser.extDeclaration_return extDeclaration()
      throws RecognitionException {
    AntlrPilarParser.extDeclaration_return retval = new AntlrPilarParser.extDeclaration_return();
    retval.start = input.LT(1);
    int extDeclaration_StartIndex = input.index();
    Object root_0 = null;

    Token t = null;
    Token ID152 = null;
    Token char_literal154 = null;
    Token char_literal156 = null;
    AntlrPilarParser.typeVarTuple_return typeVarTuple151 = null;

    AntlrPilarParser.annotationList_return annotationList153 = null;

    AntlrPilarParser.extElement_return extElement155 = null;

    Object t_tree = null;
    Object ID152_tree = null;
    Object char_literal154_tree = null;
    Object char_literal156_tree = null;
    RewriteRuleTokenStream stream_188 = new RewriteRuleTokenStream(adaptor,
        "token 188");
    RewriteRuleTokenStream stream_ID = new RewriteRuleTokenStream(adaptor,
        "token ID");
    RewriteRuleTokenStream stream_178 = new RewriteRuleTokenStream(adaptor,
        "token 178");
    RewriteRuleTokenStream stream_177 = new RewriteRuleTokenStream(adaptor,
        "token 177");
    RewriteRuleSubtreeStream stream_annotationList = new RewriteRuleSubtreeStream(
        adaptor, "rule annotationList");
    RewriteRuleSubtreeStream stream_extElement = new RewriteRuleSubtreeStream(
        adaptor, "rule extElement");
    RewriteRuleSubtreeStream stream_typeVarTuple = new RewriteRuleSubtreeStream(
        adaptor, "rule typeVarTuple");
    try {
      if (state.backtracking > 0 && alreadyParsedRule(input, 43)) {
        return retval;
      }
      // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:378:2: (t= 'extension' ( typeVarTuple )? ID annotationList '{' ( extElement )+ '}' -> ^( EXTENSION[$t] ^( OPTION ( typeVarTuple )? ) ID annotationList ^( LIST ( extElement )+ ) ) )
      // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:378:4: t= 'extension' ( typeVarTuple )? ID annotationList '{' ( extElement )+ '}'
      {
        t = (Token) match(input, 188, FOLLOW_188_in_extDeclaration3154);
        if (state.failed) return retval;
        if (state.backtracking == 0) stream_188.add(t);

        // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:378:18: ( typeVarTuple )?
        int alt42 = 2;
        int LA42_0 = input.LA(1);

        if ((LA42_0 == 167)) {
          alt42 = 1;
        }
        switch (alt42) {
          case 1:
          // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:0:0: typeVarTuple
          {
            pushFollow(FOLLOW_typeVarTuple_in_extDeclaration3156);
            typeVarTuple151 = typeVarTuple();

            state._fsp--;
            if (state.failed) return retval;
            if (state.backtracking == 0)
              stream_typeVarTuple.add(typeVarTuple151.getTree());

          }
            break;

        }

        ID152 = (Token) match(input, ID, FOLLOW_ID_in_extDeclaration3162);
        if (state.failed) return retval;
        if (state.backtracking == 0) stream_ID.add(ID152);

        pushFollow(FOLLOW_annotationList_in_extDeclaration3164);
        annotationList153 = annotationList();

        state._fsp--;
        if (state.failed) return retval;
        if (state.backtracking == 0)
          stream_annotationList.add(annotationList153.getTree());
        char_literal154 = (Token) match(
            input,
            177,
            FOLLOW_177_in_extDeclaration3169);
        if (state.failed) return retval;
        if (state.backtracking == 0) stream_177.add(char_literal154);

        // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:380:8: ( extElement )+
        int cnt43 = 0;
        loop43: do {
          int alt43 = 2;
          int LA43_0 = input.LA(1);

          if (((LA43_0 >= 189 && LA43_0 <= 192))) {
            alt43 = 1;
          }

          switch (alt43) {
            case 1:
            // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:0:0: extElement
            {
              pushFollow(FOLLOW_extElement_in_extDeclaration3171);
              extElement155 = extElement();

              state._fsp--;
              if (state.failed) return retval;
              if (state.backtracking == 0)
                stream_extElement.add(extElement155.getTree());

            }
              break;

            default:
              if (cnt43 >= 1) break loop43;
              if (state.backtracking > 0) {
                state.failed = true;
                return retval;
              }
              EarlyExitException eee = new EarlyExitException(43, input);
              throw eee;
          }
          cnt43++;
        } while (true);

        char_literal156 = (Token) match(
            input,
            178,
            FOLLOW_178_in_extDeclaration3174);
        if (state.failed) return retval;
        if (state.backtracking == 0) stream_178.add(char_literal156);

        // AST REWRITE
        // elements: ID, annotationList, typeVarTuple, extElement
        // token labels: 
        // rule labels: retval
        // token list labels: 
        // rule list labels: 
        // wildcard labels: 
        if (state.backtracking == 0) {
          retval.tree = root_0;
          RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(
              adaptor, "rule retval", retval != null ? retval.tree : null);

          root_0 = (Object) adaptor.nil();
          // 380:41: -> ^( EXTENSION[$t] ^( OPTION ( typeVarTuple )? ) ID annotationList ^( LIST ( extElement )+ ) )
          {
            // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:380:44: ^( EXTENSION[$t] ^( OPTION ( typeVarTuple )? ) ID annotationList ^( LIST ( extElement )+ ) )
            {
              Object root_1 = (Object) adaptor.nil();
              root_1 = (Object) adaptor.becomeRoot(
                  (Object) adaptor.create(EXTENSION, t),
                  root_1);

              // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:380:60: ^( OPTION ( typeVarTuple )? )
              {
                Object root_2 = (Object) adaptor.nil();
                root_2 = (Object) adaptor.becomeRoot(
                    (Object) adaptor.create(OPTION, "OPTION"),
                    root_2);

                // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:380:69: ( typeVarTuple )?
                if (stream_typeVarTuple.hasNext()) {
                  adaptor.addChild(root_2, stream_typeVarTuple.nextTree());

                }
                stream_typeVarTuple.reset();

                adaptor.addChild(root_1, root_2);
              }
              adaptor.addChild(root_1, stream_ID.nextNode());
              adaptor.addChild(root_1, stream_annotationList.nextTree());
              // /Users/robby/Repositories/sireum-parser/sireum-parser/src/main/java/org/sireum/pilar/parser/AntlrPilar.g:380:102: ^( LIST ( extElement )+ )
              {
                Object root_2 = (Object) adaptor.nil();
                root_2 = (Object) adaptor.becomeRoot(
                    (Object) adaptor.create(LIST, "LIST"),
                    root_2);

                if (!(stream_extElement.hasNext())) {
                  throw new RewriteEarlyExitException();
                }
                while (stream_extElement.hasNext()) {
                  adaptor.addChild(root_2, stream_extElement.nextTree());

                }
                stream_extElement.reset();

                adaptor.addChild(root_1, root_2);
              }

              adaptor.addChild(root_0, root_1);
            }

          }

          retval.tree = root_0;
        }
      }

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

      if (state.backtracking == 0) {

        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 {
      if (state.backtracking > 0) {
        memoize(input, 43, extDeclaration_StartIndex);
      }
    }
    return retval;
  }