Just in time processing on a character stream: Difference between revisions
Just in time processing on a character stream (view source)
Revision as of 18:35, 15 October 2021
, 2 years ago→{{header|jq}}: emit_until
(→{{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 };
then .
▲ | if .f == ui.formFeed and .l == ui.lineFeed and .t == ui.tab and .s == ui.space
elif $c == "\f"
then .f += 1
Line 711 ⟶ 709:
else .s += 1
end;
if .
//
decode2($uiList) ;
# Input: the text
[emit_until(. == "!"; getUserInput as $ui | decode($ui)) ] | add</lang>
{{out}}
Invocation: jq -Rsr -f program.jq theRaven.txt
|