label node

This commit is contained in:
vadim 2017-12-08 12:01:52 +02:00
parent c25748d7db
commit 92688ac8d2
3 changed files with 27 additions and 2 deletions

25
node/stmt/label.go Normal file
View File

@ -0,0 +1,25 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Label struct {
node.SimpleNode
token token.Token
}
func NewLabel(token token.Token) node.Node {
return Label{
node.SimpleNode{Name: "Label", Attributes: make(map[string]string)},
token,
}
}
func (n Label) 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)
}

View File

@ -2939,7 +2939,7 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:403 //line parser/parser.y:403
{ {
yyVAL.node = node.NewSimpleNode("Label").Attribute("name", yyDollar[1].token.String()) yyVAL.node = stmt.NewLabel(yyDollar[1].token)
} }
case 153: case 153:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]

View File

@ -400,7 +400,7 @@ statement:
} }
| T_THROW expr ';' { $$ = node.NewSimpleNode("Throw").Append($2) } | T_THROW expr ';' { $$ = node.NewSimpleNode("Throw").Append($2) }
| T_GOTO T_STRING ';' { $$ = stmt.NewGoto($1, $2) } | T_GOTO T_STRING ';' { $$ = stmt.NewGoto($1, $2) }
| T_STRING ':' { $$ = node.NewSimpleNode("Label").Attribute("name", $1.String()) } | T_STRING ':' { $$ = stmt.NewLabel($1) }
catch_list: catch_list:
/* empty */ { $$ = []node.Node{} } /* empty */ { $$ = []node.Node{} }