Skip to content

Commit 536e7b0

Browse files
committed
cfg syntax: Enhance the 'return' statement
The opensips.cfg now additionally allows syntax such as: * return 1; * return +2; * return -3; * return $var(foo);
1 parent 72fba84 commit 536e7b0

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

cfg.y

+23-30
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,14 @@ extern int cfg_parse_only_routes;
517517
%type <strval> folded_string
518518
%type <multistr> multi_string
519519

520-
/* all shift/reduce conflicts are currently disambiguated */
521-
%expect 0
520+
/*
521+
* known shift/reduce conflicts (the default action, shift, is correct):
522+
* - RETURN PLUS NUMBER
523+
* - RETURN MINUS NUMBER
524+
* (reason: MINUS has left associativity, but for both "return -1;" and
525+
* "return;" to work, it would need right assoc; same idea for PLUS)
526+
*/
527+
%expect 2
522528

523529

524530
%%
@@ -2130,34 +2136,21 @@ async_func: ID LPAREN RPAREN {
21302136
cmd: ASSERT LPAREN exp COMMA STRING RPAREN {
21312137
mk_action2( $$, ASSERT_T, EXPR_ST, STRING_ST, $3, $5);
21322138
}
2133-
| DROP LPAREN RPAREN {mk_action2( $$, DROP_T,0, 0, 0, 0); }
2134-
| DROP {mk_action2( $$, DROP_T,0, 0, 0, 0); }
2135-
| EXIT LPAREN RPAREN {mk_action2( $$, EXIT_T,0, 0, 0, 0); }
2136-
| EXIT {mk_action2( $$, EXIT_T,0, 0, 0, 0); }
2137-
| RETURN LPAREN snumber RPAREN {mk_action2( $$, RETURN_T,
2138-
NUMBER_ST,
2139-
0,
2140-
(void*)$3,
2141-
0);
2142-
}
2143-
| RETURN LPAREN script_var RPAREN {mk_action2( $$, RETURN_T,
2144-
SCRIPTVAR_ST,
2145-
0,
2146-
(void*)$3,
2147-
0);
2148-
}
2149-
| RETURN LPAREN RPAREN {mk_action2( $$, RETURN_T,
2150-
NUMBER_ST,
2151-
0,
2152-
(void*)1,
2153-
0);
2154-
}
2155-
| RETURN {mk_action2( $$, RETURN_T,
2156-
NUMBER_ST,
2157-
0,
2158-
(void*)1,
2159-
0);
2160-
}
2139+
| DROP {mk_action0( $$, DROP_T); }
2140+
| DROP LPAREN RPAREN {mk_action0( $$, DROP_T); }
2141+
| EXIT {mk_action0( $$, EXIT_T); }
2142+
| EXIT LPAREN RPAREN {mk_action0( $$, EXIT_T); }
2143+
| RETURN script_var
2144+
{mk_action1( $$, RETURN_T, SCRIPTVAR_ST, (void*)$2); }
2145+
| RETURN LPAREN script_var RPAREN
2146+
{mk_action1( $$, RETURN_T, SCRIPTVAR_ST, (void*)$3); }
2147+
| RETURN snumber
2148+
{mk_action1( $$, RETURN_T, NUMBER_ST, (void*)$2); }
2149+
| RETURN LPAREN snumber RPAREN
2150+
{mk_action1( $$, RETURN_T, NUMBER_ST, (void*)$3); }
2151+
| RETURN LPAREN RPAREN
2152+
{mk_action1( $$, RETURN_T, NUMBER_ST, (void*)1); }
2153+
| RETURN {mk_action1( $$, RETURN_T, NUMBER_ST, (void*)1); }
21612154
| LOG_TOK LPAREN STRING RPAREN {mk_action2( $$, LOG_T, NUMBER_ST,
21622155
STRING_ST,(void*)4,$3);
21632156
}

0 commit comments

Comments
 (0)