Backslash escaped newline support

This commit is contained in:
Axel Liljencrantz 2024-07-26 17:41:17 +02:00
parent e0bb07676b
commit 8c2bf5ab79

View File

@ -61,6 +61,15 @@ impl<'input> Lexer<'input> {
Some((i, '|')) => return Some(Token::Pipe(Location::from(i)).into()),
Some((i, ';')) => return Some(Token::Separator(";", Location::from(i)).into()),
Some((i, '\n')) => return Some(Token::Separator("\n", Location::from(i)).into()),
Some((i, '\\')) =>
match self.chars.peek() {
Some((_, '\n')) => {
self.chars.next();
continue;
}
Some((_, ch)) => return Some(Err(LexicalError::UnexpectedCharacter(*ch))),
None => return Some(Err(LexicalError::UnexpectedEOFWithSuggestion('\n'))),
}
Some((i, '<')) =>
match self.chars.peek() {
Some((_, '=')) => {
@ -339,6 +348,15 @@ impl<'input> Lexer<'input> {
Some((i, ';')) => return Some(Token::Separator(";", Location::from(i)).into()),
Some((i, ',')) => return Some(Token::Separator(",", Location::from(i)).into()),
Some((i, '\n')) => return Some(Token::Separator("\n", Location::from(i)).into()),
Some((i, '\\')) =>
match self.chars.peek() {
Some((_, '\n')) => {
self.chars.next();
continue;
}
Some((_, ch)) => return Some(Err(LexicalError::UnexpectedCharacter(*ch))),
None => return Some(Err(LexicalError::UnexpectedEOFWithSuggestion('\n'))),
}
Some((i, '<')) =>
match self.chars.peek() {