mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
Add missing rules to parser to allow a::${b}
This commit is contained in:
parent
4e50877e27
commit
2fb0206deb
20140
grammar/y.output
20140
grammar/y.output
File diff suppressed because it is too large
Load Diff
@ -697,6 +697,10 @@ base_variable:
|
||||
static_property_with_arrays:
|
||||
class_name T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
||||
{ $$ = new Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1))); }
|
||||
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
||||
{ $$ = new Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => substr($3, 1))); }
|
||||
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
||||
{ $$ = new Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5)); }
|
||||
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
||||
{ $$ = new Node_Expr_StaticPropertyFetch(array('class' => $1, 'name' => $5)); }
|
||||
| static_property_with_arrays '[' dim_offset ']' { $$ = new Node_Expr_ArrayDimFetch(array('var' => $1, 'dim' => $3)); }
|
||||
|
@ -697,6 +697,10 @@ base_variable:
|
||||
static_property_with_arrays:
|
||||
class_name T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
||||
{ $$ = Expr_StaticPropertyFetch[class: $1, name: parseVar($3)]; }
|
||||
| reference_variable T_PAAMAYIM_NEKUDOTAYIM T_VARIABLE
|
||||
{ $$ = Expr_StaticPropertyFetch[class: $1, name: parseVar($3)]; }
|
||||
| class_name T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
||||
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; }
|
||||
| reference_variable T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}'
|
||||
{ $$ = Expr_StaticPropertyFetch[class: $1, name: $5]; }
|
||||
| static_property_with_arrays '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[var: $1, dim: $3]; }
|
||||
|
918
lib/Parser.php
918
lib/Parser.php
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
22
test.php
22
test.php
@ -8,28 +8,6 @@ echo '<pre>';
|
||||
|
||||
$parser = new Parser;
|
||||
$prettyPrinter = new PrettyPrinter_Zend;
|
||||
$nodeDumper = new NodeDumper;
|
||||
|
||||
// Output Demo
|
||||
$stmts = $parser->parse(new Lexer(
|
||||
'<?php
|
||||
x::$y[z];
|
||||
$x->y[z];
|
||||
$x->y[z][k]->l()->m[t];
|
||||
$x->y[z]();
|
||||
$x->$y[z]();
|
||||
$x->$$y[z]();'
|
||||
),
|
||||
function ($msg) {
|
||||
echo $msg;
|
||||
}
|
||||
);
|
||||
|
||||
if (false !== $stmts) {
|
||||
echo htmlspecialchars($nodeDumper->dump($stmts));
|
||||
}
|
||||
|
||||
echo "\n\n";
|
||||
|
||||
$code = $prettyPrinter->pStmts(
|
||||
$parser->parse(
|
||||
|
@ -10,31 +10,9 @@ $parser = new Parser;
|
||||
$prettyPrinter = new PrettyPrinter_Zend;
|
||||
$nodeDumper = new NodeDumper;
|
||||
|
||||
echo '<!DOCTYPE html>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Trebuchet MS", sans-serif;
|
||||
}
|
||||
include './testFormatting.html';
|
||||
|
||||
.pass {
|
||||
color: white;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.fail {
|
||||
color: white;
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.failReason {
|
||||
background-color: rgba(255, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.failCount {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
<table>
|
||||
echo '<table>
|
||||
<tr>
|
||||
<td>File</td>
|
||||
<td>Parse</td>
|
||||
|
44
test/testExpressions.php
Normal file
44
test/testExpressions.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
$exprs = <<<'EXPRS'
|
||||
a::$b
|
||||
$a::$b
|
||||
a::${b}
|
||||
$a::${b}
|
||||
a::$$b
|
||||
$a::$$b
|
||||
EXPRS;
|
||||
|
||||
function __autoload($class) {
|
||||
is_file($file = '../lib/' . strtr($class, '_', '/') . '.php') && require_once $file;
|
||||
}
|
||||
|
||||
$parser = new Parser;
|
||||
|
||||
include './testFormatting.html';
|
||||
|
||||
echo '<table>
|
||||
<tr>
|
||||
<td>Expression</td>
|
||||
<td>Result</td>
|
||||
</tr>';
|
||||
|
||||
foreach (explode("\n", $exprs) as $expr) {
|
||||
if ('' === $expr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($parser->parse(
|
||||
new Lexer('<?php ' . $expr . ';'),
|
||||
function ($msg) use(&$errMsg) {
|
||||
$errMsg = $msg;
|
||||
}
|
||||
)
|
||||
) {
|
||||
echo '<tr><td>' . $expr . '</td><td class="pass">PASS</td></tr>';
|
||||
} else {
|
||||
echo '<tr><td>' . $expr . '</td><td class="fail">FAIL</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</table>';
|
24
test/testFormatting.html
Normal file
24
test/testFormatting.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<style>
|
||||
body {
|
||||
font-family: "Trebuchet MS", sans-serif;
|
||||
}
|
||||
|
||||
.pass {
|
||||
color: white;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.fail {
|
||||
color: white;
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.failReason {
|
||||
background-color: rgba(255, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.failCount {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user