post_inc post_dec pre_inc pre_dec nodes

This commit is contained in:
z7zmey 2017-12-18 18:59:17 +02:00
parent 85f7765e79
commit b5dc115ff1
6 changed files with 124 additions and 8 deletions

29
node/expr/post_dec.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type PostDec struct {
node.SimpleNode
variable node.Node
}
func NewPostDec(variableession node.Node) node.Node {
return PostDec{
node.SimpleNode{Name: "PostDec", Attributes: make(map[string]string)},
variableession,
}
}
func (n PostDec) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
}

29
node/expr/post_inc.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type PostInc struct {
node.SimpleNode
variable node.Node
}
func NewPostInc(variableession node.Node) node.Node {
return PostInc{
node.SimpleNode{Name: "PostInc", Attributes: make(map[string]string)},
variableession,
}
}
func (n PostInc) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
}

29
node/expr/pre_dec.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type PreDec struct {
node.SimpleNode
variable node.Node
}
func NewPreDec(variableession node.Node) node.Node {
return PreDec{
node.SimpleNode{Name: "PreDec", Attributes: make(map[string]string)},
variableession,
}
}
func (n PreDec) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
}

29
node/expr/pre_inc.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type PreInc struct {
node.SimpleNode
variable node.Node
}
func NewPreInc(variableession node.Node) node.Node {
return PreInc{
node.SimpleNode{Name: "PreInc", Attributes: make(map[string]string)},
variableession,
}
}
func (n PreInc) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
}

View File

@ -3903,25 +3903,25 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:841 //line parser/parser.y:841
{ {
yyVAL.node = node.NewSimpleNode("PostIncrement").Append(yyDollar[1].node) yyVAL.node = expr.NewPostInc(yyDollar[1].node)
} }
case 311: case 311:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:842 //line parser/parser.y:842
{ {
yyVAL.node = node.NewSimpleNode("PreIncrement").Append(yyDollar[2].node) yyVAL.node = expr.NewPreInc(yyDollar[2].node)
} }
case 312: case 312:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:843 //line parser/parser.y:843
{ {
yyVAL.node = node.NewSimpleNode("PostDecrement").Append(yyDollar[1].node) yyVAL.node = expr.NewPostDec(yyDollar[1].node)
} }
case 313: case 313:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:844 //line parser/parser.y:844
{ {
yyVAL.node = node.NewSimpleNode("PreDecrement").Append(yyDollar[2].node) yyVAL.node = expr.NewPreDec(yyDollar[2].node)
} }
case 314: case 314:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -838,10 +838,10 @@ expr_without_variable:
| variable T_XOR_EQUAL expr { $$ = assign_op.NewBitwiseXor($1, $3) } | variable T_XOR_EQUAL expr { $$ = assign_op.NewBitwiseXor($1, $3) }
| variable T_SL_EQUAL expr { $$ = assign_op.NewShiftLeft($1, $3) } | variable T_SL_EQUAL expr { $$ = assign_op.NewShiftLeft($1, $3) }
| variable T_SR_EQUAL expr { $$ = assign_op.NewShiftRight($1, $3) } | variable T_SR_EQUAL expr { $$ = assign_op.NewShiftRight($1, $3) }
| variable T_INC { $$ = node.NewSimpleNode("PostIncrement").Append($1) } | variable T_INC { $$ = expr.NewPostInc($1) }
| T_INC variable { $$ = node.NewSimpleNode("PreIncrement").Append($2) } | T_INC variable { $$ = expr.NewPreInc($2) }
| variable T_DEC { $$ = node.NewSimpleNode("PostDecrement").Append($1) } | variable T_DEC { $$ = expr.NewPostDec($1) }
| T_DEC variable { $$ = node.NewSimpleNode("PreDecrement").Append($2) } | T_DEC variable { $$ = expr.NewPreDec($2) }
| expr T_BOOLEAN_OR expr { $$ = binary_op.NewBooleanOr($1, $3) } | expr T_BOOLEAN_OR expr { $$ = binary_op.NewBooleanOr($1, $3) }
| expr T_BOOLEAN_AND expr { $$ = binary_op.NewBooleanAnd($1, $3) } | expr T_BOOLEAN_AND expr { $$ = binary_op.NewBooleanAnd($1, $3) }
| expr T_LOGICAL_OR expr { $$ = binary_op.NewLogicalOr($1, $3) } | expr T_LOGICAL_OR expr { $$ = binary_op.NewLogicalOr($1, $3) }