namespace node

This commit is contained in:
vadim 2017-12-08 12:16:04 +02:00
parent 92688ac8d2
commit 32b05a653b
3 changed files with 47 additions and 6 deletions

41
node/stmt/namespace.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 Namespace struct {
node.SimpleNode
token token.Token
name node.Node
stmts []node.Node
}
func NewNamespace(token token.Token, name node.Node, stmts []node.Node) node.Node {
return Namespace{
node.SimpleNode{Name: "Namespace", Attributes: make(map[string]string)},
token,
name,
stmts,
}
}
func (n Namespace) 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.name != nil {
fmt.Fprintf(out, "\n%vname:", indent+" ")
n.name.Print(out, indent+" ")
}
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
}
}

View File

@ -2581,19 +2581,19 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:272
{
yyVAL.node = node.NewSimpleNode("Namespace").Append(name.NewName(yyDollar[2].list))
yyVAL.node = stmt.NewNamespace(yyDollar[1].token, name.NewName(yyDollar[2].list), nil)
}
case 92:
yyDollar = yyS[yypt-5 : yypt+1]
//line parser/parser.y:274
{
yyVAL.node = node.NewSimpleNode("Namespace").Append(name.NewName(yyDollar[2].list)).Append(yyDollar[4].node)
yyVAL.node = stmt.NewNamespace(yyDollar[1].token, name.NewName(yyDollar[2].list), yyDollar[4].node.(node.SimpleNode).Children)
}
case 93:
yyDollar = yyS[yypt-4 : yypt+1]
//line parser/parser.y:275
{
yyVAL.node = node.NewSimpleNode("Namespace").Append(yyDollar[3].node)
yyVAL.node = stmt.NewNamespace(yyDollar[1].token, nil, yyDollar[3].node.(node.SimpleNode).Children)
}
case 94:
yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -269,10 +269,10 @@ top_statement:
| trait_declaration_statement { $$ = $1; }
| interface_declaration_statement { $$ = $1; }
| T_HALT_COMPILER '(' ')' ';' { $$ = stmt.NewHaltCompiler($1) }
| T_NAMESPACE namespace_name ';' { $$ = node.NewSimpleNode("Namespace").Append(name.NewName($2)); }
| T_NAMESPACE namespace_name ';' { $$ = stmt.NewNamespace($1, name.NewName($2), nil) }
| T_NAMESPACE namespace_name '{' top_statement_list '}'
{ $$ = node.NewSimpleNode("Namespace").Append(name.NewName($2)).Append($4) }
| T_NAMESPACE '{' top_statement_list '}' { $$ = node.NewSimpleNode("Namespace").Append($3) }
{ $$ = stmt.NewNamespace($1, name.NewName($2), $4.(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 use_type group_use_declaration ';' { $$ = $3.(stmt.GroupUse).SetToken($1).(stmt.GroupUse).SetUseType($2) }
| T_USE use_declarations ';' { $$ = $2; }