lexer: Fun little lexer hack to allow trailing commas
This commit is contained in:
parent
222b2d7b98
commit
4b0f30f78e
11
src/lexer.rs
11
src/lexer.rs
@ -123,7 +123,7 @@ impl<'t> Lexer<'t> {
|
|||||||
')' => RParen,
|
')' => RParen,
|
||||||
'*' => Star,
|
'*' => Star,
|
||||||
'+' => Plus,
|
'+' => Plus,
|
||||||
',' => Comma,
|
',' => return self.consume().trailing(Comma),
|
||||||
'-' => Minus,
|
'-' => Minus,
|
||||||
'.' => Dot,
|
'.' => Dot,
|
||||||
'/' => Slash,
|
'/' => Slash,
|
||||||
@ -198,6 +198,15 @@ impl<'t> Lexer<'t> {
|
|||||||
Ok(self.consume().produce(tok))
|
Ok(self.consume().produce(tok))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn trailing(&mut self, kind: TKind) -> Result<Token, LexError> {
|
||||||
|
Ok(match self.skip_whitespace().peek() {
|
||||||
|
// Some(')') => self.consume().produce(TKind::RParen), // maybe.
|
||||||
|
Some(']') => self.consume().produce(TKind::RBrack),
|
||||||
|
Some('}') => self.consume().produce(TKind::RCurly),
|
||||||
|
_ => self.produce(kind),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn line_comment(&mut self) -> Result<Token, LexError> {
|
pub fn line_comment(&mut self) -> Result<Token, LexError> {
|
||||||
while self.consume().peek().is_some_and(|c| c != '\n') {}
|
while self.consume().peek().is_some_and(|c| c != '\n') {}
|
||||||
Ok(self.produce(TKind::Comment))
|
Ok(self.produce(TKind::Comment))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user