comments with a newline dont get together

This commit is contained in:
Fernando Herrera
2021-08-31 20:33:41 +01:00
parent d0be193307
commit 5da2ab1b7d
4 changed files with 134 additions and 21 deletions

View File

@ -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)
}
}

View File

@ -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();