Skip to content

Commit 5cff923

Browse files
committed
Fix tokenizer to tokenize T_NUM_STRING and T_VAR_NAME correctly
1 parent 5549ff2 commit 5cff923

14 files changed

+193
-2
lines changed

src/PhpTokenizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,13 @@ public static function getTokensArrayFromContent(
289289
T_OBJECT_CAST => TokenKind::ObjectCastToken,
290290
T_STRING_CAST => TokenKind::StringCastToken,
291291
T_UNSET_CAST => TokenKind::UnsetCastToken,
292+
292293
T_START_HEREDOC => TokenKind::HeredocStart,
293294
T_END_HEREDOC => TokenKind::HeredocEnd,
294-
T_STRING_VARNAME => TokenKind::VariableName,
295+
T_STRING_VARNAME => TokenKind::StringVarname,
295296
T_COMMENT => TokenKind::CommentToken,
296-
T_DOC_COMMENT => TokenKind::DocCommentToken
297+
T_DOC_COMMENT => TokenKind::DocCommentToken,
298+
T_NUM_STRING => TokenKind::NumStringToken
297299
];
298300

299301
const PARSE_CONTEXT_TO_PREFIX = [

src/TokenKind.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class TokenKind {
214214
const IntegerLiteralToken = 416;
215215
const CommentToken = 417;
216216
const DocCommentToken = 418;
217+
const NumStringToken = 419;
217218

218219
// TODO type annotations - PHP7
219220
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
"$x"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"kind": "ScriptSectionStartTag",
4+
"textLength": 6
5+
},
6+
{
7+
"kind": "DoubleQuoteToken",
8+
"textLength": 1
9+
},
10+
{
11+
"kind": "VariableName",
12+
"textLength": 2
13+
},
14+
{
15+
"kind": "DoubleQuoteToken",
16+
"textLength": 1
17+
},
18+
{
19+
"kind": "EndOfFileToken",
20+
"textLength": 0
21+
}
22+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
"${x}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"kind": "ScriptSectionStartTag",
4+
"textLength": 6
5+
},
6+
{
7+
"kind": "DoubleQuoteToken",
8+
"textLength": 1
9+
},
10+
{
11+
"kind": "DollarOpenBraceToken",
12+
"textLength": 2
13+
},
14+
{
15+
"kind": "StringVarname",
16+
"textLength": 1
17+
},
18+
{
19+
"kind": "CloseBraceToken",
20+
"textLength": 1
21+
},
22+
{
23+
"kind": "DoubleQuoteToken",
24+
"textLength": 1
25+
},
26+
{
27+
"kind": "EndOfFileToken",
28+
"textLength": 0
29+
}
30+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
"${$x}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"kind": "ScriptSectionStartTag",
4+
"textLength": 6
5+
},
6+
{
7+
"kind": "DoubleQuoteToken",
8+
"textLength": 1
9+
},
10+
{
11+
"kind": "DollarOpenBraceToken",
12+
"textLength": 2
13+
},
14+
{
15+
"kind": "VariableName",
16+
"textLength": 2
17+
},
18+
{
19+
"kind": "CloseBraceToken",
20+
"textLength": 1
21+
},
22+
{
23+
"kind": "DoubleQuoteToken",
24+
"textLength": 1
25+
},
26+
{
27+
"kind": "EndOfFileToken",
28+
"textLength": 0
29+
}
30+
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
"{$x}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"kind": "ScriptSectionStartTag",
4+
"textLength": 6
5+
},
6+
{
7+
"kind": "DoubleQuoteToken",
8+
"textLength": 1
9+
},
10+
{
11+
"kind": "OpenBraceDollarToken",
12+
"textLength": 1
13+
},
14+
{
15+
"kind": "VariableName",
16+
"textLength": 2
17+
},
18+
{
19+
"kind": "CloseBraceToken",
20+
"textLength": 1
21+
},
22+
{
23+
"kind": "DoubleQuoteToken",
24+
"textLength": 1
25+
},
26+
{
27+
"kind": "EndOfFileToken",
28+
"textLength": 0
29+
}
30+
]

0 commit comments

Comments
 (0)