Skip to content

Commit 841d128

Browse files
committed
added operator 'not'
1 parent b0cfaa7 commit 841d128

File tree

8 files changed

+389
-326
lines changed

8 files changed

+389
-326
lines changed

src/Latte/Compiler/TagLexer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class TagLexer
3535
'null' => Token::Php_Null,
3636
'true' => Token::Php_True,
3737
'false' => Token::Php_False,
38+
'not' => Token::Php_Not,
3839
];
3940

4041
private const KeywordsFollowed = [ // must follows ( & =

src/Latte/Compiler/TagParserData.php

Lines changed: 255 additions & 254 deletions
Large diffs are not rendered by default.

src/Latte/Compiler/Token.php

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -64,65 +64,66 @@ final class Token
6464
Php_BooleanAnd = 276,
6565
Php_AmpersandNotFollowed = 277,
6666
Php_AmpersandFollowed = 278,
67-
Php_IsEqual = 279,
68-
Php_IsNotEqual = 280,
69-
Php_IsIdentical = 281,
70-
Php_IsNotIdentical = 282,
71-
Php_Spaceship = 283,
72-
Php_IsSmallerOrEqual = 284,
73-
Php_IsGreaterOrEqual = 285,
74-
Php_Sl = 286,
75-
Php_Sr = 287,
76-
Php_In = 288,
77-
Php_Instanceof = 289,
78-
Php_Inc = 290,
79-
Php_Dec = 291,
80-
Php_IntCast = 292,
81-
Php_FloatCast = 293,
82-
Php_StringCast = 294,
83-
Php_ArrayCast = 295,
84-
Php_ObjectCast = 296,
85-
Php_BoolCast = 297,
86-
Php_Pow = 298,
87-
Php_New = 299,
88-
Php_Clone = 300,
89-
Php_Integer = 301,
90-
Php_Float = 302,
91-
Php_Identifier = 303,
92-
Php_StringVarname = 304,
93-
Php_Constant = 305,
94-
Php_Variable = 306,
95-
Php_NumString = 307,
96-
Php_EncapsedAndWhitespace = 308,
97-
Php_ConstantEncapsedString = 309,
98-
Php_Match = 310,
99-
Php_Default = 311,
100-
Php_Function = 312,
101-
Php_Fn = 313,
102-
Php_Return = 314,
103-
Php_Use = 315,
104-
Php_Isset = 316,
105-
Php_Empty = 317,
106-
Php_ObjectOperator = 318,
107-
Php_NullsafeObjectOperator = 319,
108-
Php_UndefinedsafeObjectOperator = 320,
109-
Php_List = 321,
110-
Php_Array = 322,
111-
Php_StartHeredoc = 323,
112-
Php_EndHeredoc = 324,
113-
Php_DollarOpenCurlyBraces = 325,
114-
Php_CurlyOpen = 326,
115-
Php_PaamayimNekudotayim = 327,
116-
Php_NsSeparator = 328,
117-
Php_Ellipsis = 329,
118-
Php_ExpandCast = 330,
119-
Php_NameFullyQualified = 331,
120-
Php_NameQualified = 332,
121-
Php_Whitespace = 333,
122-
Php_Comment = 334,
123-
Php_Null = 335,
124-
Php_True = 336,
125-
Php_False = 337;
67+
Php_Not = 279,
68+
Php_IsEqual = 280,
69+
Php_IsNotEqual = 281,
70+
Php_IsIdentical = 282,
71+
Php_IsNotIdentical = 283,
72+
Php_Spaceship = 284,
73+
Php_IsSmallerOrEqual = 285,
74+
Php_IsGreaterOrEqual = 286,
75+
Php_In = 287,
76+
Php_Sl = 288,
77+
Php_Sr = 289,
78+
Php_Instanceof = 290,
79+
Php_Inc = 291,
80+
Php_Dec = 292,
81+
Php_IntCast = 293,
82+
Php_FloatCast = 294,
83+
Php_StringCast = 295,
84+
Php_ArrayCast = 296,
85+
Php_ObjectCast = 297,
86+
Php_BoolCast = 298,
87+
Php_Pow = 299,
88+
Php_New = 300,
89+
Php_Clone = 301,
90+
Php_Integer = 302,
91+
Php_Float = 303,
92+
Php_Identifier = 304,
93+
Php_StringVarname = 305,
94+
Php_Constant = 306,
95+
Php_Variable = 307,
96+
Php_NumString = 308,
97+
Php_EncapsedAndWhitespace = 309,
98+
Php_ConstantEncapsedString = 310,
99+
Php_Match = 311,
100+
Php_Default = 312,
101+
Php_Function = 313,
102+
Php_Fn = 314,
103+
Php_Return = 315,
104+
Php_Use = 316,
105+
Php_Isset = 317,
106+
Php_Empty = 318,
107+
Php_ObjectOperator = 319,
108+
Php_NullsafeObjectOperator = 320,
109+
Php_UndefinedsafeObjectOperator = 321,
110+
Php_List = 322,
111+
Php_Array = 323,
112+
Php_StartHeredoc = 324,
113+
Php_EndHeredoc = 325,
114+
Php_DollarOpenCurlyBraces = 326,
115+
Php_CurlyOpen = 327,
116+
Php_PaamayimNekudotayim = 328,
117+
Php_NsSeparator = 329,
118+
Php_Ellipsis = 330,
119+
Php_ExpandCast = 331,
120+
Php_NameFullyQualified = 332,
121+
Php_NameQualified = 333,
122+
Php_Whitespace = 334,
123+
Php_Comment = 335,
124+
Php_Null = 336,
125+
Php_True = 337,
126+
Php_False = 338;
126127

127128
public const NAMES = [
128129
self::End => '[EOF]',
@@ -169,16 +170,17 @@ final class Token
169170
self::Php_BooleanAnd => "'&&'",
170171
self::Php_AmpersandNotFollowed => "'&'",
171172
self::Php_AmpersandFollowed => "'&'",
173+
self::Php_Not => "'not'",
172174
self::Php_IsEqual => "'=='",
173175
self::Php_IsNotEqual => "'!='",
174176
self::Php_IsIdentical => "'==='",
175177
self::Php_IsNotIdentical => "'!=='",
176178
self::Php_Spaceship => "'<=>'",
177179
self::Php_IsSmallerOrEqual => "'<='",
178180
self::Php_IsGreaterOrEqual => "'>='",
181+
self::Php_In => "'in'",
179182
self::Php_Sl => "'<<'",
180183
self::Php_Sr => "'>>'",
181-
self::Php_In => "'in'",
182184
self::Php_Instanceof => "'instanceof'",
183185
self::Php_Inc => "'++'",
184186
self::Php_Dec => "'--'",

tests/phpLexer/names.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ __halt_compiler();
5656
#10:8 Php_Whitespace '\n'
5757
#11:1 Php_Identifier 'aaa--bbb'
5858
#11:9 Php_Whitespace '\n'
59-
#12:1 Php_Identifier 'not'
59+
#12:1 Php_Not 'not'
6060
#12:4 Php_Dec '--'
6161
#12:6 '-'
6262
#12:7 Php_Identifier 'name'

tests/phpLexer/operators.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ $test = <<<'XX'
4444
$a xor $b;
4545
$b && 2;
4646
$b || 1;
47+
48+
!$a;
49+
not $a;
4750
XX;
4851

4952
$tokens = (new TagLexer)->tokenize($test);
@@ -268,4 +271,13 @@ __halt_compiler();
268271
#34:6 Php_Whitespace ' '
269272
#34:7 Php_Integer '1'
270273
#34:8 ';'
271-
#34:9 End ''
274+
#34:9 Php_Whitespace '\n\n'
275+
#36:1 '!'
276+
#36:2 Php_Variable '$a'
277+
#36:4 ';'
278+
#36:5 Php_Whitespace '\n'
279+
#37:1 Php_Not 'not'
280+
#37:4 Php_Whitespace ' '
281+
#37:5 Php_Variable '$a'
282+
#37:7 ';'
283+
#37:8 End ''

tests/phpParser/in.phpt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $test = <<<'XX'
1313
1414
/* precedence */
1515
$a in $b || $c in $d,
16-
$a = $b in $c,
16+
$a = not 10 + 20 in $c,
1717
XX;
1818

1919
$node = parseCode($test);
@@ -68,13 +68,23 @@ Latte\Compiler\Nodes\Php\Expression\ArrayNode
6868
| | | var: Latte\Compiler\Nodes\Php\Expression\VariableNode
6969
| | | | name: 'a'
7070
| | | | position: 5:1 (offset 50)
71-
| | | expr: Latte\Compiler\Nodes\Php\Expression\InRangeNode
72-
| | | | needle: Latte\Compiler\Nodes\Php\Expression\VariableNode
73-
| | | | | name: 'b'
74-
| | | | | position: 5:6 (offset 55)
75-
| | | | haystack: Latte\Compiler\Nodes\Php\Expression\VariableNode
76-
| | | | | name: 'c'
77-
| | | | | position: 5:12 (offset 61)
71+
| | | expr: Latte\Compiler\Nodes\Php\Expression\NotNode
72+
| | | | expr: Latte\Compiler\Nodes\Php\Expression\InRangeNode
73+
| | | | | needle: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
74+
| | | | | | left: Latte\Compiler\Nodes\Php\Scalar\IntegerNode
75+
| | | | | | | value: 10
76+
| | | | | | | kind: 10
77+
| | | | | | | position: 5:10 (offset 59)
78+
| | | | | | operator: '+'
79+
| | | | | | right: Latte\Compiler\Nodes\Php\Scalar\IntegerNode
80+
| | | | | | | value: 20
81+
| | | | | | | kind: 10
82+
| | | | | | | position: 5:15 (offset 64)
83+
| | | | | | position: 5:10 (offset 59)
84+
| | | | | haystack: Latte\Compiler\Nodes\Php\Expression\VariableNode
85+
| | | | | | name: 'c'
86+
| | | | | | position: 5:21 (offset 70)
87+
| | | | | position: 5:10 (offset 59)
7888
| | | | position: 5:6 (offset 55)
7989
| | | byRef: false
8090
| | | position: 5:1 (offset 50)

tests/phpParser/logic.phpt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ $test = <<<'XX'
2626
2727
$a = $b || $c,
2828
$a = $b or $c,
29+
30+
not $a > $b && $c == $d,
2931
XX;
3032

3133
$node = parseCode($test);
@@ -37,7 +39,7 @@ Assert::same(
3739

3840
__halt_compiler();
3941
Latte\Compiler\Nodes\Php\Expression\ArrayNode
40-
items: array (11)
42+
items: array (12)
4143
| 0 => Latte\Compiler\Nodes\Php\Expression\ArrayItemNode
4244
| | value: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
4345
| | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
@@ -222,4 +224,32 @@ Latte\Compiler\Nodes\Php\Expression\ArrayNode
222224
| | byRef: false
223225
| | unpack: false
224226
| | position: 17:1 (offset 180)
227+
| 11 => Latte\Compiler\Nodes\Php\Expression\ArrayItemNode
228+
| | value: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
229+
| | | left: Latte\Compiler\Nodes\Php\Expression\NotNode
230+
| | | | expr: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
231+
| | | | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
232+
| | | | | | name: 'a'
233+
| | | | | | position: 19:5 (offset 200)
234+
| | | | | operator: '>'
235+
| | | | | right: Latte\Compiler\Nodes\Php\Expression\VariableNode
236+
| | | | | | name: 'b'
237+
| | | | | | position: 19:10 (offset 205)
238+
| | | | | position: 19:5 (offset 200)
239+
| | | | position: 19:1 (offset 196)
240+
| | | operator: '&&'
241+
| | | right: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
242+
| | | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
243+
| | | | | name: 'c'
244+
| | | | | position: 19:16 (offset 211)
245+
| | | | operator: '=='
246+
| | | | right: Latte\Compiler\Nodes\Php\Expression\VariableNode
247+
| | | | | name: 'd'
248+
| | | | | position: 19:22 (offset 217)
249+
| | | | position: 19:16 (offset 211)
250+
| | | position: 19:1 (offset 196)
251+
| | key: null
252+
| | byRef: false
253+
| | unpack: false
254+
| | position: 19:1 (offset 196)
225255
position: null

tests/phpPrint/operators.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ $test = <<<'XX'
7878
$a instanceof $b,
7979
8080
$a in $b,
81+
!$a in $b && not $a + 2 in $b,
82+
83+
not $a,
84+
not $a > $b && not $c == not $d,
8185
XX;
8286

8387
$node = parseCode($test);
@@ -150,4 +154,7 @@ $a xor $b,
150154
$a or $b,
151155
$a instanceof Foo,
152156
$a instanceof $b,
153-
in_array($a, $b, true)
157+
in_array($a, $b, true),
158+
in_array(!$a, $b, true) && !in_array($a + 2, $b, true),
159+
!$a,
160+
!($a > $b) && !($c == !$d)

0 commit comments

Comments
 (0)