mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
#10327 Now hashtags get parsed as comment starters if they are prefixed with any whitespace.
This commit is contained in:
parent
4604e12eb0
commit
0dae22d438
2 changed files with 19 additions and 2 deletions
|
@ -149,8 +149,11 @@ pub fn lex_item(
|
||||||
quote_start = None;
|
quote_start = None;
|
||||||
}
|
}
|
||||||
} else if c == b'#' && !in_comment {
|
} else if c == b'#' && !in_comment {
|
||||||
// To start a comment, It either need to be the first character of the token or prefixed with space.
|
// To start a comment, It either need to be the first character of the token or prefixed with whitespace.
|
||||||
in_comment = previous_char.map(|pc| pc == b' ').unwrap_or(true);
|
in_comment = previous_char
|
||||||
|
.map(char::from)
|
||||||
|
.map(char::is_whitespace)
|
||||||
|
.unwrap_or(true);
|
||||||
} else if c == b'\n' || c == b'\r' {
|
} else if c == b'\n' || c == b'\r' {
|
||||||
in_comment = false;
|
in_comment = false;
|
||||||
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
||||||
|
|
|
@ -182,6 +182,20 @@ fn lex_comment_with_space_in_front_of_hashtag() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lex_comment_with_tab_in_front_of_hashtag() {
|
||||||
|
let file = b"1..10 | each {echo test\t#testing }";
|
||||||
|
|
||||||
|
let output = lex(file, 0, &[], &[], false);
|
||||||
|
|
||||||
|
assert!(output.1.is_some());
|
||||||
|
assert!(matches!(
|
||||||
|
output.1.unwrap(),
|
||||||
|
ParseError::UnexpectedEof(missing_token, span) if missing_token == "}"
|
||||||
|
&& span == Span::new(33, 34)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lex_is_incomplete() {
|
fn lex_is_incomplete() {
|
||||||
let file = b"let x = 300 | ;";
|
let file = b"let x = 300 | ;";
|
||||||
|
|
Loading…
Reference in a new issue