Logos plugged into Parser
This commit is contained in:
@@ -66,13 +66,13 @@ impl<'a> Tokenizer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_token(&mut self) -> Result<Option<Token>, Error> {
|
pub fn next_token(&mut self) -> Result<Option<Token>, Error> {
|
||||||
let to_return = self
|
let mut current = self.lexer.next().transpose();
|
||||||
.lexer
|
|
||||||
.next()
|
|
||||||
.transpose()
|
|
||||||
.map(|t| t.map(|t| self.get_token(t)))?;
|
|
||||||
|
|
||||||
Ok(to_return)
|
while matches!(current, Ok(Some(TokenType::Comment(_)))) {
|
||||||
|
current = self.lexer.next().transpose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(current.map(|t| t.map(|t| self.get_token(t)))?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,8 +233,8 @@ pub enum TokenType {
|
|||||||
/// Represents a symbol token
|
/// Represents a symbol token
|
||||||
Symbol(Symbol),
|
Symbol(Symbol),
|
||||||
|
|
||||||
#[regex(r"///[\n]*", |val| Comment::Doc(val.slice()[3..].trim().to_string()))]
|
#[token("//", |lex| Comment::Line(read_line(lex)))]
|
||||||
#[regex(r"//[\n]*", |val| Comment::Line(val.slice()[2..].trim().to_string()))]
|
#[token("///", |lex| Comment::Doc(read_line(lex)))]
|
||||||
/// Represents a comment, both a line comment and a doc comment
|
/// Represents a comment, both a line comment and a doc comment
|
||||||
Comment(Comment),
|
Comment(Comment),
|
||||||
|
|
||||||
@@ -243,6 +243,15 @@ pub enum TokenType {
|
|||||||
EOF,
|
EOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_line<'a>(lexer: &mut Lexer<'a, TokenType>) -> String {
|
||||||
|
let rem = lexer.remainder();
|
||||||
|
let len = rem.find('\n').unwrap_or(rem.len());
|
||||||
|
let content = rem[..len].trim().to_string();
|
||||||
|
|
||||||
|
lexer.bump(len);
|
||||||
|
content
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Hash, Debug, Eq, PartialEq, Clone)]
|
#[derive(Hash, Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum Comment {
|
pub enum Comment {
|
||||||
Line(String),
|
Line(String),
|
||||||
|
|||||||
Reference in New Issue
Block a user