fix node lists
This commit is contained in:
parent
24dfe3f734
commit
01f7e3fe63
@ -12,11 +12,10 @@ type Case struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
cond node.Node
|
||||
stmts node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
//TODO: stmts myst be []node.Node
|
||||
func NewCase(token token.Token, cond node.Node, stmts node.Node) node.Node {
|
||||
func NewCase(token token.Token, cond node.Node, stmts []node.Node) node.Node {
|
||||
return Case{
|
||||
node.SimpleNode{Name: "Case", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -27,8 +26,14 @@ func NewCase(token token.Token, cond node.Node, stmts node.Node) node.Node {
|
||||
|
||||
func (n Case) 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%vcond:", indent+" ")
|
||||
n.cond.Print(out, indent+" ")
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,10 @@ type Catch struct {
|
||||
token token.Token
|
||||
types []node.Node
|
||||
variable node.Node
|
||||
stmts node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
//TODO: stmts myst be []node.Node
|
||||
func NewCatch(token token.Token, types []node.Node, variable node.Node, stmts node.Node) node.Node {
|
||||
func NewCatch(token token.Token, types []node.Node, variable node.Node, stmts []node.Node) node.Node {
|
||||
return Catch{
|
||||
node.SimpleNode{Name: "Catch", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -38,6 +37,10 @@ func (n Catch) Print(out io.Writer, indent string) {
|
||||
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
|
||||
n.variable.Print(out, indent+" ")
|
||||
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,14 @@ type Class struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
modifiers []string
|
||||
args node.Node
|
||||
args []node.Node
|
||||
extends node.Node
|
||||
implements node.Node
|
||||
stmts node.Node
|
||||
implements []node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
//TODO: stmts myst be []node.Node
|
||||
func NewClass(token token.Token, modifiers []string, args node.Node, extends node.Node, implements node.Node, stmts node.Node) node.Node {
|
||||
func NewClass(token token.Token, modifiers []string, args []node.Node, extends node.Node, implements []node.Node, stmts []node.Node) node.Node {
|
||||
return Class{
|
||||
node.SimpleNode{Name: "Class", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -43,7 +43,9 @@ func (n Class) Print(out io.Writer, indent string) {
|
||||
|
||||
if n.args != nil {
|
||||
fmt.Fprintf(out, "\n%vargs:", indent+" ")
|
||||
n.args.Print(out, indent+" ")
|
||||
for _, nn := range n.args {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
if n.extends != nil {
|
||||
@ -53,9 +55,15 @@ func (n Class) Print(out io.Writer, indent string) {
|
||||
|
||||
if n.implements != nil {
|
||||
fmt.Fprintf(out, "\n%vimplements:", indent+" ")
|
||||
n.implements.Print(out, indent+" ")
|
||||
for _, nn := range n.implements {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ import (
|
||||
type Default struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
stmts node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
func NewDefault(token token.Token, stmts node.Node) node.Node {
|
||||
func NewDefault(token token.Token, stmts []node.Node) node.Node {
|
||||
return Default{
|
||||
node.SimpleNode{Name: "Default", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -24,6 +24,11 @@ func NewDefault(token token.Token, stmts node.Node) node.Node {
|
||||
|
||||
func (n Default) 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%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,10 @@ import (
|
||||
type Finally struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
stmts node.Node
|
||||
stmts []node.Node
|
||||
}
|
||||
|
||||
//TODO: stmts myst be []node.Node
|
||||
func NewFinally(token token.Token, stmts node.Node) node.Node {
|
||||
func NewFinally(token token.Token, stmts []node.Node) node.Node {
|
||||
return Finally{
|
||||
node.SimpleNode{Name: "Finally", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -26,6 +25,10 @@ func NewFinally(token token.Token, stmts node.Node) node.Node {
|
||||
func (n Finally) 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%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,12 @@ import (
|
||||
type Try struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
stmts node.Node
|
||||
stmts []node.Node
|
||||
catches []node.Node
|
||||
finally node.Node
|
||||
}
|
||||
|
||||
//TODO: stmts myst be []node.Node
|
||||
func NewTry(token token.Token, stmts node.Node, catches []node.Node, finally node.Node) node.Node {
|
||||
func NewTry(token token.Token, stmts []node.Node, catches []node.Node, finally node.Node) node.Node {
|
||||
return Try{
|
||||
node.SimpleNode{Name: "Try", Attributes: make(map[string]string)},
|
||||
token,
|
||||
@ -30,12 +29,18 @@ func NewTry(token token.Token, stmts node.Node, catches []node.Node, finally nod
|
||||
func (n Try) 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%vstmts:", indent+" ")
|
||||
n.stmts.Print(out, indent+" ")
|
||||
if n.stmts != nil {
|
||||
fmt.Fprintf(out, "\n%vstmts:", indent+" ")
|
||||
for _, nn := range n.stmts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "\n%vcatches:", indent+" ")
|
||||
for _, nn := range n.catches {
|
||||
nn.Print(out, indent+" ")
|
||||
if n.catches != nil {
|
||||
fmt.Fprintf(out, "\n%vcatches:", indent+" ")
|
||||
for _, nn := range n.catches {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
if n.finally != nil {
|
||||
|
@ -2934,7 +2934,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-6 : yypt+1]
|
||||
//line parser/parser.y:405
|
||||
{
|
||||
yyVAL.node = stmt.NewTry(yyDollar[1].token, yyDollar[3].node, yyDollar[5].list, yyDollar[6].node)
|
||||
yyVAL.node = stmt.NewTry(yyDollar[1].token, yyDollar[3].node.(node.SimpleNode).Children, yyDollar[5].list, yyDollar[6].node)
|
||||
}
|
||||
case 150:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
@ -2964,7 +2964,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-9 : yypt+1]
|
||||
//line parser/parser.y:415
|
||||
{
|
||||
yyVAL.list = append(yyDollar[1].list, stmt.NewCatch(yyDollar[2].token, yyDollar[4].list, expr.NewVariable(yyDollar[5].token), yyDollar[8].node))
|
||||
yyVAL.list = append(yyDollar[1].list, stmt.NewCatch(yyDollar[2].token, yyDollar[4].list, expr.NewVariable(yyDollar[5].token), yyDollar[8].node.(node.SimpleNode).Children))
|
||||
}
|
||||
case 155:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
@ -2988,7 +2988,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line parser/parser.y:424
|
||||
{
|
||||
yyVAL.node = stmt.NewFinally(yyDollar[1].token, yyDollar[3].node)
|
||||
yyVAL.node = stmt.NewFinally(yyDollar[1].token, yyDollar[3].node.(node.SimpleNode).Children)
|
||||
}
|
||||
case 159:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
@ -3047,13 +3047,13 @@ yydefault:
|
||||
yyDollar = yyS[yypt-8 : yypt+1]
|
||||
//line parser/parser.y:460
|
||||
{
|
||||
yyVAL.node = stmt.NewClass(yyDollar[3].token, yyDollar[1].strings, nil, yyDollar[4].node, yyDollar[5].node, yyDollar[7].node)
|
||||
yyVAL.node = stmt.NewClass(yyDollar[3].token, yyDollar[1].strings, nil, yyDollar[4].node, yyDollar[5].node.(node.SimpleNode).Children, yyDollar[7].node.(node.SimpleNode).Children)
|
||||
}
|
||||
case 168:
|
||||
yyDollar = yyS[yypt-7 : yypt+1]
|
||||
//line parser/parser.y:462
|
||||
{
|
||||
yyVAL.node = stmt.NewClass(yyDollar[2].token, nil, nil, yyDollar[3].node, yyDollar[4].node, yyDollar[6].node)
|
||||
yyVAL.node = stmt.NewClass(yyDollar[2].token, nil, nil, yyDollar[3].node, yyDollar[4].node.(node.SimpleNode).Children, yyDollar[6].node.(node.SimpleNode).Children)
|
||||
}
|
||||
case 169:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
@ -3224,13 +3224,13 @@ yydefault:
|
||||
yyDollar = yyS[yypt-5 : yypt+1]
|
||||
//line parser/parser.y:536
|
||||
{
|
||||
yyVAL.node = yyDollar[1].node.Append(stmt.NewCase(yyDollar[2].token, yyDollar[3].node, yyDollar[5].node))
|
||||
yyVAL.node = yyDollar[1].node.Append(stmt.NewCase(yyDollar[2].token, yyDollar[3].node, yyDollar[5].node.(node.SimpleNode).Children))
|
||||
}
|
||||
case 197:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line parser/parser.y:540
|
||||
{
|
||||
yyVAL.node = yyDollar[1].node.Append(stmt.NewDefault(yyDollar[2].token, yyDollar[4].node))
|
||||
yyVAL.node = yyDollar[1].node.Append(stmt.NewDefault(yyDollar[2].token, yyDollar[4].node.(node.SimpleNode).Children))
|
||||
}
|
||||
case 200:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
@ -3793,7 +3793,7 @@ yydefault:
|
||||
//line parser/parser.y:816
|
||||
{
|
||||
{
|
||||
yyVAL.node = stmt.NewClass(yyDollar[1].token, nil, yyDollar[2].node, yyDollar[3].node, yyDollar[4].node, yyDollar[6].node)
|
||||
yyVAL.node = stmt.NewClass(yyDollar[1].token, nil, yyDollar[2].node.(node.SimpleNode).Children, yyDollar[3].node, yyDollar[4].node.(node.SimpleNode).Children, yyDollar[6].node.(node.SimpleNode).Children)
|
||||
}
|
||||
}
|
||||
case 291:
|
||||
|
@ -403,7 +403,7 @@ statement:
|
||||
| ';' /* empty statement */ { $$ = node.NewSimpleNode(""); }
|
||||
| T_TRY '{' inner_statement_list '}' catch_list finally_statement
|
||||
{
|
||||
$$ = stmt.NewTry($1, $3, $5, $6)
|
||||
$$ = stmt.NewTry($1, $3.(node.SimpleNode).Children, $5, $6)
|
||||
}
|
||||
| T_THROW expr ';' { $$ = node.NewSimpleNode("Throw").Append($2) }
|
||||
| T_GOTO T_STRING ';' { $$ = node.NewSimpleNode("GoTo").Attribute("Label", $2.String()) }
|
||||
@ -412,7 +412,7 @@ statement:
|
||||
catch_list:
|
||||
/* empty */ { $$ = []node.Node{} }
|
||||
| catch_list T_CATCH '(' catch_name_list T_VARIABLE ')' '{' inner_statement_list '}'
|
||||
{ $$ = append($1, stmt.NewCatch($2, $4, expr.NewVariable($5), $8)) }
|
||||
{ $$ = append($1, stmt.NewCatch($2, $4, expr.NewVariable($5), $8.(node.SimpleNode).Children)) }
|
||||
;
|
||||
catch_name_list:
|
||||
name { $$ = []node.Node{$1} }
|
||||
@ -421,7 +421,7 @@ catch_name_list:
|
||||
|
||||
finally_statement:
|
||||
/* empty */ { $$ = nil }
|
||||
| T_FINALLY '{' inner_statement_list '}' { $$ = stmt.NewFinally($1, $3) }
|
||||
| T_FINALLY '{' inner_statement_list '}' { $$ = stmt.NewFinally($1, $3.(node.SimpleNode).Children) }
|
||||
;
|
||||
|
||||
unset_variables:
|
||||
@ -457,9 +457,9 @@ is_variadic:
|
||||
|
||||
class_declaration_statement:
|
||||
class_modifiers T_CLASS T_STRING extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = stmt.NewClass($3, $1, nil, $4, $5, $7) }
|
||||
{ $$ = stmt.NewClass($3, $1, nil, $4, $5.(node.SimpleNode).Children, $7.(node.SimpleNode).Children) }
|
||||
| T_CLASS T_STRING extends_from implements_list '{' class_statement_list '}'
|
||||
{ $$ = stmt.NewClass($2, nil, nil, $3, $4, $6) }
|
||||
{ $$ = stmt.NewClass($2, nil, nil, $3, $4.(node.SimpleNode).Children, $6.(node.SimpleNode).Children) }
|
||||
;
|
||||
|
||||
class_modifiers:
|
||||
@ -534,11 +534,11 @@ case_list:
|
||||
/* empty */ { $$ = node.NewSimpleNode("CaseList") }
|
||||
| case_list T_CASE expr case_separator inner_statement_list
|
||||
{
|
||||
$$ = $1.Append(stmt.NewCase($2, $3, $5))
|
||||
$$ = $1.Append(stmt.NewCase($2, $3, $5.(node.SimpleNode).Children))
|
||||
}
|
||||
| case_list T_DEFAULT case_separator inner_statement_list
|
||||
{
|
||||
$$ = $1.Append(stmt.NewDefault($2, $4))
|
||||
$$ = $1.Append(stmt.NewDefault($2, $4.(node.SimpleNode).Children))
|
||||
}
|
||||
;
|
||||
|
||||
@ -814,7 +814,7 @@ non_empty_for_exprs:
|
||||
anonymous_class:
|
||||
T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
|
||||
{
|
||||
{ $$ = stmt.NewClass($1, nil, $2, $3, $4, $6) }
|
||||
{ $$ = stmt.NewClass($1, nil, $2.(node.SimpleNode).Children, $3, $4.(node.SimpleNode).Children, $6.(node.SimpleNode).Children) }
|
||||
}
|
||||
;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user