Add label $name | EXP; fix break

This is to fix the problem where `break` is dynamic, not lexical.

With this it should be possible to do this sort of thing:

    label $break | inputs | if ... then $break|error else . end

This is a backwards-incompatible change for master, but the previous
`break` hadn't shipped yet.

Still needed:

 - testing
This commit is contained in:
Nicolas Williams committed 2014-12-30 11:42:45 -06:00
1 parent cbfc0d6130
commit 7dc34b92af
11 files changed
+225 -33

No files matched your search

+22 -2
View File
@@ -247,15 +247,35 @@ null
1
[1,2,4,8,16,32,64]
[while(.<100; .*2|if . > 10 then break else . end)]
[label | while(.<100; .*2|if . > 10 then break else . end)]
1
[1,2,4,8]
[(label $here | .[] | if .>1 then break $here else . end), "hi!"]
[0,1,2]
[0,1,"hi!"]
[(label $here | .[] | if .>1 then break $here else . end), "hi!"]
[0,2,1]
[0,"hi!"]
(label | (label | 2 | break2)), 1
null
1
%%FAIL
break
jq: error: break used outside labeled control structure
%%FAIL
. as $foo | break $foo
jq: error: *label-foo/0 is not defined
[.[]|[.,1]|until(.[0] < 1; [.[0] - 1, .[1] * .[0]])|.[1]]
[1,2,3,4,5]
[1,2,6,24,120]
[foreach .[] as $item ([3, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1])]
[label | foreach .[] as $item ([3, null]; if .[0] < 1 then break else [.[0] -1, $item] end; .[1])]
[11,22,33,44,55,66,77,88,99]
[11,22,33]