Just in time processing on a character stream: Difference between revisions

(→‎{{header|jq}}: .out = $c)
(→‎{{header|jq}}: emit_until)
Line 681:
| split(" ") | map(tonumber) | nwise(4)
| {formFeed: .[0], lineFeed: .[1], tab: .[2], space: .[3]} ;
 
def emit_until(cond; stream):
label $out | stream | if cond then break $out else . end;
 
# Input should be the text as a (long) string
Line 689 ⟶ 692:
| label $out
| foreach stream as $c (
{ f: 0, l: 0, t: 0, s: 0 };
| if .f == ui.formFeed and .l == ui.lineFeed and .t == ui.tab and .s == ui.space
 
then .returnout = null$c
| if .f == ui.formFeed and .l == ui.lineFeed and .t == ui.tab and .s == ui.space
then if $c == "!" then .return = false
else .out = $c
| .return = true
end
elif $c == "\f"
then .f += 1
Line 711 ⟶ 709:
else .s += 1
end;
if .return != nullout then .out, break $out else empty end )
// .out"" ;
decode2($uiList) ;
 
# Input: the text
[emit_until(. == "!"; getUserInput as $ui | decode($ui)) ] | add</lang>
</lang>
{{out}}
Invocation: jq -Rsr -f program.jq theRaven.txt
2,449

edits