mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
fixed tokenization for line with only spaces
This commit is contained in:
parent
1b37aa8a3d
commit
86c3eead71
1 changed files with 30 additions and 2 deletions
|
@ -280,6 +280,7 @@ mod test_peg_grammar {
|
|||
skip
|
||||
}
|
||||
|
||||
// also skips lines that contain only whitespace
|
||||
fn skip_newlines(bytes: &[u8]) -> (usize, usize) {
|
||||
let mut skip = 0;
|
||||
let mut indent = 0;
|
||||
|
@ -294,8 +295,13 @@ mod test_peg_grammar {
|
|||
0
|
||||
};
|
||||
|
||||
if bytes.len() > (skip + spaces) && bytes[skip + spaces] == b'\n' {
|
||||
indent = 0;
|
||||
skip += spaces;
|
||||
} else {
|
||||
indent = spaces;
|
||||
}
|
||||
}
|
||||
|
||||
(skip, indent)
|
||||
}
|
||||
|
@ -477,6 +483,28 @@ fn test_indent_tokenization_2() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tokenization_line_with_only_spaces() {
|
||||
let tokens = test_tokenize(r#"\key ->
|
||||
when dict is
|
||||
Empty ->
|
||||
4
|
||||
|
||||
Node ->
|
||||
5"#);
|
||||
|
||||
assert_eq!(
|
||||
tokens,
|
||||
[T::LambdaStart, T::LowercaseIdent, T::Arrow,
|
||||
T::OpenIndent, T::KeywordWhen, T::LowercaseIdent, T::KeywordIs,
|
||||
T::OpenIndent, T::UppercaseIdent, T::Arrow,
|
||||
T::OpenIndent, T::Number,
|
||||
T::CloseIndent,
|
||||
T::UppercaseIdent, T::Arrow,
|
||||
T::OpenIndent, T::Number]
|
||||
);
|
||||
}
|
||||
|
||||
// Inspired by https://ziglang.org/documentation/0.7.1/#Grammar
|
||||
// license information can be found in the LEGAL_DETAILS file in
|
||||
// the root directory of this distribution.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue