All of lore.kernel.org
 help / color / mirror / Atom feed
* [nft PATCH] parser_bison: Fix for bison < 3.6
@ 2026-06-10 11:57 Phil Sutter
  2026-06-10 15:16 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Sutter @ 2026-06-10 11:57 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, Jan Kończak

Support for 'custom' parse.error value was added in bison-3.6. Fall back
to previous value for earlier versions.

This is harder to get right than it seems: On one hand, preprocessor
macros can't be used in parser_bison.y's declaration section and
automake forbids conditional changes to AM_YFLAGS on the other.

Suggested-by: Jan Kończak <jan.konczak@cs.put.poznan.pl>
Fixes: 67b822f2b2624 ("parser_bison: on syntax errors, output expected tokens")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 Makefile.am        |  6 ++++++
 configure.ac       | 12 ++++++++++++
 src/parser_bison.y |  4 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index fa71e06eefee5..ddf145a87c810 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -164,6 +164,12 @@ AM_CFLAGS = \
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
+if BISON_CUSTOM_ERROR
+YACC += -D parse.error=custom -D parse.lac=full
+AM_CFLAGS += -DBISON_CUSTOM_ERROR
+else
+YACC += -D parse.error=verbose
+endif
 
 if BUILD_PROFILING
 AM_CFLAGS += --coverage
diff --git a/configure.ac b/configure.ac
index 0d3ee2ac89f69..b6cad3117a51b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,18 @@ then
         exit 1
 fi
 
+AC_ARG_ENABLE([extended_parser_errors],
+	      AS_HELP_STRING([--disable-extended-parser-errors],
+			     [Disable use of parse.error=custom and LAC in Bison]),
+	      [], [
+			enable_extended_parser_errors=no
+			AC_SUBST([BISON], [$ac_cv_prog_YACC])
+			AX_PROG_BISON_VERSION([3.6],
+					      [enable_extended_parser_errors=yes])
+	      ])
+AM_CONDITIONAL([BISON_CUSTOM_ERROR],
+	       [test "x$enable_extended_parser_errors" != xno])
+
 AM_PROG_AR
 LT_INIT([disable-static])
 AC_EXEEXT
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 5a334bf0c4997..fc95597d898c0 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -221,8 +221,6 @@ int nft_lex(void *, void *, void *);
 %parse-param		{ void *scanner }
 %parse-param		{ struct parser_state *state }
 %lex-param		{ scanner }
-%define parse.error custom
-%define parse.lac full
 %locations
 
 %initial-action {
@@ -6537,6 +6535,7 @@ exthdr_key		:	HBH	close_scope_hbh	{ $$ = IPPROTO_HOPOPTS; }
 
 %%
 
+#ifdef BISON_CUSTOM_ERROR
 static int
 yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
                       void *scanner, struct parser_state *state)
@@ -6592,3 +6591,4 @@ yyreport_syntax_error(const yypcontext_t *yyctx, struct nft_ctx *nft,
 	free(msg);
 	return 0;
 }
+#endif /* BISON_CUSTOM_ERROR */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-10 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10 11:57 [nft PATCH] parser_bison: Fix for bison < 3.6 Phil Sutter
2026-06-10 15:16 ` Pablo Neira Ayuso
2026-06-10 21:26   ` Phil Sutter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.