mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +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(";")]
|
#[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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue