mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +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
|
skip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// also skips lines that contain only whitespace
|
||||||
fn skip_newlines(bytes: &[u8]) -> (usize, usize) {
|
fn skip_newlines(bytes: &[u8]) -> (usize, usize) {
|
||||||
let mut skip = 0;
|
let mut skip = 0;
|
||||||
let mut indent = 0;
|
let mut indent = 0;
|
||||||
|
@ -294,7 +295,12 @@ mod test_peg_grammar {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
indent = spaces;
|
if bytes.len() > (skip + spaces) && bytes[skip + spaces] == b'\n' {
|
||||||
|
indent = 0;
|
||||||
|
skip += spaces;
|
||||||
|
} else {
|
||||||
|
indent = spaces;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(skip, indent)
|
(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
|
// Inspired by https://ziglang.org/documentation/0.7.1/#Grammar
|
||||||
// license information can be found in the LEGAL_DETAILS file in
|
// license information can be found in the LEGAL_DETAILS file in
|
||||||
// the root directory of this distribution.
|
// the root directory of this distribution.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue