mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 10:34:08 +02:00
ignore comments
This commit is contained in:
parent
3327a89c3f
commit
f6cd8d6fa0
1 changed files with 25 additions and 0 deletions
25
src/lexer.rs
25
src/lexer.rs
|
|
@ -30,6 +30,8 @@ pub enum Token {
|
|||
#[token(";")]
|
||||
SemiColon,
|
||||
#[error]
|
||||
#[regex(r"(#|//)[^\n]*", logos::skip)]
|
||||
#[regex(r"/\*([^*]|\*[^/])+\*/", logos::skip)]
|
||||
#[regex(r"[ \t\n\f]+", logos::skip)]
|
||||
Error,
|
||||
}
|
||||
|
|
@ -169,6 +171,29 @@ fn test_lex_float() {
|
|||
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)]
|
||||
pub struct SpannedToken<'source> {
|
||||
pub token: Token,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue