Shows a more informative message when user commits a syntax error:

        $ nft add rule t c handle 3 ...
        <cmdline>:1:14-19: Error: Did you mean `position'?
        add rule t c handle 3 ...
                     ^^^^^^
        $ nft delete rule t c position 3 ...
        <cmdline>:1:17-24: Error: Did you mean `handle' or insert a rule 
description?
        delete rule t c position 3 ...
                        ^^^^^^^^

Adds function 'erec_del_last' that deletes last error from the error queue.
This is needed to do not show two error messages.

Signed-off-by: Carlos Falgueras García <carlo...@riseup.net>
---
 include/erec.h     |  5 +++++
 src/parser_bison.y | 17 +++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/erec.h b/include/erec.h
index 36e0efa..95ed24a 100644
--- a/include/erec.h
+++ b/include/erec.h
@@ -58,6 +58,11 @@ static inline void erec_queue(struct error_record *erec,
        list_add_tail(&erec->list, queue);
 }
 
+static inline void erec_del_last(struct list_head *queue)
+{
+       list_del(queue->prev);
+}
+
 extern void erec_print(FILE *f, const struct error_record *erec);
 extern void erec_print_list(FILE *f, struct list_head *list);
 
diff --git a/src/parser_bison.y b/src/parser_bison.y
index beea38b..9739cb1 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1273,6 +1273,14 @@ rule_position            :       chain_spec
                                $$ = $1;
                                handle_merge(&$$, &$2);
                        }
+                       |       chain_spec HANDLE error
+                       {
+                               erec_del_last(state->msgs);
+                               erec_queue(error(&@2, "Did you mean 
`position'?"),
+                                          state->msgs);
+                               $$ = $1;
+                               YYERROR;
+                       }
                        ;
 
 ruleid_spec            :       chain_spec handle_spec
@@ -1287,6 +1295,15 @@ ruleid_spec              :       chain_spec handle_spec
                                $$ = $2;
                                handle_merge(&$$->handle, &$1);
                        }
+                       |       chain_spec POSITION error
+                       {
+                               erec_del_last(state->msgs);
+                               erec_queue(error(&@2, "Did you mean `handle' or 
insert a rule description?"),
+                                          state->msgs);
+                               $$ = rule_alloc(&@$, NULL);
+                               handle_merge(&$$->handle, &$1);
+                               YYERROR;
+                       }
                        ;
 
 comment_spec           :       COMMENT         string
-- 
2.8.3

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to