Jan Kończak 67b822f2b2 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>
2026-01-20 20:01:30 +01:00
2025-12-06 23:23:15 +01:00
2026-01-20 16:03:12 +01:00
2026-01-20 16:03:12 +01:00
2009-03-18 04:55:00 +01:00
2018-03-21 14:23:51 +01:00
2025-12-03 23:13:08 +01:00
Description
No description provided
7.3 MiB
Languages
C 61.3%
Shell 21.7%
Yacc 6%
Raku 3.5%
Python 2.9%
Other 4.6%