-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathconst-expr.pp3
More file actions
118 lines (103 loc) · 2.76 KB
/
Copy pathconst-expr.pp3
File metadata and controls
118 lines (103 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* -----------------------------------------------------------------------------
* Constant Expressions
* -----------------------------------------------------------------------------
*
* The literals a PHPDoc may be written of, read the way
* "PHPStan\PhpDocParser\Parser\ConstExprParser" reads them.
*
* The alternatives are written in the order that parser tries them in, and the
* places it would raise an error at are written as a rule that cannot be
* recognized, so that the two agree on what is a constant expression and what
* is not.
*/
ConstantExpr
: ConstantFloat()
| ConstantInteger()
| ConstantString()
| ConstantTrue()
| ConstantFalse()
| ConstantNull()
| ConstantArrayLiteral()
| ConstantFetch()
| ConstantArrayShorthand()
;
ConstantFloat
: <T_FLOAT>
;
ConstantInteger
: <T_INTEGER>
;
ConstantString
: <T_SINGLE_QUOTED_STRING>
| <T_DOUBLE_QUOTED_STRING>
;
ConstantTrue
: <T_KEYWORD_TRUE>
;
ConstantFalse
: <T_KEYWORD_FALSE>
;
ConstantNull
: <T_KEYWORD_NULL>
;
/**
* An array written the long way, like:
* - array(1, 2)
*
* The word is compared without regard to case, so "ARRAY(1, 2)" is one as
* well. A word that is not followed by a parenthesis is an error rather than a
* constant of that name, which is what keeps it out of "ConstantFetch".
*/
ConstantArrayLiteral
: ArrayKeyword() ParenthesesOpen() ConstantArrayItems()? <T_CLOSE_PARENTHESES>
;
/**
* An array written the short way, like:
* - [1, 2]
*/
ConstantArrayShorthand
: SquareBracketOpen() ConstantArrayItems()? <T_CLOSE_SQUARE_BRACKET>
;
/**
* A trailing comma is written by the very rule the separating ones are, so an
* array of a single item may still end with one.
*/
ConstantArrayItems
: ConstantArrayItem() ( <T_COMMA> ConstantArrayItem() )* <T_COMMA>?
;
ConstantArrayItem
: ConstantExpr() ( <T_DOUBLE_ARROW> ConstantExpr() | !<T_DOUBLE_ARROW> )
;
/**
* A constant, either of a class or of none, like:
* - Foo::BAR
* - Foo::BAR_*
* - BAR
*/
ConstantFetch
: !ArrayKeyword() Identifier() <T_DOUBLE_COLON> ClassConstantName()
| !ArrayKeyword() Identifier()
;
/**
* The name of a class constant, which may be written with asterisks standing
* for any part of it, like:
* - BAR
* - BAR_*
* - *_BAR_*
*
* A name is written of names and asterisks one after another, never two of a
* kind in a row, and it ends at the first asterisk that whitespace follows.
*/
ClassConstantName
: <T_WILDCARD_WS>
| <T_WILDCARD> ClassConstantNameAfterWildcard()?
| Identifier() ClassConstantNameAfterIdentifier()?
;
ClassConstantNameAfterWildcard
: Identifier() ClassConstantNameAfterIdentifier()?
;
ClassConstantNameAfterIdentifier
: <T_WILDCARD_WS>
| <T_WILDCARD> ClassConstantNameAfterWildcard()?
;