@vituum/vite-plugin-latte 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/handler.js +9 -0
- package/index.js +138 -0
- package/index.php +173 -0
- package/latte/AssetFilter.php +11 -0
- package/latte/FetchFunction.php +28 -0
- package/latte/IconFilter.php +14 -0
- package/latte/JsonTag.php +64 -0
- package/latte/PlaceholderFunction.php +11 -0
- package/latte/RandomColorFunction.php +14 -0
- package/latte/TelFilter.php +22 -0
- package/package.json +35 -0
- package/vendor/autoload.php +7 -0
- package/vendor/bin/latte-lint +107 -0
- package/vendor/composer/ClassLoader.php +572 -0
- package/vendor/composer/InstalledVersions.php +350 -0
- package/vendor/composer/LICENSE +21 -0
- package/vendor/composer/autoload_classmap.php +183 -0
- package/vendor/composer/autoload_namespaces.php +9 -0
- package/vendor/composer/autoload_psr4.php +9 -0
- package/vendor/composer/autoload_real.php +57 -0
- package/vendor/composer/autoload_static.php +193 -0
- package/vendor/composer/installed.json +93 -0
- package/vendor/composer/installed.php +32 -0
- package/vendor/composer/platform_check.php +26 -0
- package/vendor/latte/latte/bin/latte-lint +29 -0
- package/vendor/latte/latte/composer.json +53 -0
- package/vendor/latte/latte/license.md +60 -0
- package/vendor/latte/latte/ncs.php +14 -0
- package/vendor/latte/latte/ncs.xml +9 -0
- package/vendor/latte/latte/readme.md +21 -0
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
- package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
- package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
- package/vendor/latte/latte/src/Latte/Engine.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
- package/vendor/latte/latte/src/Latte/Extension.php +97 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
- package/vendor/latte/latte/src/Latte/Loader.php +37 -0
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
- package/vendor/latte/latte/src/Latte/Policy.php +24 -0
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
- package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
- package/vendor/latte/latte/src/Latte/Strict.php +101 -0
- package/vendor/latte/latte/src/Latte/attributes.php +24 -0
- package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
- package/vendor/latte/latte/src/Tools/Linter.php +175 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Compiler;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\Compiler\Nodes\Php as Node;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\Expression;
|
|
15
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
16
|
+
use Latte\Compiler\Nodes\Php\NameNode;
|
|
17
|
+
use Latte\Compiler\Nodes\Php\Scalar;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parser for PHP-like expression language used in tags.
|
|
22
|
+
* Based on works by Nikita Popov, Moriyoshi Koizumi and Masato Bito.
|
|
23
|
+
*/
|
|
24
|
+
final class TagParser extends TagParserData
|
|
25
|
+
{
|
|
26
|
+
use Latte\Strict;
|
|
27
|
+
|
|
28
|
+
private const
|
|
29
|
+
SchemaExpression = 'e',
|
|
30
|
+
SchemaArguments = 'a',
|
|
31
|
+
SchemaFilters = 'm';
|
|
32
|
+
|
|
33
|
+
private const SymbolNone = -1;
|
|
34
|
+
|
|
35
|
+
public TokenStream /*readonly*/ $stream;
|
|
36
|
+
public string $text;
|
|
37
|
+
private int /*readonly*/ $offsetDelta;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
public function __construct(array $tokens)
|
|
41
|
+
{
|
|
42
|
+
$this->offsetDelta = $tokens[0]->position->offset ?? 0;
|
|
43
|
+
$tokens = $this->filterTokens($tokens);
|
|
44
|
+
$this->stream = new TokenStream(new \ArrayIterator($tokens));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
public function parseExpression(): ExpressionNode
|
|
49
|
+
{
|
|
50
|
+
return $this->parse(self::SchemaExpression, recovery: true);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public function parseArguments(): Expression\ArrayNode
|
|
55
|
+
{
|
|
56
|
+
return $this->parse(self::SchemaArguments, recovery: true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
public function parseModifier(): Node\ModifierNode
|
|
61
|
+
{
|
|
62
|
+
return $this->isEnd()
|
|
63
|
+
? new Node\ModifierNode([])
|
|
64
|
+
: $this->parse(self::SchemaFilters);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
public function isEnd(): bool
|
|
69
|
+
{
|
|
70
|
+
return $this->stream->peek()->isEnd();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
public function parseUnquotedStringOrExpression(bool $colon = true): ExpressionNode
|
|
75
|
+
{
|
|
76
|
+
$position = $this->stream->peek()->position;
|
|
77
|
+
$lexer = new TagLexer;
|
|
78
|
+
$tokens = $lexer->tokenizeUnquotedString($this->text, $position, $colon, $this->offsetDelta);
|
|
79
|
+
|
|
80
|
+
if (!$tokens) {
|
|
81
|
+
return $this->parseExpression();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
$parser = new self($tokens);
|
|
85
|
+
$end = $position->offset + strlen($parser->text) - 2; // 2 quotes
|
|
86
|
+
do {
|
|
87
|
+
$this->stream->consume();
|
|
88
|
+
} while ($this->stream->peek()->position->offset < $end);
|
|
89
|
+
|
|
90
|
+
return $parser->parseExpression();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
public function tryConsumeModifier(string ...$modifiers): ?Token
|
|
95
|
+
{
|
|
96
|
+
$token = $this->stream->peek();
|
|
97
|
+
return $token->is(...$modifiers) // is followed by whitespace
|
|
98
|
+
&& $this->stream->peek(1)->position->offset > $token->position->offset + strlen($token->text)
|
|
99
|
+
? $this->stream->consume()
|
|
100
|
+
: null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
public function parseType(): ?Node\SuperiorTypeNode
|
|
105
|
+
{
|
|
106
|
+
$kind = [
|
|
107
|
+
Token::Php_Identifier, Token::Php_Constant, Token::Php_Ellipsis, Token::Php_Array, Token::Php_Integer,
|
|
108
|
+
Token::Php_NameFullyQualified, Token::Php_NameQualified, Token::Php_Null, Token::Php_False,
|
|
109
|
+
'(', ')', '<', '>', '[', ']', '|', '&', '{', '}', ':', ',', '=', '?',
|
|
110
|
+
];
|
|
111
|
+
$res = null;
|
|
112
|
+
while ($token = $this->stream->tryConsume(...$kind)) {
|
|
113
|
+
$res .= $token->text;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return $res ? new Node\SuperiorTypeNode($res) : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
/** @throws Latte\CompileException */
|
|
121
|
+
private function parse(string $schema, bool $recovery = false): mixed
|
|
122
|
+
{
|
|
123
|
+
$symbol = self::SymbolNone; // We start off with no lookahead-token
|
|
124
|
+
$this->startTokenStack = []; // Keep stack of start token
|
|
125
|
+
$token = null;
|
|
126
|
+
$state = 0; // Start off in the initial state and keep a stack of previous states
|
|
127
|
+
$stateStack = [$state];
|
|
128
|
+
$this->semStack = []; // Semantic value stack (contains values of tokens and semantic action results)
|
|
129
|
+
$stackPos = 0; // Current position in the stack(s)
|
|
130
|
+
|
|
131
|
+
do {
|
|
132
|
+
if (self::ActionBase[$state] === 0) {
|
|
133
|
+
$rule = self::ActionDefault[$state];
|
|
134
|
+
} else {
|
|
135
|
+
if ($symbol === self::SymbolNone) {
|
|
136
|
+
$recovery = $recovery
|
|
137
|
+
? [$this->stream->getIndex(), $state, $stateStack, $stackPos, $this->semValue, $this->semStack, $this->startTokenStack]
|
|
138
|
+
: null;
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if ($token) {
|
|
142
|
+
$prevToken = $token;
|
|
143
|
+
$token = $this->stream->consume();
|
|
144
|
+
} else {
|
|
145
|
+
$token = new Token(ord($schema), $schema);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
recovery:
|
|
149
|
+
$symbol = self::TokenToSymbol[$token->type];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
$idx = self::ActionBase[$state] + $symbol;
|
|
153
|
+
if ((($idx >= 0 && $idx < count(self::Action) && self::ActionCheck[$idx] === $symbol)
|
|
154
|
+
|| ($state < self::Yy2Tblstate
|
|
155
|
+
&& ($idx = self::ActionBase[$state + self::NumNonLeafStates] + $symbol) >= 0
|
|
156
|
+
&& $idx < count(self::Action) && self::ActionCheck[$idx] === $symbol))
|
|
157
|
+
&& ($action = self::Action[$idx]) !== self::DefaultAction
|
|
158
|
+
) {
|
|
159
|
+
/*
|
|
160
|
+
>= numNonLeafStates: shift and reduce
|
|
161
|
+
> 0: shift
|
|
162
|
+
= 0: accept
|
|
163
|
+
< 0: reduce
|
|
164
|
+
= -YYUNEXPECTED: error
|
|
165
|
+
*/
|
|
166
|
+
if ($action > 0) { // shift
|
|
167
|
+
++$stackPos;
|
|
168
|
+
$stateStack[$stackPos] = $state = $action;
|
|
169
|
+
$this->semStack[$stackPos] = $token->text;
|
|
170
|
+
$this->startTokenStack[$stackPos] = $token;
|
|
171
|
+
$symbol = self::SymbolNone;
|
|
172
|
+
if ($action < self::NumNonLeafStates) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
$rule = $action - self::NumNonLeafStates; // shift-and-reduce
|
|
177
|
+
} else {
|
|
178
|
+
$rule = -$action;
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
$rule = self::ActionDefault[$state];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
do {
|
|
186
|
+
if ($rule === 0) { // accept
|
|
187
|
+
return $this->semValue;
|
|
188
|
+
|
|
189
|
+
} elseif ($rule !== self::UnexpectedTokenRule) { // reduce
|
|
190
|
+
$this->reduce($rule, $stackPos);
|
|
191
|
+
|
|
192
|
+
// Goto - shift nonterminal
|
|
193
|
+
$ruleLength = self::RuleToLength[$rule];
|
|
194
|
+
$stackPos -= $ruleLength;
|
|
195
|
+
$nonTerminal = self::RuleToNonTerminal[$rule];
|
|
196
|
+
$idx = self::GotoBase[$nonTerminal] + $stateStack[$stackPos];
|
|
197
|
+
if ($idx >= 0 && $idx < count(self::Goto) && self::GotoCheck[$idx] === $nonTerminal) {
|
|
198
|
+
$state = self::Goto[$idx];
|
|
199
|
+
} else {
|
|
200
|
+
$state = self::GotoDefault[$nonTerminal];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
++$stackPos;
|
|
204
|
+
$stateStack[$stackPos] = $state;
|
|
205
|
+
$this->semStack[$stackPos] = $this->semValue;
|
|
206
|
+
if ($ruleLength === 0) {
|
|
207
|
+
$this->startTokenStack[$stackPos] = $token;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
} else { // error
|
|
211
|
+
if ($prevToken->is('echo', 'print', 'return', 'yield', 'throw', 'if', 'foreach', 'unset')) {
|
|
212
|
+
throw new Latte\CompileException("Keyword '$prevToken->text' is forbidden in Latte", $prevToken->position);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if ($recovery && $this->isExpectedEof($state)) {
|
|
216
|
+
[, $state, $stateStack, $stackPos, $this->semValue, $this->semStack, $this->startTokenStack] = $recovery;
|
|
217
|
+
$this->stream->seek($recovery[0]);
|
|
218
|
+
$token = new Token(Token::End, '');
|
|
219
|
+
goto recovery;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
throw new Latte\CompileException('Unexpected ' . ($token->text ? "'$token->text'" : 'end'), $token->position);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if ($state < self::NumNonLeafStates) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
$rule = $state - self::NumNonLeafStates; // shift-and-reduce
|
|
230
|
+
} while (true);
|
|
231
|
+
} while (true);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Can EOF be the next token?
|
|
237
|
+
*/
|
|
238
|
+
private function isExpectedEof(int $state): bool
|
|
239
|
+
{
|
|
240
|
+
foreach (self::SymbolToName as $symbol => $name) {
|
|
241
|
+
$idx = self::ActionBase[$state] + $symbol;
|
|
242
|
+
if (($idx >= 0 && $idx < count(self::Action) && self::ActionCheck[$idx] === $symbol
|
|
243
|
+
|| $state < self::Yy2Tblstate
|
|
244
|
+
&& ($idx = self::ActionBase[$state + self::NumNonLeafStates] + $symbol) >= 0
|
|
245
|
+
&& $idx < count(self::Action) && self::ActionCheck[$idx] === $symbol)
|
|
246
|
+
&& self::Action[$idx] !== self::UnexpectedTokenRule
|
|
247
|
+
&& self::Action[$idx] !== self::DefaultAction
|
|
248
|
+
&& $symbol === 0
|
|
249
|
+
) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
protected static function handleBuiltinTypes(NameNode $name): NameNode|Node\IdentifierNode
|
|
259
|
+
{
|
|
260
|
+
$builtinTypes = [
|
|
261
|
+
'bool' => true, 'int' => true, 'float' => true, 'string' => true, 'iterable' => true, 'void' => true,
|
|
262
|
+
'object' => true, 'null' => true, 'false' => true, 'mixed' => true, 'never' => true,
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
$lowerName = strtolower($name->toCodeString());
|
|
266
|
+
return isset($builtinTypes[$lowerName])
|
|
267
|
+
? new Node\IdentifierNode($lowerName, $name->position)
|
|
268
|
+
: $name;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
protected static function parseOffset(string $str, Position $position): Scalar\StringNode|Scalar\IntegerNode
|
|
273
|
+
{
|
|
274
|
+
if (!preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) {
|
|
275
|
+
return new Scalar\StringNode($str, $position);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
$num = +$str;
|
|
279
|
+
if (!is_int($num)) {
|
|
280
|
+
return new Scalar\StringNode($str, $position);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return new Scalar\IntegerNode($num, Scalar\IntegerNode::KindDecimal, $position);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
/** @param ExpressionNode[] $parts */
|
|
288
|
+
protected function parseDocString(
|
|
289
|
+
string $startToken,
|
|
290
|
+
array $parts,
|
|
291
|
+
string $endToken,
|
|
292
|
+
Position $startPos,
|
|
293
|
+
Position $endPos,
|
|
294
|
+
): Scalar\StringNode|Scalar\EncapsedStringNode {
|
|
295
|
+
$hereDoc = !str_contains($startToken, "'");
|
|
296
|
+
preg_match('/\A[ \t]*/', $endToken, $matches);
|
|
297
|
+
$indentation = $matches[0];
|
|
298
|
+
if (str_contains($indentation, ' ') && str_contains($indentation, "\t")) {
|
|
299
|
+
throw new CompileException('Invalid indentation - tabs and spaces cannot be mixed', $endPos);
|
|
300
|
+
|
|
301
|
+
} elseif (!$parts) {
|
|
302
|
+
return new Scalar\StringNode('', $startPos);
|
|
303
|
+
|
|
304
|
+
} elseif (!$parts[0] instanceof Scalar\EncapsedStringPartNode) {
|
|
305
|
+
// If there is no leading encapsed string part, pretend there is an empty one
|
|
306
|
+
$this->stripIndentation('', $indentation, true, false, $parts[0]->position);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
$newParts = [];
|
|
310
|
+
foreach ($parts as $i => $part) {
|
|
311
|
+
if ($part instanceof Scalar\EncapsedStringPartNode) {
|
|
312
|
+
$isLast = $i === \count($parts) - 1;
|
|
313
|
+
$part->value = $this->stripIndentation(
|
|
314
|
+
$part->value,
|
|
315
|
+
$indentation,
|
|
316
|
+
$i === 0,
|
|
317
|
+
$isLast,
|
|
318
|
+
$part->position,
|
|
319
|
+
);
|
|
320
|
+
if ($isLast) {
|
|
321
|
+
$part->value = preg_replace('~(\r\n|\n|\r)\z~', '', $part->value);
|
|
322
|
+
}
|
|
323
|
+
if ($hereDoc) {
|
|
324
|
+
$part->value = PhpHelpers::decodeEscapeSequences($part->value, null);
|
|
325
|
+
}
|
|
326
|
+
if ($i === 0 && $isLast) {
|
|
327
|
+
return new Scalar\StringNode($part->value, $startPos);
|
|
328
|
+
}
|
|
329
|
+
if ($part->value === '') {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
$newParts[] = $part;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return new Scalar\EncapsedStringNode($newParts, $startPos);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
private function stripIndentation(
|
|
341
|
+
string $str,
|
|
342
|
+
string $indentation,
|
|
343
|
+
bool $atStart,
|
|
344
|
+
bool $atEnd,
|
|
345
|
+
Position $position,
|
|
346
|
+
): string {
|
|
347
|
+
if ($indentation === '') {
|
|
348
|
+
return $str;
|
|
349
|
+
}
|
|
350
|
+
$start = $atStart ? '(?:(?<=\n)|\A)' : '(?<=\n)';
|
|
351
|
+
$end = $atEnd ? '(?:(?=[\r\n])|\z)' : '(?=[\r\n])';
|
|
352
|
+
$regex = '/' . $start . '([ \t]*)(' . $end . ')?/D';
|
|
353
|
+
return preg_replace_callback(
|
|
354
|
+
$regex,
|
|
355
|
+
function ($matches) use ($indentation, $position) {
|
|
356
|
+
$indentLen = \strlen($indentation);
|
|
357
|
+
$prefix = substr($matches[1], 0, $indentLen);
|
|
358
|
+
if (str_contains($prefix, $indentation[0] === ' ' ? "\t" : ' ')) {
|
|
359
|
+
throw new CompileException('Invalid indentation - tabs and spaces cannot be mixed', $position);
|
|
360
|
+
} elseif (strlen($prefix) < $indentLen && !isset($matches[2])) {
|
|
361
|
+
throw new CompileException(
|
|
362
|
+
'Invalid body indentation level ' .
|
|
363
|
+
'(expecting an indentation level of at least ' . $indentLen . ')',
|
|
364
|
+
$position,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
return substr($matches[0], strlen($prefix));
|
|
368
|
+
},
|
|
369
|
+
$str,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
/** @param Token[] $tokens */
|
|
375
|
+
private function filterTokens(array $tokens): array
|
|
376
|
+
{
|
|
377
|
+
$this->text = '';
|
|
378
|
+
$res = [];
|
|
379
|
+
foreach ($tokens as $token) {
|
|
380
|
+
$this->text .= $token->text;
|
|
381
|
+
if (!$token->is(Token::Php_Whitespace, Token::Php_Comment)) {
|
|
382
|
+
$res[] = $token;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return $res;
|
|
387
|
+
}
|
|
388
|
+
}
|