forked from extern/nushell
comments with a newline dont get together
This commit is contained in:
@ -273,7 +273,15 @@ pub fn lex(
|
||||
if *input == b'\n' || *input == b'\r' {
|
||||
output.push(Token::new(
|
||||
TokenContents::Comment,
|
||||
Span::new(start, curr_offset),
|
||||
Span::new(start, curr_offset - 1),
|
||||
));
|
||||
|
||||
// Adding an end of line token after a comment
|
||||
// This helps during lite_parser to avoid losing a command
|
||||
// in a statement
|
||||
output.push(Token::new(
|
||||
TokenContents::Eol,
|
||||
Span::new(curr_offset - 1, curr_offset),
|
||||
));
|
||||
start = curr_offset;
|
||||
|
||||
@ -307,4 +315,4 @@ pub fn lex(
|
||||
}
|
||||
}
|
||||
(output, error)
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ impl LiteCommand {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.parts.is_empty()
|
||||
}
|
||||
|
||||
pub fn is_empty_comments(&self) -> bool {
|
||||
self.comments.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -94,7 +98,7 @@ pub fn lite_parse(tokens: &[Token]) -> (LiteBlock, Option<ParseError>) {
|
||||
}
|
||||
}
|
||||
TokenContents::Eol | TokenContents::Semicolon => {
|
||||
if !curr_command.is_empty() {
|
||||
if !curr_command.is_empty() || !curr_command.is_empty_comments() {
|
||||
curr_pipeline.push(curr_command);
|
||||
}
|
||||
curr_command = LiteCommand::new();
|
||||
|
Reference in New Issue
Block a user