mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +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,47 +11,41 @@ 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
|
a : U32
|
||||||
Bytes.Decode.u8
|
a = Num.intCast x
|
||||||
\x, y, z ->
|
b : U32
|
||||||
a : U32
|
b = Num.intCast y
|
||||||
a = Num.intCast x
|
c : U32
|
||||||
b : U32
|
c = Num.intCast z
|
||||||
b = Num.intCast y
|
combined = Num.bitwiseOr (Num.bitwiseOr (Num.shiftLeftBy 16 a) (Num.shiftLeftBy 8 b)) c
|
||||||
c : U32
|
Loop
|
||||||
c = Num.intCast z
|
{
|
||||||
combined = Num.bitwiseOr (Num.bitwiseOr (Num.shiftLeftBy 16 a) (Num.shiftLeftBy 8 b)) c
|
remaining: remaining - 3,
|
||||||
Loop
|
string: Str.concat string (bitsToChars combined 0)
|
||||||
{
|
}
|
||||||
remaining: remaining - 3,
|
|
||||||
string: Str.concat string (bitsToChars combined 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
else if remaining == 0 then
|
else if remaining == 0 then
|
||||||
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
|
a : U32
|
||||||
\x, y ->
|
a = Num.intCast x
|
||||||
a : U32
|
b : U32
|
||||||
a = Num.intCast x
|
b = Num.intCast y
|
||||||
b : U32
|
combined = Num.bitwiseOr (Num.shiftLeftBy 16 a) (Num.shiftLeftBy 8 b)
|
||||||
b = Num.intCast y
|
Done (Str.concat string (bitsToChars combined 1))
|
||||||
combined = Num.bitwiseOr (Num.shiftLeftBy 16 a) (Num.shiftLeftBy 8 b)
|
|
||||||
Done (Str.concat string (bitsToChars combined 1))
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
bitsToChars : U32, Int * -> Str
|
bitsToChars : U32, Int * -> Str
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue