variable node, allow nil finally
This commit is contained in:
parent
c744a6c170
commit
2d168cd2e2
25
node/expr/variable.go
Normal file
25
node/expr/variable.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
"github.com/z7zmey/php-parser/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Variable struct {
|
||||||
|
node.SimpleNode
|
||||||
|
token token.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVariable(token token.Token) node.Node {
|
||||||
|
return Variable{
|
||||||
|
node.SimpleNode{Name: "Variable", Attributes: make(map[string]string)},
|
||||||
|
token,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n Variable) 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)
|
||||||
|
}
|
@ -38,6 +38,8 @@ func (n Try) Print(out io.Writer, indent string) {
|
|||||||
nn.Print(out, indent+" ")
|
nn.Print(out, indent+" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if n.finally != nil {
|
||||||
fmt.Fprintf(out, "\n%vfinally:", indent+" ")
|
fmt.Fprintf(out, "\n%vfinally:", indent+" ")
|
||||||
n.finally.Print(out, indent+" ")
|
n.finally.Print(out, indent+" ")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
973
parser/parser.go
973
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@ import (
|
|||||||
"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"
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
|
"github.com/z7zmey/php-parser/node/expr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootnode = node.NewSimpleNode("Root")
|
var rootnode = node.NewSimpleNode("Root")
|
||||||
@ -409,7 +410,7 @@ statement:
|
|||||||
catch_list:
|
catch_list:
|
||||||
/* empty */ { $$ = []node.Node{} }
|
/* empty */ { $$ = []node.Node{} }
|
||||||
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
|
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
|
||||||
{ $$ = append($1, stmt.NewCatch($2, $4, node.NewSimpleNode("TODO: handle variable"), $8)) }
|
{ $$ = append($1, stmt.NewCatch($2, $4, expr.NewVariable($5), $8)) }
|
||||||
;
|
;
|
||||||
catch_name_list:
|
catch_name_list:
|
||||||
name { $$ = []node.Node{$1} }
|
name { $$ = []node.Node{$1} }
|
||||||
@ -417,7 +418,7 @@ catch_name_list:
|
|||||||
;
|
;
|
||||||
|
|
||||||
finally_statement:
|
finally_statement:
|
||||||
/* empty */ { $$ = node.NewSimpleNode(""); }
|
/* empty */ { $$ = nil }
|
||||||
| T_FINALLY '{' inner_statement_list '}' { $$ = stmt.NewFinally($1, $3) }
|
| T_FINALLY '{' inner_statement_list '}' { $$ = stmt.NewFinally($1, $3) }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user