Skip to content

Commit

Permalink
libpcp_web: mirror libpcp bison handling for query_parser.y (MacOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
natoscott committed Oct 10, 2023
1 parent 36eab72 commit c7aed99
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/libpcp/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jsonsl.c
sha256.h
sha256.c
getdate.h
getdate.y
getdate.tab.?
derive_parser.y
derive_parser.output
Expand Down
1 change: 1 addition & 0 deletions src/libpcp_web/src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crc16.h
siphash.c
http_parser.c
http_parser.h
query_parser.y
query_parser.tab.c
query_parser.tab.h
libpcp_web.dll
Expand Down
5 changes: 4 additions & 1 deletion src/libpcp_web/src/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ XFILES += fnmatch.c fnmatch.h
LCFLAGS += -I.
endif

LDIRT = $(XFILES) $(YFILES:%.y=%.tab.?)
LDIRT = $(XFILES) $(YFILES:%.y=%.tab.?) query_parser.y
LCFLAGS += $(C99_CFLAGS) -DJSMN_PARENT_LINKS=1 -DJSMN_STRICT=1 -DHTTP_PARSER_STRICT=0 -Ideps

ifeq "$(HAVE_LIBUV)" "true"
Expand Down Expand Up @@ -138,6 +138,9 @@ $(HIREDIS_CLUSTER_XFILES):
query_parser.tab.h query_parser.tab.c: query_parser.y query.h
$(YACC) -d -b `basename $< .y` $<

query_parser.y: query_parser.y.in fix_query_parser_y
./fix_query_parser_y

default_pcp: default

install_pcp: install
Expand Down
56 changes: 56 additions & 0 deletions src/libpcp_web/src/fix_query_parser_y
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
# Handle Bison version issues for query_parser.y
#

b_version=`bison --version | sed -n -e '/^bison/s/.*) *//p'`

if [ -z "$b_version" ]
then
echo "Arrgh ... cannot get bison version from ..."
bison --version
exit 1
fi

if [ ! -f query_parser.y.in ]
then
echo "Arrgh ... cannot find query_parser.y.in"
exit 1
fi

rm -f query_parser.y
cat <<End-of-File >query_parser.y
/*
* DO NOT EDIT THIS FILE ... CHANGES HERE WILL BE LOST
*
* This file created from query_parser.y.in (make changes there!)
* by fix_query_parser_y on ${PACKAGE_BUILD_DATE:-`date`}.
*/
End-of-File

# From the bison CHANGELOG
# 2012-10-26
# version 2.6.4
# 2012-10-25
# src/parse-gram.y (%pure-parser, %name-prefix): Replace with...
# (%define api.pure, %define api.prefix)
#
case "$b_version"
in
2.[0-5]*|2.6.[0-3])
sed -e 's/^PUT-PURE-DECL-HERE.*/%pure-parser/' <query_parser.y.in >>query_parser.y
;;
2.6.[4-9]|2.[7-9]*|3.*)
sed -e 's/^PUT-PURE-DECL-HERE.*/%define api.pure full/' <query_parser.y.in >>query_parser.y
;;
*)
rm -f query_parser.y
echo "Arrgh ... don't know what to do with bison version $b_version"
exit 1
;;
esac

chmod a-w query_parser.y

exit 0

Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ static char *n_type_c(int);
static char *l_type_str(int);
%}

/*
* seems like the %define variant is more bisonesque, while the
* %pure-parser maybe a yaccism that bison silently accepts ...
* using the %define makes "deprecated directive" warnings go
* away on some platforms - kenj Oct 2019
* old yacc declaration was
* %pure-parser
*/
%define api.pure
PUT-PURE-DECL-HERE ... see GNUmakefile and fix_query_parser_y

%parse-param { PARSER *lp }
%lex-param { PARSER *lp }
Expand Down

0 comments on commit c7aed99

Please sign in to comment.