github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/parser/replace_help_rules.awk (about)

     1  # Grammar rules expansion - see README.md
     2  
     3  /\/\/ EXTEND WITH HELP:/ {
     4      # some_yacc_rule_name // EXTEND WITH HELP:  BLABLA
     5      # ^^^^^^^^^^^^^^^^^^^ take this
     6      prefix = substr($0, 1, index($0, "//")-1)
     7      # some_yacc_rule_name // EXTEND WITH HELP:  BLABLA
     8      #                                         ^^^^^^^^^ take this
     9      helpkey = substr($0, index($0, "HELP:")+6)
    10      rulename = prefix
    11      if (index($0, "|") > 0) {
    12          # non-terminal is prefixed by |, e.g. because
    13          # there was a non-terminal before that. Extract
    14          # only its name:
    15          #  | some_yacc_rule_name
    16          #    ^^^^^^^^^^^^^^^^^^^ take this
    17          rulename = substr(rulename, index($0, "|")+1)
    18      }
    19      printf "%s %%prec VALUES | %s HELPTOKEN %%prec UMINUS { return helpWith(sqllex, \"%s\") }\n", prefix, rulename, helpkey
    20      next
    21  }
    22  /\/\/ SHOW HELP:/ {
    23      # some_yacc_rule // SHOW HELP: BLABLA
    24      # ^^^^^^^^^^^^^^ take this
    25      prefix = substr($0, 1, index($0, "//")-1)
    26      # some_yacc_rule // SHOW HELP: BLABLA
    27      #                             ^^^^^^^^ take this
    28      helpkey = substr($0, index($0, "HELP:")+6)
    29      printf "%s { return helpWith(sqllex, \"%s\") }\n", prefix, helpkey
    30      next
    31  }
    32  { print }