ignore comments

This commit is contained in:
Robin Appelman 2021-02-24 16:19:51 +01:00
commit f6cd8d6fa0

View file

@ -30,6 +30,8 @@ pub enum Token {
#[token(";")] #[token(";")]
SemiColon, SemiColon,
#[error] #[error]
#[regex(r"(#|//)[^\n]*", logos::skip)]
#[regex(r"/\*([^*]|\*[^/])+\*/", logos::skip)]
#[regex(r"[ \t\n\f]+", logos::skip)] #[regex(r"[ \t\n\f]+", logos::skip)]
Error, Error,
} }
@ -169,6 +171,29 @@ fn test_lex_float() {
assert_eq!(lex.next(), None); assert_eq!(lex.next(), None);
} }
#[test]
fn test_lex_comments() {
let source = r###"
array (
/**
* multi line comment
*/
"double" => /** inline commend */ "quote", //line comment
)
"###;
let mut lex = Token::lexer(source);
assert_eq!(lex.next(), Some(Token::Array));
assert_eq!(lex.next(), Some(Token::BracketOpen));
assert_eq!(lex.next(), Some(Token::LiteralString));
assert_eq!(lex.next(), Some(Token::Arrow));
assert_eq!(lex.next(), Some(Token::LiteralString));
assert_eq!(lex.next(), Some(Token::Comma));
assert_eq!(lex.next(), Some(Token::BracketClose));
}
#[derive(Clone)] #[derive(Clone)]
pub struct SpannedToken<'source> { pub struct SpannedToken<'source> {
pub token: Token, pub token: Token,