continue node

This commit is contained in:
z7zmey 2017-12-06 22:55:08 +02:00
parent ea2494b9b8
commit c8487b5847
3 changed files with 34 additions and 2 deletions

32
node/stmt/continue.go Normal file
View File

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

View File

@ -2855,7 +2855,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:379 //line parser/parser.y:379
{ {
yyVAL.node = node.NewSimpleNode("Continue").Append(yyDollar[2].node) yyVAL.node = stmt.NewContinue(yyDollar[1].token, yyDollar[2].node)
} }
case 138: case 138:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -376,7 +376,7 @@ statement:
} }
| 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 ';' { $$ = stmt.NewBreak($1, $2) } | T_BREAK optional_expr ';' { $$ = stmt.NewBreak($1, $2) }
| T_CONTINUE optional_expr ';' { $$ = node.NewSimpleNode("Continue").Append($2) } | T_CONTINUE optional_expr ';' { $$ = stmt.NewContinue($1, $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; }
| T_STATIC static_var_list ';' { $$ = $2; } | T_STATIC static_var_list ';' { $$ = $2; }