Convert bison.sh to posix shell (#1369)

* Convert bison.sh to posix shell

* Refactor bison.sh to be more like CMakeLists.txt

No current warnings with shellcheck.net.
This commit is contained in:
orbea
2024-03-21 13:06:36 -07:00
committed by GitHub
parent 0300971a17
commit 0f772932a5
2 changed files with 25 additions and 20 deletions

View File

@@ -9,7 +9,7 @@ set(common_src
) )
find_package(BISON 3.0.0 REQUIRED) find_package(BISON 3.0.0 REQUIRED)
set(BISON_FLAGS "-Wall") set(BISON_FLAGS "-Wall -Dparse.lac=full -Dlr.type=ielr")
# Set some optimization flags on versions that support them # Set some optimization flags on versions that support them
if(BISON_VERSION VERSION_GREATER_EQUAL "3.5") if(BISON_VERSION VERSION_GREATER_EQUAL "3.5")
set(BISON_FLAGS "${BISON_FLAGS} -Dapi.token.raw=true") set(BISON_FLAGS "${BISON_FLAGS} -Dapi.token.raw=true")
@@ -19,8 +19,6 @@ if(BISON_VERSION VERSION_GREATER_EQUAL "3.6")
else() else()
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.error=verbose") set(BISON_FLAGS "${BISON_FLAGS} -Dparse.error=verbose")
endif() endif()
set(BISON_FLAGS "${BISON_FLAGS} -Dparse.lac=full")
set(BISON_FLAGS "${BISON_FLAGS} -Dlr.type=ielr")
BISON_TARGET(ASM_PARSER "asm/parser.y" BISON_TARGET(ASM_PARSER "asm/parser.y"
"${PROJECT_SOURCE_DIR}/src/asm/parser.cpp" "${PROJECT_SOURCE_DIR}/src/asm/parser.cpp"

View File

@@ -1,23 +1,30 @@
#!/usr/bin/env bash #!/bin/sh
set -e set -eu
BISONFLAGS=-Wall OUTPUT_CPP="${1:?}"
INPUT_Y="${2:?}"
readonly BISON_MAJOR=$(bison -V | sed -E 's/^.+ ([0-9]+)\..*$/\1/g;q') BISON_MAJOR=$(bison -V | sed -E 's/^.+ ([0-9]+)\..*$/\1/g;q')
readonly BISON_MINOR=$(bison -V | sed -E 's/^.+ [0-9]+\.([0-9]+)\..*$/\1/g;q') BISON_MINOR=$(bison -V | sed -E 's/^.+ [0-9]+\.([0-9]+)\..*$/\1/g;q')
add_flag () { if [ "$BISON_MAJOR" -lt 3 ]; then
if [[ "$BISON_MAJOR" -eq "$1" && "$BISON_MINOR" -ge "$2" ]]; then echo "Bison $BISON_MAJOR.$BISON_MINOR is not supported" 1>&2
BISONFLAGS="$BISONFLAGS -D$3" exit 1
fi fi
}
add_flag 3 0 parse.error=verbose BISON_FLAGS="-Wall -Dparse.lac=full -Dlr.type=ielr"
add_flag 3 0 parse.lac=full
add_flag 3 0 lr.type=ielr
add_flag 3 5 api.token.raw=true
add_flag 3 6 parse.error=detailed
echo "BISONFLAGS=$BISONFLAGS" # Set some optimization flags on versions that support them
if [ "$BISON_MAJOR" -eq 4 ] || [ "$BISON_MAJOR" -eq 3 ] && [ "$BISON_MINOR" -ge 5 ]; then
BISON_FLAGS="$BISON_FLAGS -Dapi.token.raw=true"
fi
if [ "$BISON_MAJOR" -eq 4 ] || [ "$BISON_MAJOR" -eq 3 ] && [ "$BISON_MINOR" -ge 6 ]; then
BISON_FLAGS="$BISON_FLAGS -Dparse.error=detailed"
else
BISON_FLAGS="$BISON_FLAGS -Dparse.error=verbose"
fi
exec bison $BISONFLAGS -d -o "$1" "$2" # Replace the arguments to this script ($@) with the ones in $BISON_FLAGS
eval "set -- $BISON_FLAGS"
exec bison "$@" -d -o "$OUTPUT_CPP" "$INPUT_Y"