use multi-backpassing in base64 example

This commit is contained in:
Folkert 2021-03-19 00:27:34 +01:00
parent 73e6128ce3
commit eef1cb2a69
2 changed files with 29 additions and 33 deletions

View file

@ -1224,6 +1224,8 @@ fn parse_expr_end<'a>(
match word2(b'<', b'-', EExpr::BackpassArrow).parse(arena, state) {
Err((_, fail, state)) => Err((MadeProgress, fail, state)),
Ok((_, _, state)) => {
let min_indent = start.col;
let parse_body = space0_before_e(
move |a, s| parse_loc_expr(min_indent + 1, a, s),
min_indent,

View file

@ -11,11 +11,8 @@ decodeBase64 = \width -> Bytes.Decode.loop loopHelp { remaining: width, string:
loopHelp : { remaining : Nat, string : Str } -> Decoder (Bytes.Decode.Step { remaining : Nat, string : Str } Str)
loopHelp = \{ remaining, string } ->
if remaining >= 3 then
Bytes.Decode.map3
Bytes.Decode.u8
Bytes.Decode.u8
Bytes.Decode.u8
\x, y, z ->
x, y, z <- Bytes.Decode.map3 Bytes.Decode.u8 Bytes.Decode.u8 Bytes.Decode.u8
a : U32
a = Num.intCast x
b : U32
@ -33,10 +30,8 @@ loopHelp = \{ remaining, string } ->
Bytes.Decode.succeed (Done string)
else if remaining == 2 then
Bytes.Decode.map2
Bytes.Decode.u8
Bytes.Decode.u8
\x, y ->
x, y <- Bytes.Decode.map2 Bytes.Decode.u8 Bytes.Decode.u8
a : U32
a = Num.intCast x
b : U32
@ -46,9 +41,8 @@ loopHelp = \{ remaining, string } ->
else
# remaining = 1
Bytes.Decode.map
Bytes.Decode.u8
\x ->
x <- Bytes.Decode.map Bytes.Decode.u8
a : U32
a = Num.intCast x
Done (Str.concat string (bitsToChars (Num.shiftLeftBy 16 a) 2))