unset node

This commit is contained in:
vadim 2017-12-09 13:18:38 +02:00
parent 1efa7ff5ee
commit e224a582fa
3 changed files with 131 additions and 97 deletions

34
node/stmt/unset.go Normal file
View File

@ -0,0 +1,34 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type Unset struct {
node.SimpleNode
token token.Token
vars []node.Node
}
func NewUnset(token token.Token, vars []node.Node) node.Node {
return Unset{
node.SimpleNode{Name: "Unset", Attributes: make(map[string]string)},
token,
vars,
}
}
func (n Unset) 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)
if n.vars != nil {
fmt.Fprintf(out, "\n%vvars:", indent+" ")
for _, nn := range n.vars {
nn.Print(out, indent+" ")
}
}
}

View File

@ -600,13 +600,13 @@ var yyAct = [...]int{
807, 197, 199, 198, 332, 607, 795, 610, 608, 308,
766, 718, 669, 279, 280, 642, 817, 633, 628, 785,
229, 564, 812, 824, 810, 825, 554, 118, 231, 409,
1, 831, 804, 848, 659, 544, 255, 256, 651, 803,
842, 144, 748, 830, 141, 813, 578, 846, 833, 321,
855, 148, 841, 687, 688, 689, 686, 685, 684, 800,
1, 831, 365, 804, 659, 544, 255, 256, 848, 803,
842, 651, 144, 830, 748, 813, 578, 846, 833, 141,
855, 321, 841, 687, 688, 689, 686, 685, 684, 148,
864, 854, 167, 168, 161, 162, 160, 163, 165, 166,
863, 178, 666, 829, 872, 250, 873, 37, 868, 681,
877, 679, 678, 164, 861, 221, 879, 223, 835, 42,
912, 529, 855, 570, 782, 878, 41, 365, 882, 15,
863, 178, 800, 666, 872, 829, 873, 250, 868, 37,
877, 681, 679, 164, 861, 678, 879, 221, 223, 835,
42, 912, 855, 529, 782, 878, 570, 41, 882, 15,
14, 519, 606, 854, 888, 889, 266, 48, 890, 87,
88, 89, 90, 91, 47, 107, 49, 82, 73, 74,
80, 75, 71, 247, 896, 893, 61, 264, 897, 60,
@ -1367,12 +1367,12 @@ var yyPgo = [...]int{
904, 9, 903, 902, 896, 894, 13, 48, 889, 887,
111, 98, 197, 886, 883, 882, 8, 880, 81, 43,
877, 55, 47, 876, 875, 874, 867, 866, 97, 862,
861, 103, 549, 1, 860, 859, 857, 7, 19, 38,
856, 853, 83, 851, 10, 4, 850, 86, 849, 18,
848, 847, 845, 44, 42, 32, 41, 2, 16, 842,
841, 839, 5, 775, 837, 670, 835, 28, 833, 832,
819, 90, 811, 31, 809, 804, 25, 29, 802, 801,
798, 24, 793, 792, 790, 37, 12,
861, 103, 549, 1, 860, 859, 7, 19, 38, 857,
856, 83, 853, 10, 4, 851, 86, 850, 18, 849,
848, 847, 44, 42, 32, 41, 2, 16, 845, 842,
841, 5, 775, 839, 670, 837, 28, 835, 833, 832,
90, 819, 31, 811, 809, 25, 29, 804, 802, 801,
24, 798, 793, 792, 790, 37, 12,
}
var yyR1 = [...]int{
@ -1384,27 +1384,27 @@ var yyR1 = [...]int{
5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 6,
6, 6, 6, 6, 6, 6, 7, 7, 71, 71,
107, 107, 9, 9, 9, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 103,
103, 16, 16, 18, 18, 125, 125, 117, 117, 116,
116, 72, 72, 17, 17, 20, 20, 19, 19, 111,
111, 73, 73, 22, 22, 22, 22, 22, 22, 10,
106, 106, 9, 9, 9, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 102,
102, 16, 16, 18, 18, 125, 125, 116, 116, 115,
115, 72, 72, 17, 17, 20, 20, 19, 19, 110,
110, 73, 73, 22, 22, 22, 22, 22, 22, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 109, 109, 108, 108, 30, 30, 76,
76, 31, 11, 1, 1, 2, 2, 12, 12, 104,
104, 4, 4, 13, 14, 33, 33, 15, 15, 79,
79, 27, 27, 27, 27, 26, 26, 28, 28, 29,
29, 120, 120, 120, 120, 121, 121, 121, 126, 126,
25, 25, 80, 80, 74, 74, 88, 88, 75, 75,
77, 77, 81, 81, 34, 34, 35, 35, 98, 98,
96, 96, 96, 97, 97, 82, 82, 83, 83, 36,
36, 115, 115, 38, 119, 119, 39, 39, 78, 78,
40, 40, 40, 40, 85, 85, 123, 123, 123, 122,
122, 41, 41, 42, 43, 43, 43, 43, 45, 45,
44, 86, 86, 99, 99, 100, 100, 101, 101, 102,
102, 102, 102, 102, 102, 118, 118, 46, 46, 110,
110, 84, 21, 112, 112, 47, 113, 113, 114, 114,
10, 10, 10, 108, 108, 107, 107, 30, 30, 123,
123, 31, 11, 1, 1, 2, 2, 12, 12, 103,
103, 4, 4, 13, 14, 33, 33, 15, 15, 78,
78, 27, 27, 27, 27, 26, 26, 28, 28, 29,
29, 119, 119, 119, 119, 120, 120, 120, 126, 126,
25, 25, 79, 79, 74, 74, 87, 87, 75, 75,
76, 76, 80, 80, 34, 34, 35, 35, 97, 97,
95, 95, 95, 96, 96, 81, 81, 82, 82, 36,
36, 114, 114, 38, 118, 118, 39, 39, 77, 77,
40, 40, 40, 40, 84, 84, 122, 122, 122, 121,
121, 41, 41, 42, 43, 43, 43, 43, 45, 45,
44, 85, 85, 98, 98, 99, 99, 100, 100, 101,
101, 101, 101, 101, 101, 117, 117, 46, 46, 109,
109, 83, 21, 111, 111, 47, 112, 112, 113, 113,
49, 48, 48, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
@ -1413,18 +1413,18 @@ var yyR1 = [...]int{
37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
37, 37, 37, 37, 37, 37, 37, 37, 37, 3,
3, 89, 89, 90, 90, 56, 56, 57, 57, 57,
57, 50, 50, 51, 51, 54, 54, 106, 106, 106,
87, 87, 61, 61, 61, 55, 55, 55, 55, 55,
3, 88, 88, 89, 89, 56, 56, 57, 57, 57,
57, 50, 50, 51, 51, 54, 54, 105, 105, 105,
86, 86, 61, 61, 61, 55, 55, 55, 55, 55,
55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
55, 62, 62, 62, 23, 23, 24, 24, 60, 63,
63, 63, 64, 64, 64, 65, 65, 65, 65, 65,
65, 32, 32, 32, 52, 52, 52, 66, 66, 67,
67, 67, 67, 67, 67, 58, 58, 58, 59, 59,
59, 93, 94, 94, 92, 92, 91, 91, 91, 91,
91, 91, 105, 105, 105, 105, 68, 68, 68, 68,
59, 92, 93, 93, 91, 91, 90, 90, 90, 90,
90, 90, 104, 104, 104, 104, 68, 68, 68, 68,
68, 68, 68, 69, 69, 69, 69, 53, 53, 53,
53, 53, 53, 53, 70, 70, 95,
53, 53, 53, 53, 70, 70, 94,
}
var yyR2 = [...]int{
@ -1483,18 +1483,18 @@ var yyChk = [...]int{
-1000, -124, -71, -8, -10, -11, -12, -13, -14, 127,
154, 120, 114, 161, -74, -75, 97, 96, 99, 106,
110, 111, 115, 122, 76, 95, 90, -23, 124, 101,
103, 163, 116, 119, 112, 86, 113, -104, 128, 129,
130, -80, -88, -32, -37, -4, 83, -65, -66, -63,
103, 163, 116, 119, 112, 86, 113, -103, 128, 129,
130, -79, -87, -32, -37, -4, 83, -65, -66, -63,
134, 69, 71, 58, 59, 49, 50, 55, 57, 164,
-48, -53, 60, 61, 62, 63, 64, 65, 66, 82,
67, -55, 160, 13, 14, 16, 77, 78, -52, -62,
-57, -50, -60, -61, 70, 125, 126, 4, 5, 6,
7, 8, 84, 85, 141, 142, 156, 138, 139, 140,
155, 137, 149, 159, 88, 167, -9, -64, 135, 94,
-107, 157, 164, 157, -107, 161, 86, -18, -103, -72,
-107, 157, 113, 114, -19, -20, -111, -21, 86, -73,
-106, 157, 164, 157, -106, 161, 86, -18, -102, -72,
-106, 157, 113, 114, -19, -20, -110, -21, 86, -73,
164, -10, 113, 154, 164, 164, -24, -23, 76, -24,
-24, -115, -38, -52, -119, 113, -39, 88, -112, -47,
-24, -114, -38, -52, -118, 113, -39, 88, -111, -47,
-23, 163, 33, 34, 10, 12, 11, 35, 37, 36,
51, 49, 50, 52, 68, 53, 54, 47, 48, 40,
41, 38, 39, 43, 44, 45, 46, 42, 56, 30,
@ -1502,26 +1502,26 @@ var yyChk = [...]int{
128, -4, 86, 86, 86, 73, 74, 73, 75, 74,
17, 18, 19, 20, 29, 21, 22, 23, 24, 25,
26, 27, 28, 58, 59, 164, 69, 161, 133, 164,
-93, -92, -94, -91, -23, 37, 134, -23, -32, -62,
-92, -91, -93, -90, -23, 37, 134, -23, -32, -62,
164, -61, 76, 69, -32, -23, -23, -23, -23, -23,
-23, -23, -23, -23, -23, -23, -23, -54, 164, -23,
-106, 93, -105, -68, 88, 151, 152, -23, -23, -23,
-105, 93, -104, -68, 88, 151, 152, -23, -23, -23,
69, 153, 153, -51, -49, -50, -67, 128, -9, -52,
164, 164, -23, -23, 164, -23, -23, 93, 150, -105,
-105, 93, 161, -52, -82, 164, -82, 164, 157, -107,
165, -107, 163, 161, -71, 163, -16, -72, -107, 157,
163, 9, 157, 105, -107, -20, 163, 9, 17, -22,
164, 164, -23, -23, 164, -23, -23, 93, 150, -104,
-104, 93, 161, -52, -81, 164, -81, 164, 157, -106,
165, -106, 163, 161, -71, 163, -16, -72, -106, 157,
163, 9, 157, 105, -106, -20, 163, 9, 17, -22,
162, -10, -11, -12, -13, -14, 127, -23, 97, -3,
-113, -114, -23, -23, 163, 163, 163, 163, 9, 163,
-112, -113, -23, -23, 163, 163, 163, 163, 9, 163,
9, -3, 17, 163, 9, -23, -23, -23, -23, -23,
-23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
-23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
-23, -51, -23, 31, -23, -76, -31, -32, -23, -111,
-23, -51, -23, 31, -23, -123, -31, -32, -23, -110,
-73, 163, 163, 86, 164, 86, -33, 131, 161, -15,
131, 164, -10, 164, 163, 31, -23, 37, -23, -23,
-23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
-23, -24, -23, -59, 86, 161, -52, -93, 166, 9,
15, -32, 164, -23, -93, 165, -24, 160, -68, -68,
-23, -24, -23, -59, 86, 161, -52, -92, 166, 9,
15, -32, 164, -23, -92, 165, -24, 160, -68, -68,
93, 69, 133, -23, 87, -32, 15, -24, -58, -7,
-52, 161, 86, -6, -5, 76, 77, 78, 79, 80,
81, 4, 5, 6, 7, 8, 10, 11, 12, 56,
@ -1531,47 +1531,47 @@ var yyChk = [...]int{
112, 113, 114, 115, 13, 14, 134, 106, 107, 108,
109, 110, 135, 136, 131, 132, 154, 129, 130, 128,
137, 138, 140, 139, 141, 142, 156, 155, -58, -7,
-52, -87, -82, 153, 69, 161, 133, 153, -87, -70,
-95, -23, -23, -23, 150, 150, 159, -23, 165, -83,
-36, -23, 158, -93, 86, 163, -71, 162, 163, 163,
157, -107, -19, 157, -107, 161, 86, 157, -21, -23,
-52, -86, -81, 153, 69, 161, 133, 153, -86, -70,
-94, -23, -23, -23, 150, 150, 159, -23, 165, -82,
-36, -23, 158, -92, 86, 163, -71, 162, 163, 163,
157, -106, -19, 157, -106, 161, 86, 157, -21, -23,
164, 165, 164, 163, 9, 165, -38, -39, 164, -23,
-47, 31, -23, -125, 9, 105, 165, 162, 164, -77,
-81, -34, -35, -98, -96, 30, 135, 136, -9, -33,
-79, 132, -9, -78, 161, -85, -9, -23, -23, -73,
-23, 165, 166, 162, -82, -23, 165, 17, -94, -23,
37, 134, -93, 165, 166, 165, -69, 86, 89, 50,
88, 86, 162, 162, 69, 162, -23, 166, -82, -23,
-82, -52, -24, -23, -59, -52, -33, -125, 9, 165,
165, 162, -125, 9, -23, 165, 162, 161, 157, -117,
-17, -20, -103, 161, 165, -25, -10, 31, -23, -113,
-23, -120, 161, 31, -77, -23, 165, -31, -27, -32,
37, 134, 69, -29, -10, 31, -109, -77, 165, 9,
-1, 37, -96, -79, 161, -85, 162, -40, -99, -100,
120, -101, 123, -102, 81, 80, 79, 76, 77, 78,
-78, 9, 165, 165, 75, -10, 31, 162, 17, -23,
-32, 164, 165, 166, 89, -23, 162, 166, 162, -79,
165, -95, 165, -36, -116, -20, 161, -125, 9, -20,
-117, 163, -73, 165, 163, -121, 163, -121, 163, 165,
163, 165, 15, -32, 164, -93, -73, -30, 117, 118,
165, -89, 120, -34, -2, 158, 161, -78, -118, -46,
88, 114, 113, -85, -102, 162, -9, -10, 31, 163,
-73, -23, -93, 166, 161, -125, 9, -116, 162, -17,
-125, 98, 163, -113, 162, 108, 109, -121, 107, -121,
-89, -28, -10, 31, -27, -93, 166, 104, 164, 161,
-97, 31, -97, 164, 88, -78, 162, 163, 9, 17,
-110, -84, -7, -3, -123, 163, 161, -73, 165, 162,
-78, 162, -20, -125, 162, 163, 165, -23, -126, 31,
163, 162, 163, 107, -97, -73, 165, 165, 163, -108,
-9, -73, 161, -98, 161, -90, -56, 88, 37, 17,
162, -46, -23, 163, 9, 17, -7, 162, -122, -41,
-47, 31, -23, -125, 9, 105, 165, 162, 164, -76,
-80, -34, -35, -97, -95, 30, 135, 136, -9, -33,
-78, 132, -9, -77, 161, -84, -9, -23, -23, -73,
-23, 165, 166, 162, -81, -23, 165, 17, -93, -23,
37, 134, -92, 165, 166, 165, -69, 86, 89, 50,
88, 86, 162, 162, 69, 162, -23, 166, -81, -23,
-81, -52, -24, -23, -59, -52, -33, -125, 9, 165,
165, 162, -125, 9, -23, 165, 162, 161, 157, -116,
-17, -20, -102, 161, 165, -25, -10, 31, -23, -112,
-23, -119, 161, 31, -76, -23, 165, -31, -27, -32,
37, 134, 69, -29, -10, 31, -108, -76, 165, 9,
-1, 37, -95, -78, 161, -84, 162, -40, -98, -99,
120, -100, 123, -101, 81, 80, 79, 76, 77, 78,
-77, 9, 165, 165, 75, -10, 31, 162, 17, -23,
-32, 164, 165, 166, 89, -23, 162, 166, 162, -78,
165, -94, 165, -36, -115, -20, 161, -125, 9, -20,
-116, 163, -73, 165, 163, -120, 163, -120, 163, 165,
163, 165, 15, -32, 164, -92, -73, -30, 117, 118,
165, -88, 120, -34, -2, 158, 161, -77, -117, -46,
88, 114, 113, -84, -101, 162, -9, -10, 31, 163,
-73, -23, -92, 166, 161, -125, 9, -115, 162, -17,
-125, 98, 163, -112, 162, 108, 109, -120, 107, -120,
-88, -28, -10, 31, -27, -92, 166, 104, 164, 161,
-96, 31, -96, 164, 88, -77, 162, 163, 9, 17,
-109, -83, -7, -3, -122, 163, 161, -73, 165, 162,
-77, 162, -20, -125, 162, 163, 165, -23, -126, 31,
163, 162, 163, 107, -96, -73, 165, 165, 163, -107,
-9, -73, 161, -97, 161, -89, -56, 88, 37, 17,
162, -46, -23, 163, 9, 17, -7, 162, -121, -41,
-42, -43, -44, -45, -9, -7, 154, 86, 162, 162,
-26, -10, 31, -126, -73, 163, 161, 102, -28, 88,
35, 162, -73, -73, 165, 9, 88, -23, -84, -23,
35, 162, -73, -73, 165, 9, 88, -23, -83, -23,
164, 162, -41, 163, 163, 121, 105, 153, -73, -73,
-73, 163, 165, -9, 162, 162, -56, -77, -85, 86,
-5, -102, -7, 100, 162, 161, 165, -7, 163, -73,
-97, 162, -86, 163, 161, -73, 162,
-73, 163, 165, -9, 162, 162, -56, -76, -84, 86,
-5, -101, -7, 100, 162, 161, 165, -7, 163, -73,
-96, 162, -85, 163, 161, -73, 162,
}
var yyDef = [...]int{
@ -2896,7 +2896,7 @@ yydefault:
yyDollar = yyS[yypt-6 : yypt+1]
//line parser/parser.y:392
{
yyVAL.node = node.NewSimpleNode("Unset").Append(yyDollar[3].node)
yyVAL.node = stmt.NewUnset(yyDollar[1].token, yyDollar[3].list)
}
case 145:
yyDollar = yyS[yypt-7 : yypt+1]
@ -2986,13 +2986,13 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
//line parser/parser.y:423
{
yyVAL.node = node.NewSimpleNode("UnsetVariablesList").Append(yyDollar[1].node)
yyVAL.list = []node.Node{yyDollar[1].node}
}
case 160:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:424
{
yyVAL.node = yyDollar[1].node.Append(yyDollar[3].node)
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
}
case 161:
yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -201,7 +201,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <node> encaps_var encaps_var_offset isset_variables
%type <node> top_statement_list use_declarations inner_statement_list if_stmt
%type <node> alt_if_stmt
%type <node> unset_variables parameter_list class_statement_list
%type <node> parameter_list class_statement_list
%type <node> implements_list if_stmt_without_else
%type <node> non_empty_parameter_list argument_list non_empty_argument_list
%type <node> class_const_decl name_list method_body
@ -218,7 +218,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list
%type <list> unprefixed_use_declarations inline_use_declarations property_list static_var_list
%type <list> switch_case_list case_list trait_adaptation_list trait_adaptations
%type <list> switch_case_list case_list trait_adaptation_list trait_adaptations unset_variables
%%
@ -389,7 +389,7 @@ statement:
| T_INLINE_HTML { $$ = stmt.NewInlineHtml($1) }
| expr ';' { $$ = stmt.NewExpression($1); }
| T_UNSET '(' unset_variables possible_comma ')' ';'
{ $$ = node.NewSimpleNode("Unset").Append($3); }
{ $$ = stmt.NewUnset($1, $3) }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
{ $$ = stmt.NewForeach($1, $3, nil, $5, $7); }
| T_FOREACH '(' expr T_AS foreach_variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
@ -420,8 +420,8 @@ finally_statement:
;
unset_variables:
unset_variable { $$ = node.NewSimpleNode("UnsetVariablesList").Append($1) }
| unset_variables ',' unset_variable { $$ = $1.Append($3) }
unset_variable { $$ = []node.Node{$1} }
| unset_variables ',' unset_variable { $$ = append($1, $3) }
;
unset_variable: