1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TYPO3Fluid\Fluid\Core\Parser; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Fluid Contexts |
8
|
|
|
* |
9
|
|
|
* Container (alternative to associative array) which carries individual |
10
|
|
|
* Context objects which provide bit masks used for matching characters, |
11
|
|
|
* and get stacked when the sequencer enters a new context. |
12
|
|
|
*/ |
13
|
|
|
class Contexts |
14
|
|
|
{ |
15
|
|
|
/** @var Context */ |
16
|
|
|
public $root; |
17
|
|
|
|
18
|
|
|
/** @var Context */ |
19
|
|
|
public $inline; |
20
|
|
|
|
21
|
|
|
/** @var Context */ |
22
|
|
|
public $tag; |
23
|
|
|
|
24
|
|
|
/** @var Context */ |
25
|
|
|
public $array; |
26
|
|
|
|
27
|
|
|
/** @var Context */ |
28
|
|
|
public $quoted; |
29
|
|
|
|
30
|
|
|
/** @var Context */ |
31
|
|
|
public $attributes; |
32
|
|
|
|
33
|
|
|
/** @var Context */ |
34
|
|
|
public $dead; |
35
|
|
|
|
36
|
|
|
/** @var Context */ |
37
|
|
|
public $protected; |
38
|
|
|
|
39
|
|
|
/** @var Context */ |
40
|
|
|
public $accessor; |
41
|
|
|
|
42
|
|
|
public function __construct() |
43
|
|
|
{ |
44
|
|
|
// Root context: aware of tag start or inline start only. |
45
|
|
|
$this->root = new Context(Context::CONTEXT_ROOT, '{<'); |
46
|
|
|
|
47
|
|
|
// Inline context: aware of array syntax, sub-inline syntax, inline VH syntax, and arguments enclosed by parenthesis by looking for parenthesis start |
48
|
|
|
$this->inline = new Context(Context::CONTEXT_INLINE, "(->[]|{}:,=|\\\t\n\r\0'\"` "); |
49
|
|
|
|
50
|
|
|
// Tag: entered into when a detected tag has a namespace operator in tag name |
51
|
|
|
$this->tag = new Context(Context::CONTEXT_TAG, ">:{ /\t\n\r\0"); |
52
|
|
|
|
53
|
|
|
// Parenthesis context: aware of separators, key/value assignments, the end of a parenthesis and quotation marks. Is used for both |
54
|
|
|
// parenthesis arguments for inline syntax and tag attribute arguments for tag syntax. |
55
|
|
|
$this->array = new Context(Context::CONTEXT_ARRAY, ":,]}=\"'`[{)\\ \t\r\n"); |
56
|
|
|
|
57
|
|
|
// Quoted: entered into when a quote mark (single or double) is encountered (in an array which includes in tag arguments) |
58
|
|
|
$this->quoted = new Context(Context::CONTEXT_QUOTED, '\\"\'{[`'); |
59
|
|
|
|
60
|
|
|
// Attributes: identical to array, except does not ignore whitespace and does not split on array [] characters |
61
|
|
|
$this->attributes = new Context(Context::CONTEXT_ATTRIBUTES, " >:{\"'/,=\t\r\n}"); |
62
|
|
|
|
63
|
|
|
// Dead tag: continues indexing until the tag ends or an inline expression is encountered |
64
|
|
|
$this->dead = new Context(Context::CONTEXT_DEAD, '>{'); |
65
|
|
|
|
66
|
|
|
// Inline protection mode: reacts to backtick and curly brace start and end, but ignores nested curly braces. Backtick enters quoted context. |
67
|
|
|
$this->protected = new Context(Context::CONTEXT_PROTECTED, '{}`'); |
68
|
|
|
|
69
|
|
|
// Inline accessor mode: identical to protected context but identifiable under its own name to distinguish it from protected |
70
|
|
|
$this->accessor = new Context(Context::CONTEXT_ACCESSOR, '{}`'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|