]> granicus.if.org Git - jq/commitdiff
Allow any number of jq-coded function arguments
authorNicolas Williams <nico@cryptonector.com>
Sat, 9 Aug 2014 17:42:39 +0000 (12:42 -0500)
committerNicolas Williams <nico@cryptonector.com>
Sat, 9 Aug 2014 17:42:39 +0000 (12:42 -0500)
parser.y
tests/all.test

index 1246483dd79294fbd2112ba5db4889b30dcbb03a..73fee5fa171727f02957ad84d3a6d9a2ca16543d 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -102,7 +102,9 @@ struct lexer_param;
 %precedence "catch"
 
 
-%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String Import Imports Param Params
+%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString
+%type <blk> FuncDef FuncDefs String Import Imports Param Params
+%type <blk> 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(); 
index 2e14afb0076d72b9fd22c266df421d070c3cd4ca..7edd14d80f830990b285eadbe144d9590c6657bb 100644 (file)
@@ -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]