stmt_list node
This commit is contained in:
parent
bb188f0637
commit
25b8add282
36
node/stmt/stmt_list.go
Normal file
36
node/stmt/stmt_list.go
Normal 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+" ")
|
||||
}
|
||||
}
|
||||
}
|
2253
parser/parser.go
2253
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -168,6 +168,8 @@ func Parse(src io.Reader, fName string) node.Node {
|
||||
%token <token> T_PUBLIC
|
||||
%token <token> '"'
|
||||
%token <token> '`'
|
||||
%token <token> '{'
|
||||
%token <token> '}'
|
||||
|
||||
%type <value> is_reference
|
||||
%type <value> is_variadic
|
||||
@ -351,7 +353,7 @@ inner_statement:
|
||||
| T_HALT_COMPILER '(' ')' ';' { $$ = node.NewSimpleNode("THaltCompiler") }
|
||||
|
||||
statement:
|
||||
'{' inner_statement_list '}' { $$ = $2; }
|
||||
'{' inner_statement_list '}' { $$ = stmt.NewStmtList($1, $3, $2.(node.SimpleNode).Children) }
|
||||
| if_stmt { $$ = $1; }
|
||||
| alt_if_stmt { $$ = $1; }
|
||||
| T_WHILE '(' expr ')' while_statement
|
||||
|
Loading…
Reference in New Issue
Block a user