Handle single and multi line comments
This commit is contained in:
parent
197129aa6d
commit
e5f70e0a7a
22
src/lexer.rs
22
src/lexer.rs
@ -52,6 +52,7 @@ impl<'a> Iterator for Lexer<'a> {
|
||||
'{' => symbol!(self, OpenBrace),
|
||||
'*' => symbol!(self, Mul),
|
||||
'}' => symbol!(self, CloseBrace),
|
||||
'/' => self.lex_forward_slash(),
|
||||
'%' => {
|
||||
self.buf.next();
|
||||
self.pos.next_char();
|
||||
@ -117,6 +118,27 @@ impl<'a> Lexer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn lex_forward_slash(&mut self) -> TokenKind {
|
||||
self.buf.next();
|
||||
self.pos.next_char();
|
||||
match self.buf.peek().expect("expected something after '/'") {
|
||||
'/' => {
|
||||
self.buf.by_ref().skip_while(|x| x != &'\n').count();
|
||||
}
|
||||
'*' => {
|
||||
while let Some(tok) = self.buf.next() {
|
||||
if tok == '*' {
|
||||
if self.buf.next() == Some('/') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => return TokenKind::Symbol(Symbol::Div),
|
||||
}
|
||||
TokenKind::Whitespace(Whitespace::Newline)
|
||||
}
|
||||
|
||||
fn lex_num(&mut self) -> TokenKind {
|
||||
let mut string = String::with_capacity(99);
|
||||
while let Some(c) = self.buf.peek() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user