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 2562
 	| SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); }
2563 2563
 	| SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2564 2564
 	| 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 2565
 	| LOG_TOK LPAREN STRING RPAREN	{$$=mk_action(LOG_T, 2, NUMBER_ST,
2575 2566
 										(void*)(L_DBG+1), STRING_ST, $3); }
2576 2567
 	| 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 2822
 		}
2823 2823
 	}
2824 2824
 	;
2825
+
2826
+ret_cmd:
2827
+	DROP LPAREN RPAREN		{
2828
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); 
2829
+	}
2830
+	| DROP rval_expr	{
2831
+		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)EXIT_R_F);
2832
+	}
2833
+	| DROP				{
2834
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F); 
2835
+	}
2836
+	| RETURN			{
2837
+		$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
2838
+						(void*)RETURN_R_F);
2839
+	}
2840
+	| RETURN rval_expr	{
2841
+		$$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)RETURN_R_F);
2842
+	}
2843
+	| BREAK				{
2844
+		$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F); 
2845
+	}
2846
+	;
2847
+
2825 2848
 %%
2826 2849
 
2827 2850
 extern int line;