mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2025-01-22 05:11:39 +01:00
Merge branch '2.x'
This commit is contained in:
commit
a7120116b0
@ -150,7 +150,7 @@ inner_statement:
|
|||||||
;
|
;
|
||||||
|
|
||||||
non_empty_statement:
|
non_empty_statement:
|
||||||
'{' inner_statement_list '}' { $$ = $2; }
|
'{' inner_statement_list '}' { $$ = $2; prependLeadingComments($$); }
|
||||||
| T_IF parentheses_expr statement elseif_list else_single
|
| T_IF parentheses_expr statement elseif_list else_single
|
||||||
{ $$ = Stmt\If_[$2, ['stmts' => toArray($3), 'elseifs' => $4, 'else' => $5]]; }
|
{ $$ = Stmt\If_[$2, ['stmts' => toArray($3), 'elseifs' => $4, 'else' => $5]]; }
|
||||||
| T_IF parentheses_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
|
| T_IF parentheses_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
|
||||||
|
@ -150,7 +150,7 @@ inner_statement:
|
|||||||
;
|
;
|
||||||
|
|
||||||
non_empty_statement:
|
non_empty_statement:
|
||||||
'{' inner_statement_list '}' { $$ = $2; }
|
'{' inner_statement_list '}' { $$ = $2; prependLeadingComments($$); }
|
||||||
| T_IF '(' expr ')' statement elseif_list else_single
|
| T_IF '(' expr ')' statement elseif_list else_single
|
||||||
{ $$ = Stmt\If_[$3, ['stmts' => toArray($5), 'elseifs' => $6, 'else' => $7]]; }
|
{ $$ = Stmt\If_[$3, ['stmts' => toArray($5), 'elseifs' => $6, 'else' => $7]]; }
|
||||||
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
|
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
|
||||||
|
@ -195,6 +195,15 @@ function resolveMacros($code) {
|
|||||||
. $args[0] . '[\'docLabel\'] = $matches[1];';
|
. $args[0] . '[\'docLabel\'] = $matches[1];';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('prependLeadingComments' == $name) {
|
||||||
|
assertArgs(1, $args, $name);
|
||||||
|
|
||||||
|
return '$attrs = $this->startAttributeStack[#1]; $stmts = ' . $args[0] . '; '
|
||||||
|
. 'if (!empty($attrs[\'comments\']) && isset($stmts[0])) {'
|
||||||
|
. '$stmts[0]->setAttribute(\'comments\', '
|
||||||
|
. 'array_merge($attrs[\'comments\'], $stmts[0]->getAttribute(\'comments\', []))); }';
|
||||||
|
}
|
||||||
|
|
||||||
return $matches[0];
|
return $matches[0];
|
||||||
},
|
},
|
||||||
$code
|
$code
|
||||||
|
@ -1420,7 +1420,7 @@ class Php5 extends \PhpParser\ParserAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function reduceRule127() {
|
protected function reduceRule127() {
|
||||||
$this->semValue = $this->semStack[$this->stackPos-(3-2)];
|
$this->semValue = $this->semStack[$this->stackPos-(3-2)]; $attrs = $this->startAttributeStack[$this->stackPos-(3-1)]; $stmts = $this->semValue; if (!empty($attrs['comments']) && isset($stmts[0])) {$stmts[0]->setAttribute('comments', array_merge($attrs['comments'], $stmts[0]->getAttribute('comments', []))); };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function reduceRule128() {
|
protected function reduceRule128() {
|
||||||
|
@ -1305,7 +1305,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function reduceRule127() {
|
protected function reduceRule127() {
|
||||||
$this->semValue = $this->semStack[$this->stackPos-(3-2)];
|
$this->semValue = $this->semStack[$this->stackPos-(3-2)]; $attrs = $this->startAttributeStack[$this->stackPos-(3-1)]; $stmts = $this->semValue; if (!empty($attrs['comments']) && isset($stmts[0])) {$stmts[0]->setAttribute('comments', array_merge($attrs['comments'], $stmts[0]->getAttribute('comments', []))); };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function reduceRule128() {
|
protected function reduceRule128() {
|
||||||
|
23
test/code/parser/blockComments.test
Normal file
23
test/code/parser/blockComments.test
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Comments on blocks
|
||||||
|
-----
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// foo
|
||||||
|
{
|
||||||
|
// bar
|
||||||
|
{
|
||||||
|
// baz
|
||||||
|
$a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
-----
|
||||||
|
array(
|
||||||
|
0: Expr_Variable(
|
||||||
|
name: a
|
||||||
|
comments: array(
|
||||||
|
0: // foo
|
||||||
|
1: // bar
|
||||||
|
2: // baz
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user