stmt_list node

This commit is contained in:
vadim 2017-12-07 11:46:25 +02:00
parent bb188f0637
commit 25b8add282
3 changed files with 1164 additions and 1129 deletions

36
node/stmt/stmt_list.go Normal file
View File

@ -0,0 +1,36 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type StmtList struct {
node.SimpleNode
openBracket token.Token
closeBracket token.Token
stmts []node.Node
}
func NewStmtList(openBracket token.Token, closeBracket token.Token, stmts []node.Node) node.Node {
return StmtList{
node.SimpleNode{Name: "StmtList", Attributes: make(map[string]string)},
openBracket,
closeBracket,
stmts,
}
}
func (n StmtList) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [%d %d]", indent, n.Name, n.openBracket.StartLine, n.closeBracket.EndLine)
if n.stmts != nil {
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
for _, nn := range n.stmts {
nn.Print(out, indent+" ")
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -168,6 +168,8 @@ func Parse(src io.Reader, fName string) node.Node {
%token <token> T_PUBLIC %token <token> T_PUBLIC
%token <token> '"' %token <token> '"'
%token <token> '`' %token <token> '`'
%token <token> '{'
%token <token> '}'
%type <value> is_reference %type <value> is_reference
%type <value> is_variadic %type <value> is_variadic
@ -351,7 +353,7 @@ inner_statement:
| T_HALT_COMPILER '(' ')' ';' { $$ = node.NewSimpleNode("THaltCompiler") } | T_HALT_COMPILER '(' ')' ';' { $$ = node.NewSimpleNode("THaltCompiler") }
statement: statement:
'{' inner_statement_list '}' { $$ = $2; } '{' inner_statement_list '}' { $$ = stmt.NewStmtList($1, $3, $2.(node.SimpleNode).Children) }
| if_stmt { $$ = $1; } | if_stmt { $$ = $1; }
| alt_if_stmt { $$ = $1; } | alt_if_stmt { $$ = $1; }
| T_WHILE '(' expr ')' while_statement | T_WHILE '(' expr ')' while_statement