lexer: fix comment tokenization skipping next character

This commit is contained in:
Ryan Chandler 2022-12-05 12:23:31 +00:00
parent aa9f33a726
commit 4b73900b59
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
6 changed files with 88 additions and 1 deletions

View File

@ -349,7 +349,6 @@ impl Lexer {
[] => unreachable!(),
}
}
state.next();
if buffer.starts_with(b"/**") {
TokenKind::DocComment(buffer.into())

View File

@ -1,3 +1,5 @@
use std::process::exit;
use php_parser_rs::prelude::Lexer;
use php_parser_rs::prelude::Parser;

View File

@ -155,6 +155,7 @@ impl Parser {
pub(in crate::parser) fn args_list(&self, state: &mut State) -> ParseResult<Vec<Arg>> {
self.lparen(state)?;
state.skip_comments();
let mut args = Vec::new();

18
tests/0245/ast.txt Normal file
View File

@ -0,0 +1,18 @@
[
Expression {
expr: Array {
items: [
ArrayItem {
key: None,
value: Call {
target: Identifier {
name: "foo",
},
args: [],
},
unpack: false,
},
],
},
},
]

3
tests/0245/code.php Normal file
View File

@ -0,0 +1,3 @@
<?php
[foo(/* comment here */)];

64
tests/0245/tokens.txt Normal file
View File

@ -0,0 +1,64 @@
[
Token {
kind: OpenTag(
Full,
),
span: (
1,
1,
),
},
Token {
kind: LeftBracket,
span: (
3,
1,
),
},
Token {
kind: Identifier(
"foo",
),
span: (
3,
2,
),
},
Token {
kind: LeftParen,
span: (
3,
5,
),
},
Token {
kind: Comment(
"/* comment here */",
),
span: (
3,
6,
),
},
Token {
kind: RightParen,
span: (
3,
24,
),
},
Token {
kind: RightBracket,
span: (
3,
25,
),
},
Token {
kind: SemiColon,
span: (
3,
26,
),
},
]