1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace TYPO3Fluid\Fluid\Core\Parser; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file belongs to the package "TYPO3 Fluid". |
7
|
|
|
* See LICENSE.txt that was shipped with this package. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Fluid Contexts |
12
|
|
|
* |
13
|
|
|
* Container (alternative to associative array) which carries individual |
14
|
|
|
* Context objects which provide bit masks used for matching characters, |
15
|
|
|
* and get stacked when the sequencer enters a new context. |
16
|
|
|
*/ |
17
|
|
|
class Contexts |
18
|
|
|
{ |
19
|
|
|
/** @var Context */ |
20
|
|
|
public $root; |
21
|
|
|
|
22
|
|
|
/** @var Context */ |
23
|
|
|
public $inline; |
24
|
|
|
|
25
|
|
|
/** @var Context */ |
26
|
|
|
public $tag; |
27
|
|
|
|
28
|
|
|
/** @var Context */ |
29
|
|
|
public $data; |
30
|
|
|
|
31
|
|
|
/** @var Context */ |
32
|
|
|
public $toggle; |
33
|
|
|
|
34
|
|
|
/** @var Context */ |
35
|
|
|
public $array; |
36
|
|
|
|
37
|
|
|
/** @var Context */ |
38
|
|
|
public $quoted; |
39
|
|
|
|
40
|
|
|
/** @var Context */ |
41
|
|
|
public $attributes; |
42
|
|
|
|
43
|
|
|
/** @var Context */ |
44
|
|
|
public $dead; |
45
|
|
|
|
46
|
|
|
/** @var Context */ |
47
|
|
|
public $protected; |
48
|
|
|
|
49
|
|
|
/** @var Context */ |
50
|
|
|
public $accessor; |
51
|
|
|
|
52
|
|
|
/** @var Context */ |
53
|
|
|
public $empty; |
54
|
|
|
|
55
|
|
|
/** @var Context */ |
56
|
|
|
public $boolean; |
57
|
|
|
|
58
|
|
|
/** @var Context */ |
59
|
|
|
public $inactive; |
60
|
|
|
|
61
|
|
|
public function __construct() |
62
|
|
|
{ |
63
|
|
|
// Root context: aware of tag start or inline start only, and escapes (to ignore next symbol). |
64
|
|
|
$this->root = new Context(Context::CONTEXT_ROOT, '{<\\'); |
65
|
|
|
|
66
|
|
|
// Inline context: aware of array syntax, sub-inline syntax, inline VH syntax, and arguments enclosed by parenthesis by looking for parenthesis start |
67
|
|
|
$this->inline = new Context(Context::CONTEXT_INLINE, "@(->[]|{}:,=|\\\t\n\r\0'\"` "); |
68
|
|
|
|
69
|
|
|
// Tag: entered into when a detected tag has a namespace operator in tag name |
70
|
|
|
$this->tag = new Context(Context::CONTEXT_TAG, "[>:{ /\t\n\r\0"); |
71
|
|
|
|
72
|
|
|
// P/CDATA: entered into when a detected tag starts with ![CDATA[ or ![PCDATA[ - exclusively matches end of tag. |
73
|
|
|
$this->data = new Context(Context::CONTEXT_DATA, '>'); |
74
|
|
|
|
75
|
|
|
// Fluid feature toggles: an inline prefixed with at sign, e.g. {@escaping off}, which supports only whitespace and ending curly brace symbols. |
76
|
|
|
$this->toggle = new Context(Context::CONTEXT_TOGGLE, ' }'); |
77
|
|
|
|
78
|
|
|
// Parenthesis context: aware of separators, key/value assignments, the end of a parenthesis and quotation marks. Is used for both |
79
|
|
|
// parenthesis arguments for inline syntax and tag attribute arguments for tag syntax. |
80
|
|
|
$this->array = new Context(Context::CONTEXT_ARRAY, ":,]}=\"'`[{)\\ \t\r\n"); |
81
|
|
|
|
82
|
|
|
// Quoted: entered into when a quote mark (single or double) is encountered (in an array which includes in tag arguments) |
83
|
|
|
$this->quoted = new Context(Context::CONTEXT_QUOTED, '\\"\'{[`'); |
84
|
|
|
|
85
|
|
|
// Attributes: identical to array, except does not ignore whitespace and does not split on array [] characters |
86
|
|
|
$this->attributes = new Context(Context::CONTEXT_ATTRIBUTES, " >:{\"'/,=\t\r\n}"); |
87
|
|
|
|
88
|
|
|
// Dead tag: continues indexing until the tag ends or an inline expression is encountered |
89
|
|
|
$this->dead = new Context(Context::CONTEXT_DEAD, '>{'); |
90
|
|
|
|
91
|
|
|
// Inline protection mode: reacts to backtick and curly brace start and end, but ignores nested curly braces. Backtick enters quoted context. Still allows expressions to match. |
92
|
|
|
$this->protected = new Context(Context::CONTEXT_PROTECTED, ' {}`'); |
93
|
|
|
|
94
|
|
|
// Inline accessor mode: identical to protected context but identifiable under its own name to distinguish it from protected |
95
|
|
|
$this->accessor = new Context(Context::CONTEXT_ACCESSOR, '{}`'); |
96
|
|
|
|
97
|
|
|
// Empty: matches no characters, only possible yield is BYTE_NULL. |
98
|
|
|
$this->empty = new Context(Context::CONTEXT_EMPTY, ''); |
99
|
|
|
|
100
|
|
|
// Boolean: matches parenthesis groups, backslash, inline expressions, quotes and whitespace (which separates expression parts but is not quoted). |
101
|
|
|
$this->boolean = new Context(Context::CONTEXT_BOOLEAN, "{()'\"\\ \t\r\n"); |
102
|
|
|
|
103
|
|
|
// Inactive: a context that will only match tag open and close, ignoring everything else |
104
|
|
|
$this->inactive = new Context(Context::CONTEXT_INACTIVE, '<>'); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|