code: protected ExpectState prepareClosure(int pairIndex, MatchResult result) {
          /* TODO: potentially remove this?
          {
              System.out.println( "Begin: " + result.beginOffset(0) );
              System.out.println( "Length: " + result.length() );
              System.out.println( "Current: " + input.getCurrentOffset() );
              System.out.println( "Begin: " + input.getMatchBeginOffset() );
              System.out.println( "End: " + input.getMatchEndOffset() );
              //System.out.println( "Match: " + input.match() );
              //System.out.println( "Pre: >" + input.preMatch() + "<");
              //System.out.println( "Post: " + input.postMatch() );
          }
           */
  
          // Prepare Closure environment
          ExpectState state;
          Map<String, Object> prevMap = null;
          if (g_state != null) {
              prevMap = g_state.getVars();
          }
  
          int matchedWhere = result.beginOffset(0);
          String matchedText = result.toString(); // expect_out(0,string)
  
          // Unmatched upto end of match
          // expect_out(buffer)
          char[] chBuffer = input.getBuffer();
          String copyBuffer = new String(chBuffer, 0, result.endOffset(0) );
  
          List<String> groups = new ArrayList<>();
          for (int j = 1; j <= result.groups(); j++) {
              String group = result.group(j);
              groups.add( group );
          }
          state = new ExpectState(copyBuffer.toString(), matchedWhere, matchedText, pairIndex, groups, prevMap);
  
          return state;
      }
docs: Don't use input, it's match values might have been reset in the
  loop that looks for the first possible match.
  
  @param pairIndex TODO
  @param result TODO
  @return TODO