summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2014-08-08 19:23:46 -0500
committerNicolas Williams <nico@cryptonector.com>2014-08-08 19:23:46 -0500
commit8706b6b16aae33aa68dc448b6f575cb657f6afb3 (patch)
tree7d588065f89d855a33a5908b838dab6856bdf31f /builtin.c
parent32c08d48f32162db1f1b6f3daaecf8f24ed85368 (diff)
Use `def f($a): ...;` syntax for builtins
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/builtin.c b/builtin.c
index 8acde3a6..ec647e82 100644
--- a/builtin.c
+++ b/builtin.c
@@ -939,9 +939,9 @@ static const char* const jq_builtins[] = {
"def from_entries: map({(.key): .value}) | add | .//={};",
"def with_entries(f): to_entries | map(f) | from_entries;",
"def reverse: [.[length - 1 - range(0;length)]];",
- "def indices(i): i as $i | if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end;",
- "def index(i): i as $i | if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end | .[0];",
- "def rindex(i): i as $i | if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end | .[-1:][0];",
+ "def indices($i): if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end;",
+ "def index($i): if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end | .[0];",
+ "def rindex($i): if type == \"array\" and ($i|type) == \"array\" then .[$i] elif type == \"array\" then .[[$i]] else .[$i] end | .[-1:][0];",
"def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
"def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);",
"def any: reduce .[] as $i (false; . or $i);",
@@ -970,10 +970,10 @@ static const char* const jq_builtins[] = {
"def values: arrays, objects, booleans, numbers, strings;",
"def scalars: select(. == null or . == true or . == false or type == \"number\" or type == \"string\");",
"def leaf_paths: paths(scalars);",
- "def join(x): x as $x | reduce .[] as $i (\"\"; . + (if . == \"\" then $i else $x + $i end));",
+ "def join($x): reduce .[] as $i (\"\"; . + (if . == \"\" then $i else $x + $i end));",
"def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
- "def flatten(x): x as $x | reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
- "def range(x): x as $x | range(0;$x);",
+ "def flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
+ "def range($x): range(0;$x);",
"def match(re; mode): _match_impl(re; mode; false)|.[];",
"def match(val): (val|type) as $vt | if $vt == \"string\" then match(val; null)"
" elif $vt == \"array\" and (val | length) > 1 then match(val[0]; val[1])"
@@ -1059,13 +1059,13 @@ static const char* const jq_builtins[] = {
" def _while: "
" if cond then ., (update | _while) else empty end; "
" try _while catch if .==\"break\" then empty else . end;",
- "def limit(n; exp): n as $n | if $n < 0 then exp else foreach exp as $item ([$n, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1]) end;",
+ "def limit($n; exp): if $n < 0 then exp else foreach exp as $item ([$n, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1]) end;",
"def first(g): foreach g as $item ([false, null]; if .[0]==true then break else [true, $item] end; .[1]);",
"def last(g): reduce g as $item (null; $item);",
- "def nth(n; g): n as $n | if $n < 0 then error(\"nth doesn't support negative indices\") else last(limit($n + 1; g)) end;",
+ "def nth($n; g): if $n < 0 then error(\"nth doesn't support negative indices\") else last(limit($n + 1; g)) end;",
"def first: .[0];",
"def last: .[-1];",
- "def nth(n): .[n];",
+ "def nth($n): .[$n];",
};
#undef LIBM_DD