mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
use multi-backpassing in base64 example
This commit is contained in:
parent
73e6128ce3
commit
eef1cb2a69
2 changed files with 29 additions and 33 deletions
|
@ -1224,6 +1224,8 @@ fn parse_expr_end<'a>(
|
||||||
match word2(b'<', b'-', EExpr::BackpassArrow).parse(arena, state) {
|
match word2(b'<', b'-', EExpr::BackpassArrow).parse(arena, state) {
|
||||||
Err((_, fail, state)) => Err((MadeProgress, fail, state)),
|
Err((_, fail, state)) => Err((MadeProgress, fail, state)),
|
||||||
Ok((_, _, state)) => {
|
Ok((_, _, state)) => {
|
||||||
|
let min_indent = start.col;
|
||||||
|
|
||||||
let parse_body = space0_before_e(
|
let parse_body = space0_before_e(
|
||||||
move |a, s| parse_loc_expr(min_indent + 1, a, s),
|
move |a, s| parse_loc_expr(min_indent + 1, a, s),
|
||||||
min_indent,
|
min_indent,
|
||||||
|
|
|
@ -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 : Nat, string : Str } -> Decoder (Bytes.Decode.Step { remaining : Nat, string : Str } Str)
|
||||||
loopHelp = \{ remaining, string } ->
|
loopHelp = \{ remaining, string } ->
|
||||||
if remaining >= 3 then
|
if remaining >= 3 then
|
||||||
Bytes.Decode.map3
|
x, y, z <- Bytes.Decode.map3 Bytes.Decode.u8 Bytes.Decode.u8 Bytes.Decode.u8
|
||||||
Bytes.Decode.u8
|
|
||||||
Bytes.Decode.u8
|
|
||||||
Bytes.Decode.u8
|
|
||||||
\x, y, z ->
|
|
||||||
a : U32
|
a : U32
|
||||||
a = Num.intCast x
|
a = Num.intCast x
|
||||||
b : U32
|
b : U32
|
||||||
|
@ -33,10 +30,8 @@ loopHelp = \{ remaining, string } ->
|
||||||
Bytes.Decode.succeed (Done string)
|
Bytes.Decode.succeed (Done string)
|
||||||
|
|
||||||
else if remaining == 2 then
|
else if remaining == 2 then
|
||||||
Bytes.Decode.map2
|
x, y <- Bytes.Decode.map2 Bytes.Decode.u8 Bytes.Decode.u8
|
||||||
Bytes.Decode.u8
|
|
||||||
Bytes.Decode.u8
|
|
||||||
\x, y ->
|
|
||||||
a : U32
|
a : U32
|
||||||
a = Num.intCast x
|
a = Num.intCast x
|
||||||
b : U32
|
b : U32
|
||||||
|
@ -46,9 +41,8 @@ loopHelp = \{ remaining, string } ->
|
||||||
|
|
||||||
else
|
else
|
||||||
# remaining = 1
|
# remaining = 1
|
||||||
Bytes.Decode.map
|
x <- Bytes.Decode.map Bytes.Decode.u8
|
||||||
Bytes.Decode.u8
|
|
||||||
\x ->
|
|
||||||
a : U32
|
a : U32
|
||||||
a = Num.intCast x
|
a = Num.intCast x
|
||||||
Done (Str.concat string (bitsToChars (Num.shiftLeftBy 16 a) 2))
|
Done (Str.concat string (bitsToChars (Num.shiftLeftBy 16 a) 2))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue