From: Nicolas Williams Date: Sat, 9 Aug 2014 17:42:39 +0000 (-0500) Subject: Allow any number of jq-coded function arguments X-Git-Tag: jq-1.5rc1~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cddb7c6816e237cc64e2954d0f91cb6564e63ca;p=jq Allow any number of jq-coded function arguments --- diff --git a/parser.y b/parser.y index 1246483..73fee5f 100644 --- a/parser.y +++ b/parser.y @@ -102,7 +102,9 @@ struct lexer_param; %precedence "catch" -%type Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String Import Imports Param Params +%type Exp Term MkDict MkDictPair ExpD ElseBody QQString +%type FuncDef FuncDefs String Import Imports Param Params +%type Arg Args %{ #include "lexer.h" struct lexer_param { @@ -639,33 +641,8 @@ IDENT { $$ = gen_location(@$, locations, gen_call(jv_string_value($1), gen_noop())); jv_free($1); } | -IDENT '(' Exp ')' { - $$ = gen_call(jv_string_value($1), gen_lambda($3)); - $$ = gen_location(@1, locations, $$); - jv_free($1); -} | -IDENT '(' Exp ';' Exp ')' { - $$ = gen_call(jv_string_value($1), BLOCK(gen_lambda($3), gen_lambda($5))); - $$ = gen_location(@1, locations, $$); - jv_free($1); -} | -IDENT '(' Exp ';' Exp ';' Exp ')' { - $$ = gen_call(jv_string_value($1), BLOCK(gen_lambda($3), gen_lambda($5), gen_lambda($7))); - $$ = gen_location(@1, locations, $$); - jv_free($1); -} | -IDENT '(' Exp ';' Exp ';' Exp ';' Exp ')' { - $$ = gen_call(jv_string_value($1), BLOCK(gen_lambda($3), gen_lambda($5), gen_lambda($7), gen_lambda($9))); - $$ = gen_location(@1, locations, $$); - jv_free($1); -} | -IDENT '(' Exp ';' Exp ';' Exp ';' Exp ';' Exp ')' { - $$ = gen_call(jv_string_value($1), BLOCK(gen_lambda($3), gen_lambda($5), gen_lambda($7), gen_lambda($9), gen_lambda($11))); - $$ = gen_location(@1, locations, $$); - jv_free($1); -} | -IDENT '(' Exp ';' Exp ';' Exp ';' Exp ';' Exp ';' Exp ')' { - $$ = gen_call(jv_string_value($1), BLOCK(gen_lambda($3), gen_lambda($5), gen_lambda($7), gen_lambda($9), gen_lambda($11), gen_lambda($13))); +IDENT '(' Args ')' { + $$ = gen_call(jv_string_value($1), $3); $$ = gen_location(@1, locations, $$); jv_free($1); } | @@ -674,6 +651,19 @@ IDENT '(' Exp ';' Exp ';' Exp ';' Exp ';' Exp ';' Exp ')' { Term '[' error ']' { $$ = $1; } | '{' error '}' { $$ = gen_noop(); } +Args: +Arg { + $$ = $1; +} | +Args ';' Arg { + $$ = BLOCK($1, $3); +} + +Arg: +Exp { + $$ = gen_lambda($1); +} + MkDict: %empty { $$=gen_noop(); diff --git a/tests/all.test b/tests/all.test index 2e14afb..7edd14d 100644 --- a/tests/all.test +++ b/tests/all.test @@ -473,6 +473,11 @@ def f(a;b;c;d;e;f): [a+1,b,c,d,e,f]; f(.[0];.[1];.[0];.[0];.[0];.[0]) [1,2] [2,2,1,1,1,1] +# Many arguments +def f(a;b;c;d;e;f;g;h;i;j): [j,i,h,g,f,e,d,c,b,a]; f(.[0];.[1];.[2];.[3];.[4];.[5];.[6];.[7];.[8];.[9]) +[0,1,2,3,4,5,6,7,8,9] +[9,8,7,6,5,4,3,2,1,0] + ([1,2] + [4,5]) [1,2,3] [1,2,4,5]