From: Nicolas Williams Date: Wed, 11 Dec 2013 20:13:57 +0000 (-0600) Subject: Complete more-arity feature not complete X-Git-Tag: jq-1.4~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=474386a1d950ab8fd8e1d4fb7570e6454466a834;p=jq Complete more-arity feature not complete And test --- diff --git a/parser.y b/parser.y index 6794116..4c0b6a2 100644 --- a/parser.y +++ b/parser.y @@ -360,8 +360,67 @@ FuncDef: jv_free($2); jv_free($4); jv_free($6); -} +} | +"def" IDENT '(' IDENT ';' IDENT ';' IDENT ')' ':' Exp ';' { + $$ = gen_function(jv_string_value($2), + BLOCK(gen_param(jv_string_value($4)), + gen_param(jv_string_value($6)), + gen_param(jv_string_value($8))), + $11); + jv_free($2); + jv_free($4); + jv_free($6); + jv_free($8); +} | + +"def" IDENT '(' IDENT ';' IDENT ';' IDENT ';' IDENT ')' ':' Exp ';' { + $$ = gen_function(jv_string_value($2), + BLOCK(gen_param(jv_string_value($4)), + gen_param(jv_string_value($6)), + gen_param(jv_string_value($8)), + gen_param(jv_string_value($10))), + $13); + jv_free($2); + jv_free($4); + jv_free($6); + jv_free($8); + jv_free($10); +} | + +"def" IDENT '(' IDENT ';' IDENT ';' IDENT ';' IDENT ';' IDENT ')' ':' Exp ';' { + $$ = gen_function(jv_string_value($2), + BLOCK(gen_param(jv_string_value($4)), + gen_param(jv_string_value($6)), + gen_param(jv_string_value($8)), + gen_param(jv_string_value($10)), + gen_param(jv_string_value($12))), + $15); + jv_free($2); + jv_free($4); + jv_free($6); + jv_free($8); + jv_free($10); + jv_free($12); +} | + +"def" IDENT '(' IDENT ';' IDENT ';' IDENT ';' IDENT ';' IDENT ';' IDENT ')' ':' Exp ';' { + $$ = gen_function(jv_string_value($2), + BLOCK(gen_param(jv_string_value($4)), + gen_param(jv_string_value($6)), + gen_param(jv_string_value($8)), + gen_param(jv_string_value($10)), + gen_param(jv_string_value($12)), + gen_param(jv_string_value($14))), + $17); + jv_free($2); + jv_free($4); + jv_free($6); + jv_free($8); + jv_free($10); + jv_free($12); + jv_free($14); +} String: diff --git a/tests/all.test b/tests/all.test index 71918a6..785a0e2 100644 --- a/tests/all.test +++ b/tests/all.test @@ -352,6 +352,10 @@ def f: (1000,2000); f 1000 2000 +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] + ([1,2] + [4,5]) [1,2,3] [1,2,4,5]