@@ -33,7 +33,7 @@ |
||
33 | 33 | */ |
34 | 34 | public function leaveNode($node, VisitorContext $ctx) |
35 | 35 | { |
36 | - if ($node instanceof Tag && strpos($node->name, $this->hiddenKeyword) === 0) { |
|
36 | + if ($node instanceof Tag && strpos($node->name, $this->hiddenKeyword) === 0){ |
|
37 | 37 | return new Hidden([$node]); |
38 | 38 | } |
39 | 39 |
@@ -33,7 +33,8 @@ |
||
33 | 33 | */ |
34 | 34 | public function leaveNode($node, VisitorContext $ctx) |
35 | 35 | { |
36 | - if ($node instanceof Tag && strpos($node->name, $this->hiddenKeyword) === 0) { |
|
36 | + if ($node instanceof Tag && strpos($node->name, $this->hiddenKeyword) === 0) |
|
37 | + { |
|
37 | 38 | return new Hidden([$node]); |
38 | 39 | } |
39 | 40 |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*'){ |
|
53 | 53 | // accept everything |
54 | 54 | return $name; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
58 | + foreach (explode(';', $this->pattern) as $condition){ |
|
59 | + if (strpos($condition, ':') === false){ |
|
60 | 60 | //Invalid |
61 | 61 | continue; |
62 | 62 | } |
@@ -65,27 +65,27 @@ discard block |
||
65 | 65 | $conditions[$option] = $value; |
66 | 66 | } |
67 | 67 | |
68 | - if (isset($conditions['include'])) { |
|
68 | + if (isset($conditions['include'])){ |
|
69 | 69 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
70 | + if (in_array($name, $include)){ |
|
71 | 71 | return $name; |
72 | 72 | } |
73 | 73 | |
74 | 74 | return null; |
75 | 75 | } |
76 | 76 | |
77 | - if (isset($conditions['exclude'])) { |
|
77 | + if (isset($conditions['exclude'])){ |
|
78 | 78 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
79 | + if (in_array($name, $exclude)){ |
|
80 | 80 | return null; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return $name; |
84 | 84 | } |
85 | 85 | |
86 | - if (isset($conditions['prefix'])) { |
|
86 | + if (isset($conditions['prefix'])){ |
|
87 | 87 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
88 | + if (strpos($name, $conditions['prefix']) === 0){ |
|
89 | 89 | return substr($name, strlen($conditions['prefix'])); |
90 | 90 | } |
91 | 91 |
@@ -49,14 +49,17 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*') |
|
53 | + { |
|
53 | 54 | // accept everything |
54 | 55 | return $name; |
55 | 56 | } |
56 | 57 | |
57 | 58 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
59 | + foreach (explode(';', $this->pattern) as $condition) |
|
60 | + { |
|
61 | + if (strpos($condition, ':') === false) |
|
62 | + { |
|
60 | 63 | //Invalid |
61 | 64 | continue; |
62 | 65 | } |
@@ -65,27 +68,33 @@ discard block |
||
65 | 68 | $conditions[$option] = $value; |
66 | 69 | } |
67 | 70 | |
68 | - if (isset($conditions['include'])) { |
|
71 | + if (isset($conditions['include'])) |
|
72 | + { |
|
69 | 73 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
74 | + if (in_array($name, $include)) |
|
75 | + { |
|
71 | 76 | return $name; |
72 | 77 | } |
73 | 78 | |
74 | 79 | return null; |
75 | 80 | } |
76 | 81 | |
77 | - if (isset($conditions['exclude'])) { |
|
82 | + if (isset($conditions['exclude'])) |
|
83 | + { |
|
78 | 84 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
85 | + if (in_array($name, $exclude)) |
|
86 | + { |
|
80 | 87 | return null; |
81 | 88 | } |
82 | 89 | |
83 | 90 | return $name; |
84 | 91 | } |
85 | 92 | |
86 | - if (isset($conditions['prefix'])) { |
|
93 | + if (isset($conditions['prefix'])) |
|
94 | + { |
|
87 | 95 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
96 | + if (strpos($name, $conditions['prefix']) === 0) |
|
97 | + { |
|
89 | 98 | return substr($name, strlen($conditions['prefix'])); |
90 | 99 | } |
91 | 100 |
@@ -53,7 +53,7 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 |
@@ -53,7 +53,8 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length) |
|
57 | + { |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function parse(Buffer $src): \Generator |
28 | 28 | { |
29 | - while ($n = $src->next()) { |
|
30 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
29 | + while ($n = $src->next()){ |
|
30 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?'){ |
|
31 | 31 | yield $n; |
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
|
36 | - if ($php === null) { |
|
35 | + $php = $this->parseGrammar($n->char.$src->nextBytes(), $n->offset); |
|
36 | + if ($php === null){ |
|
37 | 37 | yield $n; |
38 | 38 | $src->replay($n->offset); |
39 | 39 | continue; |
@@ -61,27 +61,27 @@ discard block |
||
61 | 61 | private function parseGrammar(string $content, int $offset): ?Token |
62 | 62 | { |
63 | 63 | $tokens = null; |
64 | - foreach (token_get_all($content) as $token) { |
|
65 | - if ($tokens === null) { |
|
66 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
64 | + foreach (token_get_all($content) as $token){ |
|
65 | + if ($tokens === null){ |
|
66 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])){ |
|
67 | 67 | // not php |
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | $tokens[] = $token; |
73 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
73 | + if ($this->is($token, [T_CLOSE_TAG])){ |
|
74 | 74 | break; |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | - if ($tokens === null) { |
|
78 | + if ($tokens === null){ |
|
79 | 79 | return null; |
80 | 80 | } |
81 | 81 | |
82 | 82 | $buffer = ''; |
83 | - foreach ($tokens as $token) { |
|
84 | - if (!is_array($token)) { |
|
83 | + foreach ($tokens as $token){ |
|
84 | + if (!is_array($token)){ |
|
85 | 85 | $buffer .= $token; |
86 | 86 | continue; |
87 | 87 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | private function is($token, array $type): bool |
103 | 103 | { |
104 | - if (!is_array($token)) { |
|
104 | + if (!is_array($token)){ |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 |
@@ -26,14 +26,17 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function parse(Buffer $src): \Generator |
28 | 28 | { |
29 | - while ($n = $src->next()) { |
|
30 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
29 | + while ($n = $src->next()) |
|
30 | + { |
|
31 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') |
|
32 | + { |
|
31 | 33 | yield $n; |
32 | 34 | continue; |
33 | 35 | } |
34 | 36 | |
35 | 37 | $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
36 | - if ($php === null) { |
|
38 | + if ($php === null) |
|
39 | + { |
|
37 | 40 | yield $n; |
38 | 41 | $src->replay($n->offset); |
39 | 42 | continue; |
@@ -61,27 +64,34 @@ discard block |
||
61 | 64 | private function parseGrammar(string $content, int $offset): ?Token |
62 | 65 | { |
63 | 66 | $tokens = null; |
64 | - foreach (token_get_all($content) as $token) { |
|
65 | - if ($tokens === null) { |
|
66 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
67 | + foreach (token_get_all($content) as $token) |
|
68 | + { |
|
69 | + if ($tokens === null) |
|
70 | + { |
|
71 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) |
|
72 | + { |
|
67 | 73 | // not php |
68 | 74 | return null; |
69 | 75 | } |
70 | 76 | } |
71 | 77 | |
72 | 78 | $tokens[] = $token; |
73 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
79 | + if ($this->is($token, [T_CLOSE_TAG])) |
|
80 | + { |
|
74 | 81 | break; |
75 | 82 | } |
76 | 83 | } |
77 | 84 | |
78 | - if ($tokens === null) { |
|
85 | + if ($tokens === null) |
|
86 | + { |
|
79 | 87 | return null; |
80 | 88 | } |
81 | 89 | |
82 | 90 | $buffer = ''; |
83 | - foreach ($tokens as $token) { |
|
84 | - if (!is_array($token)) { |
|
91 | + foreach ($tokens as $token) |
|
92 | + { |
|
93 | + if (!is_array($token)) |
|
94 | + { |
|
85 | 95 | $buffer .= $token; |
86 | 96 | continue; |
87 | 97 | } |
@@ -101,7 +111,8 @@ discard block |
||
101 | 111 | */ |
102 | 112 | private function is($token, array $type): bool |
103 | 113 | { |
104 | - if (!is_array($token)) { |
|
114 | + if (!is_array($token)) |
|
115 | + { |
|
105 | 116 | return false; |
106 | 117 | } |
107 | 118 |
@@ -84,33 +84,33 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function parse(Buffer $src): \Generator |
86 | 86 | { |
87 | - while ($n = $src->next()) { |
|
88 | - if (!$n instanceof Byte) { |
|
87 | + while ($n = $src->next()){ |
|
88 | + if (!$n instanceof Byte){ |
|
89 | 89 | yield $n; |
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | |
93 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
93 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
94 | 94 | if ( |
95 | 95 | $this->echo->nextToken($src) || |
96 | 96 | $this->raw->nextToken($src) || |
97 | 97 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
98 | - ) { |
|
98 | + ){ |
|
99 | 99 | // escaped echo sequence, hide directive byte |
100 | 100 | yield $src->next(); |
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $directive = new DirectiveGrammar(); |
105 | - if ($directive->parse($src, $n->offset)) { |
|
106 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
105 | + if ($directive->parse($src, $n->offset)){ |
|
106 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
107 | 107 | // configure braces syntax |
108 | 108 | $this->declare($directive->getBody()); |
109 | - } else { |
|
109 | + }else{ |
|
110 | 110 | if ( |
111 | 111 | $this->directiveRenderer !== null |
112 | 112 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
113 | - ) { |
|
113 | + ){ |
|
114 | 114 | // directive opening char |
115 | 115 | yield $n; |
116 | 116 | |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | |
132 | 132 | /** @var BracesGrammar|null $braces */ |
133 | 133 | $braces = null; |
134 | - if ($this->echo->starts($src, $n)) { |
|
134 | + if ($this->echo->starts($src, $n)){ |
|
135 | 135 | $braces = clone $this->echo; |
136 | - } elseif ($this->raw->starts($src, $n)) { |
|
136 | + } elseif ($this->raw->starts($src, $n)){ |
|
137 | 137 | $braces = clone $this->raw; |
138 | 138 | } |
139 | 139 | |
140 | - if ($braces !== null) { |
|
140 | + if ($braces !== null){ |
|
141 | 141 | $echo = $braces->parse($src, $n); |
142 | - if ($echo !== null) { |
|
142 | + if ($echo !== null){ |
|
143 | 143 | yield from $echo; |
144 | 144 | continue; |
145 | 145 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function tokenName(int $token): string |
161 | 161 | { |
162 | - switch ($token) { |
|
162 | + switch ($token){ |
|
163 | 163 | case self::TYPE_OPEN_TAG: |
164 | 164 | return 'DYNAMIC:OPEN_TAG'; |
165 | 165 | case self::TYPE_CLOSE_TAG: |
@@ -184,20 +184,20 @@ discard block |
||
184 | 184 | /** |
185 | 185 | * @param string $body |
186 | 186 | */ |
187 | - private function declare(?string $body): void |
|
187 | + private function declare(?string$body) : void |
|
188 | 188 | { |
189 | - if ($body === null) { |
|
189 | + if ($body === null){ |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
193 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
194 | 194 | $value = trim($value, '\'" '); |
195 | - switch ($option) { |
|
195 | + switch ($option){ |
|
196 | 196 | case 'syntax': |
197 | 197 | $this->echo->setActive($value !== 'off'); |
198 | 198 | $this->raw->setActive($value !== 'off'); |
199 | 199 | |
200 | - if ($value === 'default') { |
|
200 | + if ($value === 'default'){ |
|
201 | 201 | $this->echo->setStartSequence('{{'); |
202 | 202 | $this->echo->setEndSequence('}}'); |
203 | 203 | $this->raw->setStartSequence('{!!'); |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | $keyword = null; |
239 | 239 | |
240 | 240 | /** @var Token $token */ |
241 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
242 | - switch ($token->type) { |
|
241 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
242 | + switch ($token->type){ |
|
243 | 243 | case DeclareGrammar::TYPE_KEYWORD: |
244 | - if ($keyword !== null) { |
|
244 | + if ($keyword !== null){ |
|
245 | 245 | $options[$keyword] = $token->content; |
246 | 246 | $keyword = null; |
247 | 247 | break; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $keyword = $token->content; |
250 | 250 | break; |
251 | 251 | case DeclareGrammar::TYPE_QUOTED: |
252 | - if ($keyword !== null) { |
|
252 | + if ($keyword !== null){ |
|
253 | 253 | $options[$keyword] = trim($token->content, $token->content[0]); |
254 | 254 | $keyword = null; |
255 | 255 | break; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $keyword = trim($token->content, $token->content[0]); |
259 | 259 | break; |
260 | 260 | case DeclareGrammar::TYPE_COMMA: |
261 | - if ($keyword !== null) { |
|
261 | + if ($keyword !== null){ |
|
262 | 262 | $options[$keyword] = null; |
263 | 263 | $keyword = null; |
264 | 264 | break; |
@@ -84,13 +84,16 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function parse(Buffer $src): \Generator |
86 | 86 | { |
87 | - while ($n = $src->next()) { |
|
88 | - if (!$n instanceof Byte) { |
|
87 | + while ($n = $src->next()) |
|
88 | + { |
|
89 | + if (!$n instanceof Byte) |
|
90 | + { |
|
89 | 91 | yield $n; |
90 | 92 | continue; |
91 | 93 | } |
92 | 94 | |
93 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
95 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
96 | + { |
|
94 | 97 | if ( |
95 | 98 | $this->echo->nextToken($src) || |
96 | 99 | $this->raw->nextToken($src) || |
@@ -102,11 +105,15 @@ discard block |
||
102 | 105 | } |
103 | 106 | |
104 | 107 | $directive = new DirectiveGrammar(); |
105 | - if ($directive->parse($src, $n->offset)) { |
|
106 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
108 | + if ($directive->parse($src, $n->offset)) |
|
109 | + { |
|
110 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
111 | + { |
|
107 | 112 | // configure braces syntax |
108 | 113 | $this->declare($directive->getBody()); |
109 | - } else { |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
110 | 117 | if ( |
111 | 118 | $this->directiveRenderer !== null |
112 | 119 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -131,15 +138,20 @@ discard block |
||
131 | 138 | |
132 | 139 | /** @var BracesGrammar|null $braces */ |
133 | 140 | $braces = null; |
134 | - if ($this->echo->starts($src, $n)) { |
|
141 | + if ($this->echo->starts($src, $n)) |
|
142 | + { |
|
135 | 143 | $braces = clone $this->echo; |
136 | - } elseif ($this->raw->starts($src, $n)) { |
|
144 | + } |
|
145 | + elseif ($this->raw->starts($src, $n)) |
|
146 | + { |
|
137 | 147 | $braces = clone $this->raw; |
138 | 148 | } |
139 | 149 | |
140 | - if ($braces !== null) { |
|
150 | + if ($braces !== null) |
|
151 | + { |
|
141 | 152 | $echo = $braces->parse($src, $n); |
142 | - if ($echo !== null) { |
|
153 | + if ($echo !== null) |
|
154 | + { |
|
143 | 155 | yield from $echo; |
144 | 156 | continue; |
145 | 157 | } |
@@ -159,7 +171,8 @@ discard block |
||
159 | 171 | */ |
160 | 172 | public static function tokenName(int $token): string |
161 | 173 | { |
162 | - switch ($token) { |
|
174 | + switch ($token) |
|
175 | + { |
|
163 | 176 | case self::TYPE_OPEN_TAG: |
164 | 177 | return 'DYNAMIC:OPEN_TAG'; |
165 | 178 | case self::TYPE_CLOSE_TAG: |
@@ -186,18 +199,22 @@ discard block |
||
186 | 199 | */ |
187 | 200 | private function declare(?string $body): void |
188 | 201 | { |
189 | - if ($body === null) { |
|
202 | + if ($body === null) |
|
203 | + { |
|
190 | 204 | return; |
191 | 205 | } |
192 | 206 | |
193 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
207 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
208 | + { |
|
194 | 209 | $value = trim($value, '\'" '); |
195 | - switch ($option) { |
|
210 | + switch ($option) |
|
211 | + { |
|
196 | 212 | case 'syntax': |
197 | 213 | $this->echo->setActive($value !== 'off'); |
198 | 214 | $this->raw->setActive($value !== 'off'); |
199 | 215 | |
200 | - if ($value === 'default') { |
|
216 | + if ($value === 'default') |
|
217 | + { |
|
201 | 218 | $this->echo->setStartSequence('{{'); |
202 | 219 | $this->echo->setEndSequence('}}'); |
203 | 220 | $this->raw->setStartSequence('{!!'); |
@@ -238,10 +255,13 @@ discard block |
||
238 | 255 | $keyword = null; |
239 | 256 | |
240 | 257 | /** @var Token $token */ |
241 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
242 | - switch ($token->type) { |
|
258 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
259 | + { |
|
260 | + switch ($token->type) |
|
261 | + { |
|
243 | 262 | case DeclareGrammar::TYPE_KEYWORD: |
244 | - if ($keyword !== null) { |
|
263 | + if ($keyword !== null) |
|
264 | + { |
|
245 | 265 | $options[$keyword] = $token->content; |
246 | 266 | $keyword = null; |
247 | 267 | break; |
@@ -249,7 +269,8 @@ discard block |
||
249 | 269 | $keyword = $token->content; |
250 | 270 | break; |
251 | 271 | case DeclareGrammar::TYPE_QUOTED: |
252 | - if ($keyword !== null) { |
|
272 | + if ($keyword !== null) |
|
273 | + { |
|
253 | 274 | $options[$keyword] = trim($token->content, $token->content[0]); |
254 | 275 | $keyword = null; |
255 | 276 | break; |
@@ -258,7 +279,8 @@ discard block |
||
258 | 279 | $keyword = trim($token->content, $token->content[0]); |
259 | 280 | break; |
260 | 281 | case DeclareGrammar::TYPE_COMMA: |
261 | - if ($keyword !== null) { |
|
282 | + if ($keyword !== null) |
|
283 | + { |
|
262 | 284 | $options[$keyword] = null; |
263 | 285 | $keyword = null; |
264 | 286 | break; |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n){ |
|
31 | + if ($n instanceof Byte){ |
|
32 | + if ($buffer === null){ |
|
33 | 33 | $buffer = ''; |
34 | 34 | $bufferOffset = $n->offset; |
35 | 35 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - if ($buffer !== null) { |
|
41 | + if ($buffer !== null){ |
|
42 | 42 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 43 | $buffer = null; |
44 | 44 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | yield $n; |
47 | 47 | } |
48 | 48 | |
49 | - if ($buffer !== null) { |
|
49 | + if ($buffer !== null){ |
|
50 | 50 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 51 | } |
52 | 52 | } |
@@ -27,9 +27,12 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n) |
|
31 | + { |
|
32 | + if ($n instanceof Byte) |
|
33 | + { |
|
34 | + if ($buffer === null) |
|
35 | + { |
|
33 | 36 | $buffer = ''; |
34 | 37 | $bufferOffset = $n->offset; |
35 | 38 | } |
@@ -38,7 +41,8 @@ discard block |
||
38 | 41 | continue; |
39 | 42 | } |
40 | 43 | |
41 | - if ($buffer !== null) { |
|
44 | + if ($buffer !== null) |
|
45 | + { |
|
42 | 46 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 47 | $buffer = null; |
44 | 48 | } |
@@ -46,7 +50,8 @@ discard block |
||
46 | 50 | yield $n; |
47 | 51 | } |
48 | 52 | |
49 | - if ($buffer !== null) { |
|
53 | + if ($buffer !== null) |
|
54 | + { |
|
50 | 55 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 56 | } |
52 | 57 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function getStackPath(): string |
52 | 52 | { |
53 | 53 | $path = [$this->nodeName($this->node)]; |
54 | - foreach ($this->stack as $tuple) { |
|
54 | + foreach ($this->stack as $tuple){ |
|
55 | 55 | $path[] = $this->nodeName($tuple[0]); |
56 | 56 | } |
57 | 57 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | private function nodeName(NodeInterface $node): string |
95 | 95 | { |
96 | 96 | $r = new \ReflectionClass($node); |
97 | - if (property_exists($node, 'name')) { |
|
98 | - return lcfirst($r->getShortName()) . "[{$node->name}]"; |
|
97 | + if (property_exists($node, 'name')){ |
|
98 | + return lcfirst($r->getShortName())."[{$node->name}]"; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return lcfirst($r->getShortName()); |
@@ -51,7 +51,8 @@ discard block |
||
51 | 51 | public function getStackPath(): string |
52 | 52 | { |
53 | 53 | $path = [$this->nodeName($this->node)]; |
54 | - foreach ($this->stack as $tuple) { |
|
54 | + foreach ($this->stack as $tuple) |
|
55 | + { |
|
55 | 56 | $path[] = $this->nodeName($tuple[0]); |
56 | 57 | } |
57 | 58 | |
@@ -94,7 +95,8 @@ discard block |
||
94 | 95 | private function nodeName(NodeInterface $node): string |
95 | 96 | { |
96 | 97 | $r = new \ReflectionClass($node); |
97 | - if (property_exists($node, 'name')) { |
|
98 | + if (property_exists($node, 'name')) |
|
99 | + { |
|
98 | 100 | return lcfirst($r->getShortName()) . "[{$node->name}]"; |
99 | 101 | } |
100 | 102 |
@@ -26,8 +26,8 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []){ |
|
30 | + if ($token->type === Token::TYPE_RAW){ |
|
31 | 31 | return new Raw($token->content); |
32 | 32 | } |
33 | 33 |
@@ -26,8 +26,10 @@ |
||
26 | 26 | */ |
27 | 27 | private function parseToken(Parser $parser, Token $token) |
28 | 28 | { |
29 | - if ($token->tokens === []) { |
|
30 | - if ($token->type === Token::TYPE_RAW) { |
|
29 | + if ($token->tokens === []) |
|
30 | + { |
|
31 | + if ($token->type === Token::TYPE_RAW) |
|
32 | + { |
|
31 | 33 | return new Raw($token->content); |
32 | 34 | } |
33 | 35 |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx){ |
|
62 | 62 | $parser->syntax[$grammar] = clone $stx; |
63 | 63 | } |
64 | 64 | |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | { |
96 | 96 | $template = new Template(); |
97 | 97 | |
98 | - try { |
|
98 | + try{ |
|
99 | 99 | $this->parseTokens( |
100 | 100 | new Assembler($template, 'nodes'), |
101 | 101 | $this->lexer->parse($stream) |
102 | 102 | ); |
103 | - } catch (SyntaxException $e) { |
|
103 | + }catch (SyntaxException $e){ |
|
104 | 104 | throw new ParserException( |
105 | 105 | $e->getMessage(), |
106 | 106 | new Context($e->getToken(), $this->getPath()), |
@@ -122,21 +122,21 @@ discard block |
||
122 | 122 | $node = $asm->getNode(); |
123 | 123 | |
124 | 124 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
125 | + foreach ($this->syntax as $grammar => $stx){ |
|
126 | 126 | $syntax[$grammar] = clone $stx; |
127 | 127 | } |
128 | 128 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
129 | + foreach ($tokens as $token){ |
|
130 | + if (!isset($syntax[$token->grammar])){ |
|
131 | 131 | throw new SyntaxException('Undefined token', $token); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 135 | } |
136 | 136 | |
137 | - if ($asm->getNode() !== $node) { |
|
137 | + if ($asm->getNode() !== $node){ |
|
138 | 138 | throw new SyntaxException( |
139 | - 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
|
139 | + 'Invalid node hierarchy, unclosed '.$asm->getStackPath(), |
|
140 | 140 | $asm->getNode()->getContext()->getToken() |
141 | 141 | ); |
142 | 142 | } |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | $parser->path = $path; |
59 | 59 | $parser->lexer = clone $this->lexer; |
60 | 60 | |
61 | - foreach ($parser->syntax as $grammar => $stx) { |
|
61 | + foreach ($parser->syntax as $grammar => $stx) |
|
62 | + { |
|
62 | 63 | $parser->syntax[$grammar] = clone $stx; |
63 | 64 | } |
64 | 65 | |
@@ -95,12 +96,15 @@ discard block |
||
95 | 96 | { |
96 | 97 | $template = new Template(); |
97 | 98 | |
98 | - try { |
|
99 | + try |
|
100 | + { |
|
99 | 101 | $this->parseTokens( |
100 | 102 | new Assembler($template, 'nodes'), |
101 | 103 | $this->lexer->parse($stream) |
102 | 104 | ); |
103 | - } catch (SyntaxException $e) { |
|
105 | + } |
|
106 | + catch (SyntaxException $e) |
|
107 | + { |
|
104 | 108 | throw new ParserException( |
105 | 109 | $e->getMessage(), |
106 | 110 | new Context($e->getToken(), $this->getPath()), |
@@ -122,19 +126,23 @@ discard block |
||
122 | 126 | $node = $asm->getNode(); |
123 | 127 | |
124 | 128 | $syntax = []; |
125 | - foreach ($this->syntax as $grammar => $stx) { |
|
129 | + foreach ($this->syntax as $grammar => $stx) |
|
130 | + { |
|
126 | 131 | $syntax[$grammar] = clone $stx; |
127 | 132 | } |
128 | 133 | |
129 | - foreach ($tokens as $token) { |
|
130 | - if (!isset($syntax[$token->grammar])) { |
|
134 | + foreach ($tokens as $token) |
|
135 | + { |
|
136 | + if (!isset($syntax[$token->grammar])) |
|
137 | + { |
|
131 | 138 | throw new SyntaxException('Undefined token', $token); |
132 | 139 | } |
133 | 140 | |
134 | 141 | $syntax[$token->grammar]->handle($this, $asm, $token); |
135 | 142 | } |
136 | 143 | |
137 | - if ($asm->getNode() !== $node) { |
|
144 | + if ($asm->getNode() !== $node) |
|
145 | + { |
|
138 | 146 | throw new SyntaxException( |
139 | 147 | 'Invalid node hierarchy, unclosed ' . $asm->getStackPath(), |
140 | 148 | $asm->getNode()->getContext()->getToken() |