Constant declarations with names matching certain reserved words result in parsing errors:
callable
namespace
void
false
mixed
true
I suspect this is due to the reserved words being created as regexes with the case insensitive "i" flag here:
It's not clear to me why some reserved words conflict and others don't.
<?php
const CALLABLE = 'callable';
const NAMESPACE = 'namespace';
const VOID = 'void';
const FALSE = 'false';
const MIXED = 'mixed';
const TRUE = 'true';
(program [0, 0] - [8, 0]
(php_tag [0, 0] - [0, 5])
(ERROR [1, 0] - [1, 16])
(expression_statement [1, 17] - [1, 28]
(string [1, 17] - [1, 27]
(string_content [1, 18] - [1, 26])))
(ERROR [2, 0] - [2, 17])
(expression_statement [2, 18] - [2, 30]
(string [2, 18] - [2, 29]
(string_content [2, 19] - [2, 28])))
(ERROR [4, 0] - [4, 12])
(expression_statement [4, 13] - [4, 20]
(string [4, 13] - [4, 19]
(string_content [4, 14] - [4, 18])))
(ERROR [5, 0] - [5, 13])
(expression_statement [5, 14] - [5, 22]
(string [5, 14] - [5, 21]
(string_content [5, 15] - [5, 20])))
(ERROR [6, 0] - [6, 13])
(expression_statement [6, 14] - [6, 22]
(string [6, 14] - [6, 21]
(string_content [6, 15] - [6, 20])))
(ERROR [7, 0] - [7, 12])
(expression_statement [7, 13] - [7, 20]
(string [7, 13] - [7, 19]
(string_content [7, 14] - [7, 18]))))
0:0 - 8:0 •program
0:0 - 0:5 php_tag `<?php`
1:0 - 1:16 •ERROR
1:0 - 1:5 "const"
1:15 - 1:16 "="
1:17 - 1:28 expression_statement
1:17 - 1:27 string
1:17 - 1:18 "'"
1:18 - 1:26 string_content `callable`
1:26 - 1:27 "'"
1:27 - 1:28 ";"
2:0 - 2:17 •ERROR
2:0 - 2:5 "const"
2:6 - 2:15 "namespace"
2:16 - 2:17 "="
2:18 - 2:30 expression_statement
2:18 - 2:29 string
2:18 - 2:19 "'"
2:19 - 2:28 string_content `namespace`
2:28 - 2:29 "'"
2:29 - 2:30 ";"
4:0 - 4:12 •ERROR
4:0 - 4:5 "const"
4:11 - 4:12 "="
4:13 - 4:20 expression_statement
4:13 - 4:19 string
4:13 - 4:14 "'"
4:14 - 4:18 string_content `void`
4:18 - 4:19 "'"
4:19 - 4:20 ";"
5:0 - 5:13 •ERROR
5:0 - 5:5 "const"
5:12 - 5:13 "="
5:14 - 5:22 expression_statement
5:14 - 5:21 string
5:14 - 5:15 "'"
5:15 - 5:20 string_content `false`
5:20 - 5:21 "'"
5:21 - 5:22 ";"
6:0 - 6:13 •ERROR
6:0 - 6:5 "const"
6:12 - 6:13 "="
6:14 - 6:22 expression_statement
6:14 - 6:21 string
6:14 - 6:15 "'"
6:15 - 6:20 string_content `mixed`
6:20 - 6:21 "'"
6:21 - 6:22 ";"
7:0 - 7:12 •ERROR
7:0 - 7:5 "const"
7:11 - 7:12 "="
7:13 - 7:20 expression_statement
7:13 - 7:19 string
7:13 - 7:14 "'"
7:14 - 7:18 string_content `true`
7:18 - 7:19 "'"
7:19 - 7:20 ";"
Did you check existing issues?
Tree-Sitter CLI Version, if relevant (output of
tree-sitter --version)tree-sitter 0.26.3
Describe the bug
Constant declarations with names matching certain reserved words result in parsing errors:
After briefly checking the members of
BASE_RESERVED_KEYWORD_SETandOTHER_RESERVED_KEYWORD_SETfromcommon/define-grammar.js, I found the following names to be problematic:I suspect this is due to the reserved words being created as regexes with the case insensitive "i" flag here:
tree-sitter-php/common/define-grammar.js
Lines 1665 to 1670 in 7d07b41
It's not clear to me why some reserved words conflict and others don't.
Steps To Reproduce/Bad Parse Tree
input:
Resulting s-expression/cst:
Originally discussed here: #293 (comment)
Expected Behavior/Parse Tree
The code should parse correctly as a
const_declarationnode.