goto node

This commit is contained in:
vadim 2017-12-07 18:51:40 +02:00
parent 9e73d2b162
commit d266fce399
3 changed files with 29 additions and 2 deletions

27
node/stmt/goto.go Normal file
View File

@ -0,0 +1,27 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Goto struct {
node.SimpleNode
token token.Token
name token.Token
}
func NewGoto(token token.Token, name token.Token) node.Node {
return Goto{
node.SimpleNode{Name: "Goto", Attributes: make(map[string]string)},
token,
name,
}
}
func (n Goto) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.name.EndLine, n.name.Value)
}

View File

@ -2930,7 +2930,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:390 //line parser/parser.y:390
{ {
yyVAL.node = node.NewSimpleNode("GoTo").Attribute("Label", yyDollar[2].token.String()) yyVAL.node = stmt.NewGoto(yyDollar[1].token, yyDollar[2].token)
} }
case 152: case 152:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]

View File

@ -387,7 +387,7 @@ statement:
$$ = stmt.NewTry($1, $3.(node.SimpleNode).Children, $5, $6) $$ = stmt.NewTry($1, $3.(node.SimpleNode).Children, $5, $6)
} }
| T_THROW expr ';' { $$ = node.NewSimpleNode("Throw").Append($2) } | T_THROW expr ';' { $$ = node.NewSimpleNode("Throw").Append($2) }
| T_GOTO T_STRING ';' { $$ = node.NewSimpleNode("GoTo").Attribute("Label", $2.String()) } | T_GOTO T_STRING ';' { $$ = stmt.NewGoto($1, $2) }
| T_STRING ':' { $$ = node.NewSimpleNode("Label").Attribute("name", $1.String()) } | T_STRING ':' { $$ = node.NewSimpleNode("Label").Attribute("name", $1.String()) }
catch_list: catch_list: