mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Error recovery for functions without body
This commit is contained in:
parent
01e85a26c6
commit
7b201b63d2
@ -6,6 +6,7 @@ Version 4.0.2-dev
|
||||
* Improved error recovery inside classes.
|
||||
* Support error recovery for `foreach` without `as`.
|
||||
* Support error recovery for parameters without variable (`function (Type ) {}`).
|
||||
* Support error recovery for functions without body (`function ($foo)`).
|
||||
|
||||
Version 4.0.1 (2018-03-25)
|
||||
--------------------------
|
||||
|
@ -297,9 +297,14 @@ optional_ellipsis:
|
||||
| T_ELLIPSIS { $$ = true; }
|
||||
;
|
||||
|
||||
block_or_error:
|
||||
'{' inner_statement_list '}' { $$ = $2; }
|
||||
| error { $$ = []; }
|
||||
;
|
||||
|
||||
function_declaration_statement:
|
||||
T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
|
||||
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
|
||||
T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type block_or_error
|
||||
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $8]]; }
|
||||
;
|
||||
|
||||
class_declaration_statement:
|
||||
@ -567,7 +572,7 @@ trait_method_reference:
|
||||
|
||||
method_body:
|
||||
';' /* abstract method */ { $$ = null; }
|
||||
| '{' inner_statement_list '}' { $$ = $2; }
|
||||
| block_or_error { $$ = $1; }
|
||||
;
|
||||
|
||||
variable_modifiers:
|
||||
@ -713,11 +718,11 @@ expr:
|
||||
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr\Yield_[$4, $2]; }
|
||||
| T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; }
|
||||
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
|
||||
'{' inner_statement_list '}'
|
||||
{ $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
|
||||
block_or_error
|
||||
{ $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $8]]; }
|
||||
| T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
|
||||
'{' inner_statement_list '}'
|
||||
{ $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
|
||||
block_or_error
|
||||
{ $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9]]; }
|
||||
;
|
||||
|
||||
anonymous_class:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1048,12 +1048,23 @@ function foo(...) {
|
||||
function foo(&) {
|
||||
$qux;
|
||||
}
|
||||
|
||||
function foo(Bar)
|
||||
|
||||
class Bar {
|
||||
function foo(Baz)
|
||||
}
|
||||
|
||||
function(Foo);
|
||||
-----
|
||||
!!php7
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 3:18 to 3:18
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 7:31 to 7:31
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 11:17 to 11:17
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 15:15 to 15:15
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 19:17 to 19:17
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 22:21 to 22:21
|
||||
Syntax error, unexpected ')', expecting T_VARIABLE from 25:13 to 25:13
|
||||
array(
|
||||
0: Stmt_Function(
|
||||
byRef: false
|
||||
@ -1172,4 +1183,87 @@ array(
|
||||
)
|
||||
)
|
||||
)
|
||||
4: Stmt_Function(
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: foo
|
||||
)
|
||||
params: array(
|
||||
0: Param(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: Bar
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
var: Expr_Error(
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
returnType: null
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
5: Stmt_Class(
|
||||
flags: 0
|
||||
name: Identifier(
|
||||
name: Bar
|
||||
)
|
||||
extends: null
|
||||
implements: array(
|
||||
)
|
||||
stmts: array(
|
||||
0: Stmt_ClassMethod(
|
||||
flags: 0
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: foo
|
||||
)
|
||||
params: array(
|
||||
0: Param(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: Baz
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
var: Expr_Error(
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
returnType: null
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
6: Stmt_Expression(
|
||||
expr: Expr_Closure(
|
||||
static: false
|
||||
byRef: false
|
||||
params: array(
|
||||
0: Param(
|
||||
type: Name(
|
||||
parts: array(
|
||||
0: Foo
|
||||
)
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
var: Expr_Error(
|
||||
)
|
||||
default: null
|
||||
)
|
||||
)
|
||||
uses: array(
|
||||
)
|
||||
returnType: null
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user