static node

This commit is contained in:
vadim 2017-12-08 17:26:18 +02:00
parent 5fe3c4071d
commit 8cb363d5aa
3 changed files with 131 additions and 97 deletions

34
node/stmt/static.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 Static struct {
node.SimpleNode
token token.Token
vars []node.Node
}
func NewStatic(token token.Token, vars []node.Node) node.Node {
return Static{
node.SimpleNode{Name: "Static", Attributes: make(map[string]string)},
token,
vars,
}
}
func (n Static) 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, 748, 141, 659, 544, 255, 256, 321, 803,
842, 148, 800, 830, 666, 813, 578, 846, 833, 829,
855, 250, 841, 687, 688, 689, 686, 685, 684, 37,
1, 831, 144, 748, 659, 544, 255, 256, 141, 803,
842, 321, 148, 830, 800, 813, 578, 846, 833, 666,
855, 829, 841, 687, 688, 689, 686, 685, 684, 250,
864, 854, 167, 168, 161, 162, 160, 163, 165, 166,
863, 178, 681, 679, 872, 678, 873, 221, 868, 223,
877, 835, 848, 164, 861, 42, 879, 912, 804, 529,
570, 41, 855, 365, 782, 878, 144, 651, 882, 15,
863, 178, 37, 681, 872, 679, 873, 678, 868, 221,
877, 223, 835, 164, 861, 848, 879, 42, 912, 804,
529, 570, 855, 41, 782, 878, 365, 651, 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, 856, 853, 7,
19, 38, 24, 851, 850, 83, 849, 10, 4, 848,
847, 86, 845, 842, 18, 841, 839, 837, 44, 42,
32, 41, 2, 16, 835, 833, 832, 5, 775, 819,
670, 811, 28, 809, 804, 802, 90, 801, 31, 798,
793, 25, 29, 792, 790, 37, 12,
861, 103, 549, 1, 860, 859, 857, 856, 7, 19,
38, 24, 853, 851, 83, 850, 10, 4, 849, 848,
86, 847, 845, 18, 842, 841, 839, 44, 42, 32,
41, 2, 16, 837, 835, 833, 5, 775, 832, 670,
819, 28, 811, 809, 804, 90, 802, 31, 801, 798,
25, 29, 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,
112, 112, 9, 9, 9, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 108,
108, 16, 16, 18, 18, 125, 125, 122, 122, 121,
121, 72, 72, 17, 17, 20, 20, 19, 19, 116,
116, 73, 73, 22, 22, 22, 22, 22, 22, 10,
111, 111, 9, 9, 9, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 107,
107, 16, 16, 18, 18, 125, 125, 121, 121, 120,
120, 72, 72, 17, 17, 20, 20, 19, 19, 115,
115, 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, 114, 114, 113, 113, 30, 30, 78,
78, 31, 11, 1, 1, 2, 2, 12, 12, 109,
109, 4, 4, 13, 14, 33, 33, 15, 15, 81,
81, 27, 27, 27, 27, 26, 26, 28, 28, 29,
29, 76, 76, 76, 76, 82, 82, 82, 126, 126,
25, 25, 83, 83, 74, 74, 92, 92, 75, 75,
79, 79, 84, 84, 34, 34, 35, 35, 103, 103,
101, 101, 101, 102, 102, 85, 85, 86, 86, 36,
36, 120, 120, 38, 77, 77, 39, 39, 80, 80,
40, 40, 40, 40, 88, 88, 89, 89, 89, 93,
93, 41, 41, 42, 43, 43, 43, 43, 45, 45,
44, 90, 90, 104, 104, 105, 105, 106, 106, 107,
107, 107, 107, 107, 107, 123, 123, 46, 46, 115,
115, 87, 21, 117, 117, 47, 118, 118, 119, 119,
10, 10, 10, 113, 113, 112, 112, 30, 30, 77,
77, 31, 11, 1, 1, 2, 2, 12, 12, 108,
108, 4, 4, 13, 14, 33, 33, 15, 15, 80,
80, 27, 27, 27, 27, 26, 26, 28, 28, 29,
29, 76, 76, 76, 76, 81, 81, 81, 126, 126,
25, 25, 82, 82, 74, 74, 91, 91, 75, 75,
78, 78, 83, 83, 34, 34, 35, 35, 102, 102,
100, 100, 100, 101, 101, 84, 84, 85, 85, 36,
36, 119, 119, 38, 123, 123, 39, 39, 79, 79,
40, 40, 40, 40, 87, 87, 88, 88, 88, 92,
92, 41, 41, 42, 43, 43, 43, 43, 45, 45,
44, 89, 89, 103, 103, 104, 104, 105, 105, 106,
106, 106, 106, 106, 106, 122, 122, 46, 46, 114,
114, 86, 21, 116, 116, 47, 117, 117, 118, 118,
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, 94, 94, 95, 95, 56, 56, 57, 57, 57,
57, 50, 50, 51, 51, 54, 54, 111, 111, 111,
91, 91, 61, 61, 61, 55, 55, 55, 55, 55,
3, 93, 93, 94, 94, 56, 56, 57, 57, 57,
57, 50, 50, 51, 51, 54, 54, 110, 110, 110,
90, 90, 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, 98, 99, 99, 97, 97, 96, 96, 96, 96,
96, 96, 110, 110, 110, 110, 68, 68, 68, 68,
59, 97, 98, 98, 96, 96, 95, 95, 95, 95,
95, 95, 109, 109, 109, 109, 68, 68, 68, 68,
68, 68, 68, 69, 69, 69, 69, 53, 53, 53,
53, 53, 53, 53, 70, 70, 100,
53, 53, 53, 53, 70, 70, 99,
}
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, -109, 128, 129,
130, -83, -92, -32, -37, -4, 83, -65, -66, -63,
103, 163, 116, 119, 112, 86, 113, -108, 128, 129,
130, -82, -91, -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,
-112, 157, 164, 157, -112, 161, 86, -18, -108, -72,
-112, 157, 113, 114, -19, -20, -116, -21, 86, -73,
-111, 157, 164, 157, -111, 161, 86, -18, -107, -72,
-111, 157, 113, 114, -19, -20, -115, -21, 86, -73,
164, -10, 113, 154, 164, 164, -24, -23, 76, -24,
-24, -120, -38, -52, -77, 113, -39, 88, -117, -47,
-24, -119, -38, -52, -123, 113, -39, 88, -116, -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,
-98, -97, -99, -96, -23, 37, 134, -23, -32, -62,
-97, -96, -98, -95, -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,
-111, 93, -110, -68, 88, 151, 152, -23, -23, -23,
-110, 93, -109, -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, -110,
-110, 93, 161, -52, -85, 164, -85, 164, 157, -112,
165, -112, 163, 161, -71, 163, -16, -72, -112, 157,
163, 9, 157, 105, -112, -20, 163, 9, 17, -22,
164, 164, -23, -23, 164, -23, -23, 93, 150, -109,
-109, 93, 161, -52, -84, 164, -84, 164, 157, -111,
165, -111, 163, 161, -71, 163, -16, -72, -111, 157,
163, 9, 157, 105, -111, -20, 163, 9, 17, -22,
162, -10, -11, -12, -13, -14, 127, -23, 97, -3,
-118, -119, -23, -23, 163, 163, 163, 163, 9, 163,
-117, -118, -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, -78, -31, -32, -23, -116,
-23, -51, -23, 31, -23, -77, -31, -32, -23, -115,
-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, -98, 166, 9,
15, -32, 164, -23, -98, 165, -24, 160, -68, -68,
-23, -24, -23, -59, 86, 161, -52, -97, 166, 9,
15, -32, 164, -23, -97, 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, -91, -85, 153, 69, 161, 133, 153, -91, -70,
-100, -23, -23, -23, 150, 150, 159, -23, 165, -86,
-36, -23, 158, -98, 86, 163, -71, 162, 163, 163,
157, -112, -19, 157, -112, 161, 86, 157, -21, -23,
-52, -90, -84, 153, 69, 161, 133, 153, -90, -70,
-99, -23, -23, -23, 150, 150, 159, -23, 165, -85,
-36, -23, 158, -97, 86, 163, -71, 162, 163, 163,
157, -111, -19, 157, -111, 161, 86, 157, -21, -23,
164, 165, 164, 163, 9, 165, -38, -39, 164, -23,
-47, 31, -23, -125, 9, 105, 165, 162, 164, -79,
-84, -34, -35, -103, -101, 30, 135, 136, -9, -33,
-81, 132, -9, -80, 161, -88, -9, -23, -23, -73,
-23, 165, 166, 162, -85, -23, 165, 17, -99, -23,
37, 134, -98, 165, 166, 165, -69, 86, 89, 50,
88, 86, 162, 162, 69, 162, -23, 166, -85, -23,
-85, -52, -24, -23, -59, -52, -33, -125, 9, 165,
165, 162, -125, 9, -23, 165, 162, 161, 157, -122,
-17, -20, -108, 161, 165, -25, -10, 31, -23, -118,
-23, -76, 161, 31, -79, -23, 165, -31, -27, -32,
37, 134, 69, -29, -10, 31, -114, -79, 165, 9,
-1, 37, -101, -81, 161, -88, 162, -40, -104, -105,
120, -106, 123, -107, 81, 80, 79, 76, 77, 78,
-80, 9, 165, 165, 75, -10, 31, 162, 17, -23,
-32, 164, 165, 166, 89, -23, 162, 166, 162, -81,
165, -100, 165, -36, -121, -20, 161, -125, 9, -20,
-122, 163, -73, 165, 163, -82, 163, -82, 163, 165,
163, 165, 15, -32, 164, -98, -73, -30, 117, 118,
165, -94, 120, -34, -2, 158, 161, -80, -123, -46,
88, 114, 113, -88, -107, 162, -9, -10, 31, 163,
-73, -23, -98, 166, 161, -125, 9, -121, 162, -17,
-125, 98, 163, -118, 162, 108, 109, -82, 107, -82,
-94, -28, -10, 31, -27, -98, 166, 104, 164, 161,
-102, 31, -102, 164, 88, -80, 162, 163, 9, 17,
-115, -87, -7, -3, -89, 163, 161, -73, 165, 162,
-80, 162, -20, -125, 162, 163, 165, -23, -126, 31,
163, 162, 163, 107, -102, -73, 165, 165, 163, -113,
-9, -73, 161, -103, 161, -95, -56, 88, 37, 17,
162, -46, -23, 163, 9, 17, -7, 162, -93, -41,
-47, 31, -23, -125, 9, 105, 165, 162, 164, -78,
-83, -34, -35, -102, -100, 30, 135, 136, -9, -33,
-80, 132, -9, -79, 161, -87, -9, -23, -23, -73,
-23, 165, 166, 162, -84, -23, 165, 17, -98, -23,
37, 134, -97, 165, 166, 165, -69, 86, 89, 50,
88, 86, 162, 162, 69, 162, -23, 166, -84, -23,
-84, -52, -24, -23, -59, -52, -33, -125, 9, 165,
165, 162, -125, 9, -23, 165, 162, 161, 157, -121,
-17, -20, -107, 161, 165, -25, -10, 31, -23, -117,
-23, -76, 161, 31, -78, -23, 165, -31, -27, -32,
37, 134, 69, -29, -10, 31, -113, -78, 165, 9,
-1, 37, -100, -80, 161, -87, 162, -40, -103, -104,
120, -105, 123, -106, 81, 80, 79, 76, 77, 78,
-79, 9, 165, 165, 75, -10, 31, 162, 17, -23,
-32, 164, 165, 166, 89, -23, 162, 166, 162, -80,
165, -99, 165, -36, -120, -20, 161, -125, 9, -20,
-121, 163, -73, 165, 163, -81, 163, -81, 163, 165,
163, 165, 15, -32, 164, -97, -73, -30, 117, 118,
165, -93, 120, -34, -2, 158, 161, -79, -122, -46,
88, 114, 113, -87, -106, 162, -9, -10, 31, 163,
-73, -23, -97, 166, 161, -125, 9, -120, 162, -17,
-125, 98, 163, -117, 162, 108, 109, -81, 107, -81,
-93, -28, -10, 31, -27, -97, 166, 104, 164, 161,
-101, 31, -101, 164, 88, -79, 162, 163, 9, 17,
-114, -86, -7, -3, -88, 163, 161, -73, 165, 162,
-79, 162, -20, -125, 162, 163, 165, -23, -126, 31,
163, 162, 163, 107, -101, -73, 165, 165, 163, -112,
-9, -73, 161, -102, 161, -94, -56, 88, 37, 17,
162, -46, -23, 163, 9, 17, -7, 162, -92, -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, -87, -23,
35, 162, -73, -73, 165, 9, 88, -23, -86, -23,
164, 162, -41, 163, 163, 121, 105, 153, -73, -73,
-73, 163, 165, -9, 162, 162, -56, -79, -88, 86,
-5, -107, -7, 100, 162, 161, 165, -7, 163, -73,
-102, 162, -90, 163, 161, -73, 162,
-73, 163, 165, -9, 162, 162, -56, -78, -87, 86,
-5, -106, -7, 100, 162, 161, 165, -7, 163, -73,
-101, 162, -89, 163, 161, -73, 162,
}
var yyDef = [...]int{
@ -2872,7 +2872,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:386
{
yyVAL.node = yyDollar[2].node
yyVAL.node = stmt.NewStatic(yyDollar[1].token, yyDollar[2].list)
}
case 141:
yyDollar = yyS[yypt-3 : yypt+1]
@ -3440,13 +3440,13 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:656
{
yyVAL.node = yyDollar[1].node.Append(yyDollar[3].node)
yyVAL.list = append(yyDollar[1].list, yyDollar[3].node)
}
case 235:
yyDollar = yyS[yypt-1 : yypt+1]
//line parser/parser.y:657
{
yyVAL.node = node.NewSimpleNode("StaticVarList").Append(yyDollar[1].node)
yyVAL.list = []node.Node{yyDollar[1].node}
}
case 236:
yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -200,7 +200,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <node> callable_expr callable_variable static_member new_variable
%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 switch_case_list static_var_list
%type <node> alt_if_stmt switch_case_list
%type <node> unset_variables parameter_list class_statement_list
%type <node> implements_list case_list if_stmt_without_else
%type <node> non_empty_parameter_list argument_list non_empty_argument_list
@ -217,7 +217,7 @@ func Parse(src io.Reader, fName string) node.Node {
%type <strings> class_modifiers
%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
%type <list> unprefixed_use_declarations inline_use_declarations property_list static_var_list
%%
@ -383,7 +383,7 @@ statement:
| T_CONTINUE optional_expr ';' { $$ = stmt.NewContinue($1, $2) }
| T_RETURN optional_expr ';' { $$ = stmt.NewReturn($1, $2) }
| T_GLOBAL global_var_list ';' { $$ = stmt.NewGlobal($1, $2) }
| T_STATIC static_var_list ';' { $$ = $2; }
| T_STATIC static_var_list ';' { $$ = stmt.NewStatic($1, $2); }
| T_ECHO echo_expr_list ';' { $$ = stmt.NewEcho($1, $2) }
| T_INLINE_HTML { $$ = stmt.NewInlineHtml($1) }
| expr ';' { $$ = stmt.NewExpression($1); }
@ -653,8 +653,8 @@ global_var:
;
static_var_list:
static_var_list ',' static_var { $$ = $1.Append($3); }
| static_var { $$ = node.NewSimpleNode("StaticVarList").Append($1); }
static_var_list ',' static_var { $$ = append($1, $3) }
| static_var { $$ = []node.Node{$1} }
;
static_var: