docs: public RuleDescr query(PackageDescrBuilder pkg) throws RecognitionException {
          QueryDescrBuilder query = null;
          try {
              query = helper.start(pkg,
                      QueryDescrBuilder.class,
                      null);
  
              setAnnotationsOn(query);
  
              // 'query'
              match(input,
                      DRL6Lexer.ID,
                      DroolsSoftKeywords.QUERY,
                      null,
                      DroolsEditorType.KEYWORD);
              if (state.failed)
                  return null;
  
              if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN) ||
                      helper.validateIdentifierKey(DroolsSoftKeywords.THEN) ||
                      helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
                  failMissingTokenException();
                  return null; // in case it is backtracking
              }
  
              String name = stringId();
              if (state.backtracking == 0)
                  query.name(name);
              if (state.failed)
                  return null;
  
              if (state.backtracking == 0) {
                  helper.emit(Location.LOCATION_RULE_HEADER);
              }
  
              if (speculateParameters(true)) {
                  // parameters
                  parameters(query,
                          true);
                  if (state.failed)
                      return null;
                  if (state.backtracking == 0) {
                      helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
                  }
              } else if (speculateParameters(false)) {
                  // parameters
                  parameters(query,
                          false);
                  if (state.failed)
                      return null;
                  if (state.backtracking == 0) {
                      helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
                  }
              }
  
              if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
                  helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
              }
              if (input.LA(1) != DRL6Lexer.EOF) {
                  lhsExpression(query != null ? query.lhs() : null);
              }
  
              match(input,
                      DRL6Lexer.ID,
                      DroolsSoftKeywords.END,
                      null,
                      DroolsEditorType.KEYWORD);
              if (state.failed)
                  return null;
  
              helper.emit(Location.LOCATION_RHS);
  
          } catch (RecognitionException re) {
              reportError(re);
          } finally {
              helper.end(QueryDescrBuilder.class,
                      query);
          }
          return (query != null) ? query.getDescr() : null;
      }