php5 syntax

This commit is contained in:
z7zmey 2018-02-01 16:07:18 +02:00
parent 799cd1d5ce
commit c80f0b8fa0
3 changed files with 2318 additions and 2171 deletions

View File

@ -56,3 +56,11 @@ type simpleIndirectReference struct {
all []*expr.Variable all []*expr.Variable
last *expr.Variable last *expr.Variable
} }
const arrayFetchType = 0
const propertyFetchType = 1
type objectProperty struct {
node node.Node
fetchType int
}

File diff suppressed because it is too large Load Diff

View File

@ -25,8 +25,9 @@ import (
// boolWithToken boolWithToken // boolWithToken boolWithToken
list []node.Node list []node.Node
foreachVariable foreachVariable foreachVariable foreachVariable
// nodesWithEndToken *nodesWithEndToken nodesWithEndToken *nodesWithEndToken
simpleIndirectReference simpleIndirectReference simpleIndirectReference simpleIndirectReference
objectPropertyList []objectProperty
// str string // str string
} }
@ -199,7 +200,7 @@ import (
%type <node> base_variable array_function_dereference function_call inner_statement statement unticked_statement %type <node> base_variable array_function_dereference function_call inner_statement statement unticked_statement
%type <node> inner_statement statement global_var static_scalar scalar class_constant static_class_name_scalar class_name_scalar %type <node> inner_statement statement global_var static_scalar scalar class_constant static_class_name_scalar class_name_scalar
%type <node> encaps_var encaps_var encaps_var_offset general_constant isset_variable internal_functions_in_yacc assignment_list_element %type <node> encaps_var encaps_var encaps_var_offset general_constant isset_variable internal_functions_in_yacc assignment_list_element
%type <node> variable_name %type <node> variable_name variable_without_objects dynamic_class_name_reference new_expr class_name_reference
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations %type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list %type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
@ -207,6 +208,8 @@ import (
%type <simpleIndirectReference> simple_indirect_reference %type <simpleIndirectReference> simple_indirect_reference
%type <foreachVariable> foreach_variable %type <foreachVariable> foreach_variable
%type <objectPropertyList> object_property object_dim_list dynamic_class_name_variable_properties dynamic_class_name_variable_property
%type <nodesWithEndToken> ctor_arguments function_call_parameter_list
%% %%
@ -766,7 +769,8 @@ optional_class_type:
function_call_parameter_list: function_call_parameter_list:
'(' ')' { } '(' ')'
{ $$ = &nodesWithEndToken{[]node.Node{}, $2} }
| '(' non_empty_function_call_parameter_list ')' { } | '(' non_empty_function_call_parameter_list ')' { }
| '(' yield_expr ')' { } | '(' yield_expr ')' { }
; ;
@ -1041,7 +1045,18 @@ instance_call:
; ;
new_expr: new_expr:
T_NEW class_name_reference { } ctor_arguments { } T_NEW class_name_reference ctor_arguments
{
if $3 != nil {
$$ = expr.NewNew($2, $3.nodes)
positions.AddPosition($$, positionBuilder.NewTokensPosition($1, $3.endToken))
} else {
$$ = expr.NewNew($2, nil)
positions.AddPosition($$, positionBuilder.NewTokenNodePosition($1, $2))
}
comments.AddComments($$, $1.Comments())
}
; ;
expr_without_variable: expr_without_variable:
@ -1106,7 +1121,8 @@ expr_without_variable:
| expr T_IS_GREATER_OR_EQUAL expr { } | expr T_IS_GREATER_OR_EQUAL expr { }
| expr T_INSTANCEOF class_name_reference { } | expr T_INSTANCEOF class_name_reference { }
| parenthesis_expr { } | parenthesis_expr { }
| new_expr { } | new_expr
{ $$ = $1 }
| '(' new_expr ')' { } instance_call { } | '(' new_expr ')' { } instance_call { }
| expr '?' { } | expr '?' { }
expr ':' { } expr ':' { }
@ -1123,7 +1139,7 @@ expr_without_variable:
| T_UNSET_CAST expr { } | T_UNSET_CAST expr { }
| T_EXIT exit_expr { } | T_EXIT exit_expr { }
| '@' { } expr { } | '@' { } expr { }
| scalar { } | scalar { $$ = $1 }
| combined_scalar_offset { } | combined_scalar_offset { }
| combined_scalar { } | combined_scalar { }
| '`' backticks_expr '`' { } | '`' backticks_expr '`' { }
@ -1227,27 +1243,60 @@ fully_qualified_class_name:
class_name_reference: class_name_reference:
class_name { } class_name
| dynamic_class_name_reference { } { $$ = $1 }
| dynamic_class_name_reference
{ $$ = $1 }
; ;
dynamic_class_name_reference: dynamic_class_name_reference:
base_variable T_OBJECT_OPERATOR { } base_variable T_OBJECT_OPERATOR object_property dynamic_class_name_variable_properties
object_property { } dynamic_class_name_variable_properties {
{ } $$ = $1
| base_variable { }
for _, f := range($3) {
switch (f.fetchType) {
case arrayFetchType:
$$ = expr.NewArrayDimFetch($$, f.node)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, f.node))
comments.AddComments($$, comments[$1])
case propertyFetchType:
$$ = expr.NewPropertyFetch($$, f.node)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, f.node))
comments.AddComments($$, comments[$1])
}
}
for _, f := range($4) {
switch (f.fetchType) {
case arrayFetchType:
$$ = expr.NewArrayDimFetch($$, f.node)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, f.node))
comments.AddComments($$, comments[$1])
case propertyFetchType:
$$ = expr.NewPropertyFetch($$, f.node)
positions.AddPosition($$, positionBuilder.NewNodesPosition($1, f.node))
comments.AddComments($$, comments[$1])
}
}
}
| base_variable
{ $$ = $1 }
; ;
dynamic_class_name_variable_properties: dynamic_class_name_variable_properties:
dynamic_class_name_variable_properties dynamic_class_name_variable_property dynamic_class_name_variable_properties dynamic_class_name_variable_property
{ $$ = append($1, $2...) }
| /* empty */ | /* empty */
{ $$ = []objectProperty{} }
; ;
dynamic_class_name_variable_property: dynamic_class_name_variable_property:
T_OBJECT_OPERATOR object_property { } T_OBJECT_OPERATOR object_property
{ $$ = $2 }
; ;
exit_expr: exit_expr:
@ -1263,8 +1312,10 @@ backticks_expr:
; ;
ctor_arguments: ctor_arguments:
/* empty */ { } /* empty */
| function_call_parameter_list { } { $$ = nil }
| function_call_parameter_list
{ $$ = $1 }
; ;
common_scalar: common_scalar:
@ -1280,7 +1331,12 @@ common_scalar:
positions.AddPosition($$, positionBuilder.NewTokenPosition($1)) positions.AddPosition($$, positionBuilder.NewTokenPosition($1))
comments.AddComments($$, $1.Comments()) comments.AddComments($$, $1.Comments())
} }
| T_CONSTANT_ENCAPSED_STRING { $$ = nil } | T_CONSTANT_ENCAPSED_STRING
{
$$ = scalar.NewString($1.Value)
positions.AddPosition($$, positionBuilder.NewTokenPosition($1))
comments.AddComments($$, $1.Comments())
}
| T_LINE | T_LINE
{ {
$$ = scalar.NewMagicConstant($1.Value) $$ = scalar.NewMagicConstant($1.Value)
@ -1466,7 +1522,7 @@ non_empty_static_array_pair_list:
expr: expr:
r_variable { $$ = $1 } r_variable { $$ = $1 }
| expr_without_variable { } | expr_without_variable { $$ = $1 }
; ;
parenthesis_expr: parenthesis_expr:
@ -1618,14 +1674,31 @@ dim_offset:
object_property: object_property:
object_dim_list { } object_dim_list
| variable_without_objects { } { $$ = $1 }
| variable_without_objects
{
op := objectProperty{$1, propertyFetchType}
$$ = []objectProperty{op}
}
; ;
object_dim_list: object_dim_list:
object_dim_list '[' dim_offset ']' { } object_dim_list '[' dim_offset ']'
| object_dim_list '{' expr '}' { } {
| variable_name { } op := objectProperty{$3, arrayFetchType}
$$ = append($1, op)
}
| object_dim_list '{' expr '}'
{
op := objectProperty{$3, arrayFetchType}
$$ = append($1, op)
}
| variable_name
{
op := objectProperty{$1, propertyFetchType}
$$ = []objectProperty{op}
}
; ;
variable_name: variable_name: