Skip to content

Commit d8da1a4

Browse files
feat: add comprehensive language features and improve parser architecture
- Add new statement types: call, filter, break, continue with proper parsing - Add ternary expressions and improved if-else parsing with elif support - Add spread expressions (*args) for function argument unpacking - Add string concatenation support with multiple string literals - Add new string manipulation filters: capitalize, replace, split with maxsplit - Add enhanced startswith/endswith filters supporting tuple arguments - Add items, keys, values methods for object iteration - Add string concatenation operator (~) for template building - Add comment support with {# #} syntax - Add proper numeric type handling with IntegerValue and FloatValue - Add support for both lowercase and uppercase boolean literals (true/false, True/False) - Add null literal support (none, None) - Improve parser architecture with better statement detection and identifier handling - Refactor token handling to use string-based keywords instead of enum types - Add proper error handling for missing identifiers and statements - Improve member expression parsing with better computed property detection - Add support for complex nested expressions and chained method calls
1 parent d706a8d commit d8da1a4

32 files changed

Lines changed: 887 additions & 515 deletions

src/AST/ArrayLiteral.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
/**
99
* Represents an array literal in the template.
1010
*/
11-
class ArrayLiteral extends Literal {
11+
class ArrayLiteral extends Literal
12+
{
1213
public string $type = "ArrayLiteral";
1314

1415
/**
@@ -18,4 +19,4 @@ public function __construct(array $value)
1819
{
1920
parent::__construct($value);
2021
}
21-
}
22+
}

src/AST/BooleanLiteral.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/AST/CallStatement.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codewithkyrian\Jinja\AST;
6+
7+
class CallStatement extends Statement
8+
{
9+
public string $type = "CallStatement";
10+
11+
/**
12+
* @param CallExpression $call
13+
* @param Expression[]|null $args
14+
* @param Statement[] $body
15+
*/
16+
public function __construct(public CallExpression $call, public ?array $args, public array $body) {}
17+
}

src/AST/Comment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codewithkyrian\Jinja\AST;
6+
7+
class Comment extends Statement
8+
{
9+
public string $type = "Comment";
10+
11+
public function __construct(public string $value) {}
12+
}

src/AST/FilterStatement.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codewithkyrian\Jinja\AST;
6+
7+
class FilterStatement extends Statement
8+
{
9+
public string $type = "FilterStatement";
10+
11+
/**
12+
* @param Identifier|CallExpression $filter
13+
* @param Statement[] $body
14+
*/
15+
public function __construct(public Identifier|CallExpression $filter, public array $body) {}
16+
}

src/AST/FloatLiteral.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codewithkyrian\Jinja\AST;
6+
7+
class FloatLiteral extends Literal
8+
{
9+
public string $type = "FloatLiteral";
10+
11+
public function __construct(float $value)
12+
{
13+
parent::__construct($value);
14+
}
15+
}

src/AST/IntegerLiteral.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Codewithkyrian\Jinja\AST;
6+
7+
class IntegerLiteral extends Literal
8+
{
9+
public string $type = "IntegerLiteral";
10+
11+
public function __construct(int $value)
12+
{
13+
parent::__construct($value);
14+
}
15+
}

src/AST/Literal.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ abstract class Literal extends Expression
1313
{
1414
public string $type = "Literal";
1515

16-
public function __construct(public mixed $value)
17-
{
18-
}
19-
}
16+
public function __construct(public $value) {}
17+
}

src/AST/LogicalNegationExpression.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/AST/MemberExpression.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
declare(strict_types=1);
44

5-
65
namespace Codewithkyrian\Jinja\AST;
76

87
class MemberExpression extends Expression
@@ -12,7 +11,6 @@ class MemberExpression extends Expression
1211
public function __construct(
1312
public Expression $object,
1413
public Expression $property,
15-
public bool $computed)
16-
{
17-
}
18-
}
14+
public bool $computed
15+
) {}
16+
}

0 commit comments

Comments
 (0)