-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f708f69
commit 555d2c4
Showing
4 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import gleam/int | ||
import lenient_parse/internal/tokenizer.{type Token, Whitespace} | ||
|
||
// TODO: Better name | ||
|
||
pub type WhitespaceBlockTracker = | ||
Int | ||
|
||
pub fn new() -> WhitespaceBlockTracker { | ||
0 | ||
} | ||
|
||
pub fn mark( | ||
tracker: WhitespaceBlockTracker, | ||
token: Token, | ||
) -> WhitespaceBlockTracker { | ||
case token, tracker % 2 == 0 { | ||
Whitespace(_), True -> tracker | ||
Whitespace(_), False -> tracker |> int.bitwise_shift_left(1) | ||
_, True -> { tracker |> int.bitwise_shift_left(1) } + 1 | ||
_, False -> tracker | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import gleam/list | ||
import lenient_parse/internal/tokenizer | ||
import lenient_parse/internal/whitespace_block_tracker | ||
import startest/expect | ||
|
||
// TODO: Convert to describe-style data-driven tests | ||
|
||
pub fn whitespace_block_tracker_test() { | ||
" " | ||
|> build_tracker_int | ||
|> expect.to_equal(0b0) | ||
|
||
"123123" | ||
|> build_tracker_int | ||
|> expect.to_equal(0b1) | ||
|
||
"1 1 1 1 " | ||
|> build_tracker_int | ||
|> expect.to_equal(0b10101010) | ||
|
||
" 12 3.400 " | ||
|> build_tracker_int | ||
|> expect.to_equal(0b1010) | ||
} | ||
|
||
fn build_tracker_int(text: String) -> Int { | ||
text | ||
|> tokenizer.tokenize_number_string | ||
|> list.fold(whitespace_block_tracker.new(), fn(tracker, token) { | ||
tracker |> whitespace_block_tracker.mark(token) | ||
}) | ||
} |