break node

This commit is contained in:
vadim 2017-12-06 13:31:57 +02:00
parent f9e21be04b
commit 88fb95a784
3 changed files with 517 additions and 486 deletions

29
node/stmt/break.go Normal file
View File

@ -0,0 +1,29 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Break struct {
node.SimpleNode
token token.Token
expr node.Node
}
func NewBreak(token token.Token, expr node.Node) node.Node {
return Break{
node.SimpleNode{Name: "Break", Attributes: make(map[string]string)},
token,
expr,
}
}
func (n Break) 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)
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
n.expr.Print(out, indent+" ")
}

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/stmt"
)
var rootnode = node.NewSimpleNode("Root")
@ -370,7 +371,7 @@ statement:
Append(node.NewSimpleNode("stmt").Append($9))
}
| T_SWITCH '(' expr ')' switch_case_list { $$ = node.NewSimpleNode("Switch").Append(node.NewSimpleNode("expr").Append($3)).Append($5); }
| T_BREAK optional_expr ';' { $$ = node.NewSimpleNode("Break").Append($2) }
| T_BREAK optional_expr ';' { $$ = stmt.NewBreak($1, $2) }
| T_CONTINUE optional_expr ';' { $$ = node.NewSimpleNode("Continue").Append($2) }
| T_RETURN optional_expr ';' { $$ = node.NewSimpleNode("Return").Append($2) }
| T_GLOBAL global_var_list ';' { $$ = $2; }