]> git.ipfire.org Git - thirdparty/nftables.git/commit
parser_bison: on syntax errors, output expected tokens
authorJan Kończak <jan.konczak@cs.put.poznan.pl>
Thu, 4 Dec 2025 21:54:48 +0000 (22:54 +0100)
committerFlorian Westphal <fw@strlen.de>
Tue, 20 Jan 2026 19:01:30 +0000 (20:01 +0100)
commit67b822f2b2624ed018cd80e83feebe110a33266e
tree00d7ffb31c6c35c05001d4f0ef7eb3a21053f4a4
parent9d105581b5f1b14c48c96b0617a25d4b60e57ade
parser_bison: on syntax errors, output expected tokens

Now, on syntax errors, e.g., 'nft create fable filter', the user sees:
 Error: syntax error, unexpected string
 create fable filter
          ^^^^^
The patch builds an error message that lists what the parser expects
to see, in that case it would print:
 Error: syntax error, unexpected string
 expected any of: synproxy, table, chain, set, element, map,
 flowtable, ct, counter, limit, quota, secmark
 create fable filter
        ^^^^^
The obvious purpose of this is to help people who learn nft syntax.

The messages are still not as explanatory as one wishes, for it may
list parser token names such as 'string', but it's still better than
no hints at all.

Heed that the list of possible items on the parser's side is not
always consistent with expectations.

For instance, lexer/parser recognizes 'l4proto' in this command:
nft add rule ip F I meta l4proto tcp
as a generic '%token <string> STRING', while 'iifname' in
   nft add rule ip F I meta iifname eth0

is recognized as a '%token IIFNAME'

In such case the parser is only able to say that right after 'meta'
it expects 'iifname' or 'string', rather than 'iifname' and 'l4proto'.

This 'meta STRING' is a historic wart and can be resolved in
a followup patch.

[ fw@strlen.de: minor coding style changes and rewordings ]

Signed-off-by: Jan Kończak <jan.konczak@cs.put.poznan.pl>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/parser_bison.y