netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 2/2] parser: add grammatical distinction for verdict maps
Date: Fri,  7 Mar 2014 11:12:48 +0100	[thread overview]
Message-ID: <1394187168-18977-2-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1394187168-18977-1-git-send-email-kaber@trash.net>

Currently the parser accepts verdicts in regular maps and non-verdicts
in verdict maps and we have to check matching types during evaluation.
Add grammar rules for verdict maps and seperate them from regular maps.
This has a couple of advantages:

- We recognize verdict maps completely in the parser and any attempt to
  mix verdicts and other expressions will result in a syntax error.
  So far this hasn't actually been checked.

- Using verdicts in non-verdict mappings will also result in a syntax
  error instead of a datatype mismatch.

- There's a grammatical distinction between dictionaries and verdict
  maps, which are actually statements.

This is needed as preparation for a following patch to turn verdicts
into pure statements, which in turn is needed to reinstate support for
using the queue verdict in maps, which was broken by the introduction
of the queue statement.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 src/parser.y | 52 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 13 deletions(-)

diff --git a/src/parser.y b/src/parser.y
index dd09fb4..0d97ae9 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -428,8 +428,11 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %type <expr>			map_expr
 %destructor { expr_free($$); }	map_expr
 
-%type <expr>			verdict_map_expr
-%destructor { expr_free($$); }	verdict_map_expr
+%type <expr>			verdict_map_stmt
+%destructor { expr_free($$); }	verdict_map_stmt
+
+%type <expr>			verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
+%destructor { expr_free($$); }	verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
 
 %type <expr>			set_expr set_list_expr set_list_member_expr
 %destructor { expr_free($$); }	set_expr set_list_expr set_list_member_expr
@@ -1072,12 +1075,45 @@ verdict_stmt		:	verdict_expr
 			{
 				$$ = verdict_stmt_alloc(&@$, $1);
 			}
-			|	verdict_map_expr
+			|	verdict_map_stmt
 			{
 				$$ = verdict_stmt_alloc(&@$, $1);
 			}
 			;
 
+verdict_map_stmt	:	concat_expr	VMAP	verdict_map_expr
+			{
+				$$ = map_expr_alloc(&@$, $1, $3);
+			}
+			;
+
+verdict_map_expr	:	'{'	verdict_map_list_expr	'}'
+			{
+				$2->location = @$;
+				$$ = $2;
+			}
+			;
+
+verdict_map_list_expr	:	verdict_map_list_member_expr
+			{
+				$$ = set_expr_alloc(&@$);
+				compound_expr_add($$, $1);
+			}
+			|	verdict_map_list_expr	COMMA	verdict_map_list_member_expr
+			{
+				compound_expr_add($1, $3);
+				$$ = $1;
+			}
+			|	verdict_map_list_expr	COMMA	opt_newline
+			;
+
+verdict_map_list_member_expr:	opt_newline	map_lhs_expr	COLON	verdict_expr	opt_newline
+			{
+				$$ = mapping_expr_alloc(&@$, $2, $4);
+			}
+			;
+
+
 counter_stmt		:	counter_stmt_alloc
 			|	counter_stmt_alloc	counter_args
 
@@ -1404,12 +1440,6 @@ map_expr		:	concat_expr	MAP	expr
 			}
 			;
 
-verdict_map_expr	:	concat_expr	VMAP	expr
-			{
-				$$ = map_expr_alloc(&@$, $1, $3);
-			}
-			;
-
 expr			:	concat_expr
 			|	set_expr
 			|       map_expr
@@ -1444,10 +1474,6 @@ set_list_member_expr	:	opt_newline	expr	opt_newline
 			{
 				$$ = mapping_expr_alloc(&@$, $2, $4);
 			}
-			|	opt_newline	map_lhs_expr	COLON	verdict_expr	opt_newline
-			{
-				$$ = mapping_expr_alloc(&@$, $2, $4);
-			}
 			;
 
 initializer_expr	:	expr
-- 
1.8.5.3


      reply	other threads:[~2014-03-07 10:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07 10:12 [PATCH 1/2] netlink: use set location for IO errors Patrick McHardy
2014-03-07 10:12 ` Patrick McHardy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394187168-18977-2-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).