mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:35:59 +02:00
Revert "For #
to start a comment, then it either need to be the first chara…" (#14606)
Reverts nushell/nushell#14562 due to https://github.com/nushell/nushell/issues/14605
This commit is contained in:
@ -51,7 +51,7 @@ impl BlockKind {
|
||||
}
|
||||
|
||||
// A baseline token is terminated if it's not nested inside of a paired
|
||||
// delimiter and the next character is one of: `|`, `;` or any
|
||||
// delimiter and the next character is one of: `|`, `;`, `#` or any
|
||||
// whitespace.
|
||||
fn is_item_terminator(
|
||||
block_level: &[BlockKind],
|
||||
@ -115,7 +115,6 @@ pub fn lex_item(
|
||||
// character (whitespace, `|`, `;` or `#`) is encountered, the baseline
|
||||
// token is done.
|
||||
// - Otherwise, accumulate the character into the current baseline token.
|
||||
let mut previous_char = None;
|
||||
while let Some(c) = input.get(*curr_offset) {
|
||||
let c = *c;
|
||||
|
||||
@ -148,9 +147,11 @@ pub fn lex_item(
|
||||
// Also need to check to make sure we aren't escaped
|
||||
quote_start = None;
|
||||
}
|
||||
} 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.
|
||||
in_comment = previous_char.map(|pc| pc == b' ').unwrap_or(true);
|
||||
} else if c == b'#' {
|
||||
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
||||
break;
|
||||
}
|
||||
in_comment = true;
|
||||
} else if c == b'\n' || c == b'\r' {
|
||||
in_comment = false;
|
||||
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
||||
@ -253,7 +254,6 @@ pub fn lex_item(
|
||||
}
|
||||
|
||||
*curr_offset += 1;
|
||||
previous_char = Some(c);
|
||||
}
|
||||
|
||||
let span = Span::new(span_offset + token_start, span_offset + *curr_offset);
|
||||
|
@ -159,29 +159,6 @@ fn lex_comment() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lex_not_comment_needs_space_in_front_of_hashtag() {
|
||||
let file = b"1..10 | each {echo test#testing }";
|
||||
|
||||
let output = lex(file, 0, &[], &[], false);
|
||||
|
||||
assert!(output.1.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lex_comment_with_space_in_front_of_hashtag() {
|
||||
let file = b"1..10 | each {echo test #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]
|
||||
fn lex_is_incomplete() {
|
||||
let file = b"let x = 300 | ;";
|
||||
|
Reference in New Issue
Block a user