Browse code

core script parser: allow expressions in return/drop

Changed drop and return to allow expressions.
E.g.: return $foo+2

Andrei Pelinescu-Onciul authored on 14/05/2009 19:36:59
Showing 1 changed files
... ...
@@ -529,7 +529,7 @@ static int case_check_default(struct case_stms* stms);
529 529
 %type <intval> intno eint_op eint_op_onsend
530 530
 %type <intval> eip_op eip_op_onsend
531 531
 %type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
532
-%type <action> switch_cmd while_cmd
532
+%type <action> switch_cmd while_cmd ret_cmd
533 533
 %type <case_stms> single_case case_stms
534 534
 %type <ipaddr> ipv4 ipv6 ipv6addr ip
535 535
 %type <ipnet> ipnet
... ...
@@ -1862,6 +1862,7 @@ action:
1862 1862
 	| if_cmd {$$=$1;}
1863 1863
 	| switch_cmd {$$=$1;}
1864 1864
 	| while_cmd { $$=$1; }
1865
+	| ret_cmd SEMICOLON { $$=$1; }
1865 1866
 	| assign_action SEMICOLON {$$=$1;}
1866 1867
 	| SEMICOLON /* null action */ {$$=0;}
1867 1868
 	| fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
... ...
@@ -2562,15 +2563,6 @@ cmd:
2562 2563
 	| SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2563 2564
 	| SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2564 2565
 	| SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
2565
-	| DROP LPAREN RPAREN		{$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2566
-	| DROP LPAREN NUMBER RPAREN	{$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$3, NUMBER_ST, (void*)EXIT_R_F); }
2567
-	| DROP NUMBER 			{$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)EXIT_R_F); }
2568
-	| DROP RETCODE 			{$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2569
-	| DROP				{$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); }
2570
-	| RETURN			{$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST, (void*)RETURN_R_F); }
2571
-	| RETURN NUMBER			{$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST, (void*)RETURN_R_F);}
2572
-	| RETURN RETCODE		{$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST, (void*)RETURN_R_F);}
2573
-	| BREAK				{$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F); }
2574 2566
 	| LOG_TOK LPAREN STRING RPAREN	{$$=mk_action(LOG_T, 2, NUMBER_ST,
2575 2567
 										(void*)(L_DBG+1), STRING_ST, $3); }
2576 2568
 	| LOG_TOK LPAREN NUMBER COMMA STRING RPAREN	{$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); }
... ...
@@ -2822,6 +2814,29 @@ func_param:
2822 2814
 		}
2823 2815
 	}
2824 2816
 	;
2817
+
2818
+ret_cmd:
2819
+	DROP LPAREN RPAREN		{
2820
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); 
2821
+	}
2822
+	| DROP rval_expr	{
2823
+		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)EXIT_R_F);
2824
+	}
2825
+	| DROP				{
2826
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); 
2827
+	}
2828
+	| RETURN			{
2829
+		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
2830
+						(void*)RETURN_R_F);
2831
+	}
2832
+	| RETURN rval_expr	{
2833
+		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)RETURN_R_F);
2834
+	}
2835
+	| BREAK				{
2836
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F); 
2837
+	}
2838
+	;
2839
+
2825 2840
 %%
2826 2841
 
2827 2842
 extern int line;