use_list node

This commit is contained in:
vadim 2017-12-09 13:50:01 +02:00
parent b424e82812
commit ddf72d4b4f
4 changed files with 622 additions and 580 deletions

View File

@ -33,7 +33,7 @@ func (n Use) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name) fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.useType != nil { if n.useType != nil {
fmt.Fprintf(out, "\n%vtype: %q", indent+" ", n.alias.GetValue()) fmt.Fprintf(out, "\n%vtype:", indent+" ")
n.useType.Print(out, indent+" ") n.useType.Print(out, indent+" ")
} }

41
node/stmt/use_list.go Normal file
View File

@ -0,0 +1,41 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type UseList struct {
node.SimpleNode
token token.Token
useType node.Node
uses []node.Node
}
func NewUseList(token token.Token, useType node.Node, uses []node.Node) node.Node {
return UseList{
node.SimpleNode{Name: "UseList", Attributes: make(map[string]string)},
token,
useType,
uses,
}
}
func (n UseList) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
if n.useType != nil {
fmt.Fprintf(out, "\n%vtype:", indent+" ")
n.useType.Print(out, indent+" ")
}
if n.uses != nil {
fmt.Fprintf(out, "\n%vuses:", indent+" ")
for _, nn := range n.uses {
nn.Print(out, indent+" ")
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -199,7 +199,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <node> variable_class_name dereferencable_scalar constant dereferencable %type <node> variable_class_name dereferencable_scalar constant dereferencable
%type <node> callable_expr callable_variable static_member new_variable %type <node> callable_expr callable_variable static_member new_variable
%type <node> encaps_var encaps_var_offset isset_variables %type <node> encaps_var encaps_var_offset isset_variables
%type <node> top_statement_list use_declarations inner_statement_list if_stmt %type <node> top_statement_list inner_statement_list if_stmt
%type <node> alt_if_stmt %type <node> alt_if_stmt
%type <node> parameter_list class_statement_list %type <node> parameter_list class_statement_list
%type <node> implements_list if_stmt_without_else %type <node> implements_list if_stmt_without_else
@ -219,6 +219,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list %type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list
%type <list> unprefixed_use_declarations inline_use_declarations property_list static_var_list %type <list> unprefixed_use_declarations inline_use_declarations property_list static_var_list
%type <list> switch_case_list case_list trait_adaptation_list trait_adaptations unset_variables %type <list> switch_case_list case_list trait_adaptation_list trait_adaptations unset_variables
%type <list> use_declarations
%% %%
@ -277,8 +278,8 @@ top_statement:
| T_NAMESPACE '{' top_statement_list '}' { $$ = stmt.NewNamespace($1, nil, $3.(node.SimpleNode).Children) } | T_NAMESPACE '{' top_statement_list '}' { $$ = stmt.NewNamespace($1, nil, $3.(node.SimpleNode).Children) }
| T_USE mixed_group_use_declaration ';' { $$ = $2.(stmt.GroupUse).SetToken($1) } | T_USE mixed_group_use_declaration ';' { $$ = $2.(stmt.GroupUse).SetToken($1) }
| T_USE use_type group_use_declaration ';' { $$ = $3.(stmt.GroupUse).SetToken($1).(stmt.GroupUse).SetUseType($2) } | T_USE use_type group_use_declaration ';' { $$ = $3.(stmt.GroupUse).SetToken($1).(stmt.GroupUse).SetUseType($2) }
| T_USE use_declarations ';' { $$ = $2; } | T_USE use_declarations ';' { $$ = stmt.NewUseList($1, nil, $2) }
| T_USE use_type use_declarations ';' { $$ = $3.Append($2) } | T_USE use_type use_declarations ';' { $$ = stmt.NewUseList($1, $2, $3) }
| T_CONST const_list ';' { $$ = stmt.NewStmtConst($1, $2) } | T_CONST const_list ';' { $$ = stmt.NewStmtConst($1, $2) }
; ;
@ -329,8 +330,8 @@ unprefixed_use_declarations:
; ;
use_declarations: use_declarations:
use_declarations ',' use_declaration { $$ = $1.Append($3) } use_declarations ',' use_declaration { $$ = append($1, $3) }
| use_declaration { $$ = node.NewSimpleNode("UseList").Append($1) } | use_declaration { $$ = []node.Node{$1} }
; ;
inline_use_declaration: inline_use_declaration: