break node
This commit is contained in:
parent
f9e21be04b
commit
88fb95a784
29
node/stmt/break.go
Normal file
29
node/stmt/break.go
Normal 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+" ")
|
||||||
|
}
|
971
parser/parser.go
971
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
"github.com/z7zmey/php-parser/node/scalar"
|
"github.com/z7zmey/php-parser/node/scalar"
|
||||||
"github.com/z7zmey/php-parser/node/name"
|
"github.com/z7zmey/php-parser/node/name"
|
||||||
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootnode = node.NewSimpleNode("Root")
|
var rootnode = node.NewSimpleNode("Root")
|
||||||
@ -370,7 +371,7 @@ statement:
|
|||||||
Append(node.NewSimpleNode("stmt").Append($9))
|
Append(node.NewSimpleNode("stmt").Append($9))
|
||||||
}
|
}
|
||||||
| T_SWITCH '(' expr ')' switch_case_list { $$ = node.NewSimpleNode("Switch").Append(node.NewSimpleNode("expr").Append($3)).Append($5); }
|
| 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_CONTINUE optional_expr ';' { $$ = node.NewSimpleNode("Continue").Append($2) }
|
||||||
| T_RETURN optional_expr ';' { $$ = node.NewSimpleNode("Return").Append($2) }
|
| T_RETURN optional_expr ';' { $$ = node.NewSimpleNode("Return").Append($2) }
|
||||||
| T_GLOBAL global_var_list ';' { $$ = $2; }
|
| T_GLOBAL global_var_list ';' { $$ = $2; }
|
||||||
|
Loading…
Reference in New Issue
Block a user