summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2014-08-09 12:42:39 -0500
committerNicolas Williams <nico@cryptonector.com>2014-08-09 12:42:39 -0500
commit8cddb7c6816e237cc64e2954d0f91cb6564e63ca (patch)
tree2064d775a1ee6b52ec88f2c0032df2d19773f6b5
parent4249bbf0d549c6c2e9e1e1e93ccda7f87523cf05 (diff)
Allow any number of jq-coded function arguments
-rw-r--r--parser.y46
-rw-r--r--tests/all.test5
2 files changed, 23 insertions, 28 deletions
diff --git a/parser.y b/parser.y
index 1246483d..73fee5fa 100644
--- 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();
diff --git a/tests/all.test b/tests/all.test
index 2e14afb0..7edd14d8 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]