Skip to content

Commit

Permalink
added operator 'not'
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 28, 2022
1 parent 304492a commit c26220e
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 326 deletions.
1 change: 1 addition & 0 deletions src/Latte/Compiler/TagLexer.php
Expand Up @@ -35,6 +35,7 @@ final class TagLexer
'null' => Token::Php_Null,
'true' => Token::Php_True,
'false' => Token::Php_False,
'not' => Token::Php_Not,
];

private const KeywordsFollowed = [ // must follows ( & =
Expand Down
509 changes: 255 additions & 254 deletions src/Latte/Compiler/TagParserData.php

Large diffs are not rendered by default.

122 changes: 62 additions & 60 deletions src/Latte/Compiler/Token.php
Expand Up @@ -64,65 +64,66 @@ final class Token
Php_BooleanAnd = 276,
Php_AmpersandNotFollowed = 277,
Php_AmpersandFollowed = 278,
Php_IsEqual = 279,
Php_IsNotEqual = 280,
Php_IsIdentical = 281,
Php_IsNotIdentical = 282,
Php_Spaceship = 283,
Php_IsSmallerOrEqual = 284,
Php_IsGreaterOrEqual = 285,
Php_Sl = 286,
Php_Sr = 287,
Php_In = 288,
Php_Instanceof = 289,
Php_Inc = 290,
Php_Dec = 291,
Php_IntCast = 292,
Php_FloatCast = 293,
Php_StringCast = 294,
Php_ArrayCast = 295,
Php_ObjectCast = 296,
Php_BoolCast = 297,
Php_Pow = 298,
Php_New = 299,
Php_Clone = 300,
Php_Integer = 301,
Php_Float = 302,
Php_Identifier = 303,
Php_StringVarname = 304,
Php_Constant = 305,
Php_Variable = 306,
Php_NumString = 307,
Php_EncapsedAndWhitespace = 308,
Php_ConstantEncapsedString = 309,
Php_Match = 310,
Php_Default = 311,
Php_Function = 312,
Php_Fn = 313,
Php_Return = 314,
Php_Use = 315,
Php_Isset = 316,
Php_Empty = 317,
Php_ObjectOperator = 318,
Php_NullsafeObjectOperator = 319,
Php_UndefinedsafeObjectOperator = 320,
Php_List = 321,
Php_Array = 322,
Php_StartHeredoc = 323,
Php_EndHeredoc = 324,
Php_DollarOpenCurlyBraces = 325,
Php_CurlyOpen = 326,
Php_PaamayimNekudotayim = 327,
Php_NsSeparator = 328,
Php_Ellipsis = 329,
Php_ExpandCast = 330,
Php_NameFullyQualified = 331,
Php_NameQualified = 332,
Php_Whitespace = 333,
Php_Comment = 334,
Php_Null = 335,
Php_True = 336,
Php_False = 337;
Php_Not = 279,
Php_IsEqual = 280,
Php_IsNotEqual = 281,
Php_IsIdentical = 282,
Php_IsNotIdentical = 283,
Php_Spaceship = 284,
Php_IsSmallerOrEqual = 285,
Php_IsGreaterOrEqual = 286,
Php_In = 287,
Php_Sl = 288,
Php_Sr = 289,
Php_Instanceof = 290,
Php_Inc = 291,
Php_Dec = 292,
Php_IntCast = 293,
Php_FloatCast = 294,
Php_StringCast = 295,
Php_ArrayCast = 296,
Php_ObjectCast = 297,
Php_BoolCast = 298,
Php_Pow = 299,
Php_New = 300,
Php_Clone = 301,
Php_Integer = 302,
Php_Float = 303,
Php_Identifier = 304,
Php_StringVarname = 305,
Php_Constant = 306,
Php_Variable = 307,
Php_NumString = 308,
Php_EncapsedAndWhitespace = 309,
Php_ConstantEncapsedString = 310,
Php_Match = 311,
Php_Default = 312,
Php_Function = 313,
Php_Fn = 314,
Php_Return = 315,
Php_Use = 316,
Php_Isset = 317,
Php_Empty = 318,
Php_ObjectOperator = 319,
Php_NullsafeObjectOperator = 320,
Php_UndefinedsafeObjectOperator = 321,
Php_List = 322,
Php_Array = 323,
Php_StartHeredoc = 324,
Php_EndHeredoc = 325,
Php_DollarOpenCurlyBraces = 326,
Php_CurlyOpen = 327,
Php_PaamayimNekudotayim = 328,
Php_NsSeparator = 329,
Php_Ellipsis = 330,
Php_ExpandCast = 331,
Php_NameFullyQualified = 332,
Php_NameQualified = 333,
Php_Whitespace = 334,
Php_Comment = 335,
Php_Null = 336,
Php_True = 337,
Php_False = 338;

public const NAMES = [
self::End => '[EOF]',
Expand Down Expand Up @@ -169,16 +170,17 @@ final class Token
self::Php_BooleanAnd => "'&&'",
self::Php_AmpersandNotFollowed => "'&'",
self::Php_AmpersandFollowed => "'&'",
self::Php_Not => "'not'",
self::Php_IsEqual => "'=='",
self::Php_IsNotEqual => "'!='",
self::Php_IsIdentical => "'==='",
self::Php_IsNotIdentical => "'!=='",
self::Php_Spaceship => "'<=>'",
self::Php_IsSmallerOrEqual => "'<='",
self::Php_IsGreaterOrEqual => "'>='",
self::Php_In => "'in'",
self::Php_Sl => "'<<'",
self::Php_Sr => "'>>'",
self::Php_In => "'in'",
self::Php_Instanceof => "'instanceof'",
self::Php_Inc => "'++'",
self::Php_Dec => "'--'",
Expand Down
2 changes: 1 addition & 1 deletion tests/phpLexer/names.phpt
Expand Up @@ -56,7 +56,7 @@ __halt_compiler();
#10:8 Php_Whitespace '\n'
#11:1 Php_Identifier 'aaa--bbb'
#11:9 Php_Whitespace '\n'
#12:1 Php_Identifier 'not'
#12:1 Php_Not 'not'
#12:4 Php_Dec '--'
#12:6 '-'
#12:7 Php_Identifier 'name'
Expand Down
14 changes: 13 additions & 1 deletion tests/phpLexer/operators.phpt
Expand Up @@ -44,6 +44,9 @@ $test = <<<'XX'
$a xor $b;
$b && 2;
$b || 1;
!$a;
not $a;
XX;

$tokens = (new TagLexer)->tokenize($test);
Expand Down Expand Up @@ -268,4 +271,13 @@ __halt_compiler();
#34:6 Php_Whitespace ' '
#34:7 Php_Integer '1'
#34:8 ';'
#34:9 End ''
#34:9 Php_Whitespace '\n\n'
#36:1 '!'
#36:2 Php_Variable '$a'
#36:4 ';'
#36:5 Php_Whitespace '\n'
#37:1 Php_Not 'not'
#37:4 Php_Whitespace ' '
#37:5 Php_Variable '$a'
#37:7 ';'
#37:8 End ''
26 changes: 18 additions & 8 deletions tests/phpParser/in.phpt
Expand Up @@ -13,7 +13,7 @@ $test = <<<'XX'
/* precedence */
$a in $b || $c in $d,
$a = $b in $c,
$a = not 10 + 20 in $c,
XX;

$node = parseCode($test);
Expand Down Expand Up @@ -68,13 +68,23 @@ Latte\Compiler\Nodes\Php\Expression\ArrayNode
| | | var: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | name: 'a'
| | | | position: 5:1 (offset 50)
| | | expr: Latte\Compiler\Nodes\Php\Expression\InRangeNode
| | | | needle: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | name: 'b'
| | | | | position: 5:6 (offset 55)
| | | | haystack: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | name: 'c'
| | | | | position: 5:12 (offset 61)
| | | expr: Latte\Compiler\Nodes\Php\Expression\NotNode
| | | | expr: Latte\Compiler\Nodes\Php\Expression\InRangeNode
| | | | | needle: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
| | | | | | left: Latte\Compiler\Nodes\Php\Scalar\IntegerNode
| | | | | | | value: 10
| | | | | | | kind: 10
| | | | | | | position: 5:10 (offset 59)
| | | | | | operator: '+'
| | | | | | right: Latte\Compiler\Nodes\Php\Scalar\IntegerNode
| | | | | | | value: 20
| | | | | | | kind: 10
| | | | | | | position: 5:15 (offset 64)
| | | | | | position: 5:10 (offset 59)
| | | | | haystack: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | | name: 'c'
| | | | | | position: 5:21 (offset 70)
| | | | | position: 5:10 (offset 59)
| | | | position: 5:6 (offset 55)
| | | byRef: false
| | | position: 5:1 (offset 50)
Expand Down
32 changes: 31 additions & 1 deletion tests/phpParser/logic.phpt
Expand Up @@ -26,6 +26,8 @@ $test = <<<'XX'
$a = $b || $c,
$a = $b or $c,
not $a > $b && $c == $d,
XX;

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

__halt_compiler();
Latte\Compiler\Nodes\Php\Expression\ArrayNode
items: array (11)
items: array (12)
| 0 => Latte\Compiler\Nodes\Php\Expression\ArrayItemNode
| | value: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
| | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
Expand Down Expand Up @@ -222,4 +224,32 @@ Latte\Compiler\Nodes\Php\Expression\ArrayNode
| | byRef: false
| | unpack: false
| | position: 17:1 (offset 180)
| 11 => Latte\Compiler\Nodes\Php\Expression\ArrayItemNode
| | value: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
| | | left: Latte\Compiler\Nodes\Php\Expression\NotNode
| | | | expr: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
| | | | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | | name: 'a'
| | | | | | position: 19:5 (offset 200)
| | | | | operator: '>'
| | | | | right: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | | name: 'b'
| | | | | | position: 19:10 (offset 205)
| | | | | position: 19:5 (offset 200)
| | | | position: 19:1 (offset 196)
| | | operator: '&&'
| | | right: Latte\Compiler\Nodes\Php\Expression\BinaryOpNode
| | | | left: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | name: 'c'
| | | | | position: 19:16 (offset 211)
| | | | operator: '=='
| | | | right: Latte\Compiler\Nodes\Php\Expression\VariableNode
| | | | | name: 'd'
| | | | | position: 19:22 (offset 217)
| | | | position: 19:16 (offset 211)
| | | position: 19:1 (offset 196)
| | key: null
| | byRef: false
| | unpack: false
| | position: 19:1 (offset 196)
position: null
9 changes: 8 additions & 1 deletion tests/phpPrint/operators.phpt
Expand Up @@ -78,6 +78,10 @@ $test = <<<'XX'
$a instanceof $b,
$a in $b,
!$a in $b && not $a + 2 in $b,
not $a,
not $a > $b && not $c == not $d,
XX;

$node = parseCode($test);
Expand Down Expand Up @@ -150,4 +154,7 @@ $a xor $b,
$a or $b,
$a instanceof Foo,
$a instanceof $b,
in_array($a, $b, true)
in_array($a, $b, true),
in_array(!$a, $b, true) && !in_array($a + 2, $b, true),
!$a,
!($a > $b) && !($c == !$d)

0 comments on commit c26220e

Please sign in to comment.