diff options
author | Patrick McHardy <kaber@trash.net> | 2014-02-04 08:09:27 +0000 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2014-02-04 08:12:01 +0000 |
commit | f3129a3cc4800321ed2157eb400da8b43398606e (patch) | |
tree | 9eb9a47256de3a19f1571abc80854556fcdf7acd /src | |
parent | f164cb18c0a94701a641bce4f141d51990b8eef1 (diff) |
parser: recover from errors in any block
Move error recovery to the common_block definition to handle errors
in any block. Queue those errors and abort parsing once a threshold
is reached.
With this in place, we can continue parsing when errors occur and
show all of them to the user at once.
tests/error.1:3:8-8: Error: syntax error, unexpected '{', expecting string
filter {
^
tests/error.1:4:13-13: Error: syntax error, unexpected newline
filter input
^
tests/error.1:5:17-17: Error: syntax error, unexpected newline
filter input tcp
^
tests/error.1:6:23-23: Error: syntax error, unexpected newline
filter input tcp dport
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/parser.y | 7 |
2 files changed, 8 insertions, 2 deletions
@@ -26,6 +26,7 @@ #include <erec.h> #include <mnl.h> +unsigned int max_errors = 10; unsigned int numeric_output; unsigned int handle_output; #ifdef DEBUG @@ -219,7 +220,7 @@ int nft_run(void *scanner, struct parser_state *state, struct list_head *msgs) int ret = 0; ret = nft_parse(scanner, state); - if (ret != 0) + if (ret != 0 || state->nerrs > 0) return -1; memset(&ctx, 0, sizeof(ctx)); diff --git a/src/parser.y b/src/parser.y index fa33b570..0dad036c 100644 --- a/src/parser.y +++ b/src/parser.y @@ -518,6 +518,12 @@ common_block : INCLUDE QUOTED_STRING stmt_seperator symbol_bind(current_scope(state), $2, $4); xfree($2); } + | error stmt_seperator + { + if (++state->nerrs == max_errors) + YYABORT; + yyerrok; + } ; line : common_block { $$ = NULL; } @@ -542,7 +548,6 @@ line : common_block { $$ = NULL; } YYACCEPT; } - | base_cmd error { $$ = $1; } ; base_cmd : /* empty */ add_cmd { $$ = $1; } |