github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/lexbase/sql-gen.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # This is used through bazel when generating sql.go and plpgsql.go.
     4  # Look at BUILD.bazel in pkg/sql/parser or pkg/plpgsql/parser for
     5  # usage.
     6  
     7  set -euo pipefail
     8  
     9  LANG=$2
    10  SYMUNION="${LANG}"'SymUnion'
    11  GENYACC=$LANG-gen.y
    12  
    13  
    14      awk -v regex="$SYMUNION" '/func.*'"$SYMUNION"'/ {print $(NF - 1)}' $1 | \
    15          sed -e 's/[]\/$*.^|[]/\\&/g' | \
    16          sed -e "s/^/s_(type|token) <(/" | \
    17          awk '{print $0")>_\\1 <union> /* <\\2> */_"}' > types_regex.tmp
    18  
    19      sed -E -f types_regex.tmp < $1 | \
    20          if [ $LANG != plpgsql ] && [ $LANG != pgrepl ]; then \
    21              awk -f $3 | \
    22            sed -Ee 's,//.*$$,,g;s,/[*]([^*]|[*][^/])*[*]/, ,g;s/ +$$//g' > $GENYACC
    23          else
    24            sed -Ee 's,//.*$$,,g;s,/[*]([^*]|[*][^/])*[*]/, ,g;s/ +$$//g' > $GENYACC
    25          fi;
    26  
    27      rm types_regex.tmp
    28  
    29      ret=$($5 -p $LANG -o $4 $GENYACC); \
    30        if expr "$ret" : ".*conflicts" >/dev/null; then \
    31          echo "$ret"; exit 1; \
    32        fi;
    33      rm $GENYACC