@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | string $endSequence, |
| 28 | 28 | private readonly int $startToken, |
| 29 | 29 | private readonly int $endToken |
| 30 | - ) { |
|
| 30 | + ){ |
|
| 31 | 31 | $this->setStartSequence($startSequence); |
| 32 | 32 | $this->setEndSequence($endSequence); |
| 33 | 33 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function nextToken(Buffer $src): bool |
| 70 | 70 | { |
| 71 | - return $this->active && $src->lookaheadByte(\strlen((string) $this->startSequence)) === $this->startSequence; |
|
| 71 | + return $this->active && $src->lookaheadByte(\strlen((string)$this->startSequence)) === $this->startSequence; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function starts(Buffer $src, Byte $n): bool |
| 78 | 78 | { |
| 79 | - if (!$this->active) { |
|
| 79 | + if (!$this->active){ |
|
| 80 | 80 | return false; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - return $this->startSequence === ($n->char . $src->lookaheadByte(\strlen((string) $this->startSequence) - 1)); |
|
| 83 | + return $this->startSequence === ($n->char.$src->lookaheadByte(\strlen((string)$this->startSequence) - 1)); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -92,30 +92,30 @@ discard block |
||
| 92 | 92 | new Token( |
| 93 | 93 | $this->startToken, |
| 94 | 94 | $n->offset, |
| 95 | - $n->char . $this->nextBytes($src, \strlen((string) $this->startSequence) - 1) |
|
| 95 | + $n->char.$this->nextBytes($src, \strlen((string)$this->startSequence) - 1) |
|
| 96 | 96 | ), |
| 97 | 97 | ]; |
| 98 | 98 | |
| 99 | - while ($n = $src->next()) { |
|
| 100 | - if (!$n instanceof Byte) { |
|
| 99 | + while ($n = $src->next()){ |
|
| 100 | + if (!$n instanceof Byte){ |
|
| 101 | 101 | // no other grammars are allowed |
| 102 | 102 | break; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - switch ($n->char) { |
|
| 105 | + switch ($n->char){ |
|
| 106 | 106 | case '"': |
| 107 | 107 | case "'": |
| 108 | 108 | $this->body[] = $n; |
| 109 | - while ($nn = $src->next()) { |
|
| 109 | + while ($nn = $src->next()){ |
|
| 110 | 110 | $this->body[] = $nn; |
| 111 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 111 | + if ($nn instanceof Byte && $nn->char === $n->char){ |
|
| 112 | 112 | break; |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | break; |
| 116 | 116 | |
| 117 | 117 | case $this->endSequence[0]: |
| 118 | - if (!$this->ends($src, $n)) { |
|
| 118 | + if (!$this->ends($src, $n)){ |
|
| 119 | 119 | // still part of body |
| 120 | 120 | $this->body[] = $n; |
| 121 | 121 | break; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $this->tokens[] = new Token( |
| 126 | 126 | $this->endToken, |
| 127 | 127 | $n->offset, |
| 128 | - $n->char . $this->nextBytes($src, \strlen((string) $this->endSequence) - 1) |
|
| 128 | + $n->char.$this->nextBytes($src, \strlen((string)$this->endSequence) - 1) |
|
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | 131 | break 2; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if (\count($this->tokens) !== 3) { |
|
| 137 | + if (\count($this->tokens) !== 3){ |
|
| 138 | 138 | return null; |
| 139 | 139 | } |
| 140 | 140 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | private function ends(Buffer $src, Byte $n): bool |
| 148 | 148 | { |
| 149 | - return $this->endSequence === ($n->char . $src->lookaheadByte(\strlen((string) $this->endSequence) - 1)); |
|
| 149 | + return $this->endSequence === ($n->char.$src->lookaheadByte(\strlen((string)$this->endSequence) - 1)); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | private function nextBytes(Buffer $src, int $size): string |
| 162 | 162 | { |
| 163 | 163 | $result = ''; |
| 164 | - for ($i = 0; $i < $size; $i++) { |
|
| 164 | + for ($i = 0; $i < $size; $i++){ |
|
| 165 | 165 | $result .= $src->next()->char; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | private function flushBody(): void |
| 175 | 175 | { |
| 176 | - if ($this->body === []) { |
|
| 176 | + if ($this->body === []){ |
|
| 177 | 177 | return; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -76,7 +76,8 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function starts(Buffer $src, Byte $n): bool |
| 78 | 78 | { |
| 79 | - if (!$this->active) { |
|
| 79 | + if (!$this->active) |
|
| 80 | + { |
|
| 80 | 81 | return false; |
| 81 | 82 | } |
| 82 | 83 | |
@@ -96,26 +97,32 @@ discard block |
||
| 96 | 97 | ), |
| 97 | 98 | ]; |
| 98 | 99 | |
| 99 | - while ($n = $src->next()) { |
|
| 100 | - if (!$n instanceof Byte) { |
|
| 100 | + while ($n = $src->next()) |
|
| 101 | + { |
|
| 102 | + if (!$n instanceof Byte) |
|
| 103 | + { |
|
| 101 | 104 | // no other grammars are allowed |
| 102 | 105 | break; |
| 103 | 106 | } |
| 104 | 107 | |
| 105 | - switch ($n->char) { |
|
| 108 | + switch ($n->char) |
|
| 109 | + { |
|
| 106 | 110 | case '"': |
| 107 | 111 | case "'": |
| 108 | 112 | $this->body[] = $n; |
| 109 | - while ($nn = $src->next()) { |
|
| 113 | + while ($nn = $src->next()) |
|
| 114 | + { |
|
| 110 | 115 | $this->body[] = $nn; |
| 111 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 116 | + if ($nn instanceof Byte && $nn->char === $n->char) |
|
| 117 | + { |
|
| 112 | 118 | break; |
| 113 | 119 | } |
| 114 | 120 | } |
| 115 | 121 | break; |
| 116 | 122 | |
| 117 | 123 | case $this->endSequence[0]: |
| 118 | - if (!$this->ends($src, $n)) { |
|
| 124 | + if (!$this->ends($src, $n)) |
|
| 125 | + { |
|
| 119 | 126 | // still part of body |
| 120 | 127 | $this->body[] = $n; |
| 121 | 128 | break; |
@@ -134,7 +141,8 @@ discard block |
||
| 134 | 141 | } |
| 135 | 142 | } |
| 136 | 143 | |
| 137 | - if (\count($this->tokens) !== 3) { |
|
| 144 | + if (\count($this->tokens) !== 3) |
|
| 145 | + { |
|
| 138 | 146 | return null; |
| 139 | 147 | } |
| 140 | 148 | |
@@ -161,7 +169,8 @@ discard block |
||
| 161 | 169 | private function nextBytes(Buffer $src, int $size): string |
| 162 | 170 | { |
| 163 | 171 | $result = ''; |
| 164 | - for ($i = 0; $i < $size; $i++) { |
|
| 172 | + for ($i = 0; $i < $size; $i++) |
|
| 173 | + { |
|
| 165 | 174 | $result .= $src->next()->char; |
| 166 | 175 | } |
| 167 | 176 | |
@@ -173,7 +182,8 @@ discard block |
||
| 173 | 182 | */ |
| 174 | 183 | private function flushBody(): void |
| 175 | 184 | { |
| 176 | - if ($this->body === []) { |
|
| 185 | + if ($this->body === []) |
|
| 186 | + { |
|
| 177 | 187 | return; |
| 178 | 188 | } |
| 179 | 189 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function parse(Buffer $src): \Generator |
| 40 | 40 | { |
| 41 | - while ($n = $src->next()) { |
|
| 42 | - if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') { |
|
| 41 | + while ($n = $src->next()){ |
|
| 42 | + if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{'){ |
|
| 43 | 43 | yield $n; |
| 44 | 44 | continue; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $binding = (clone $this)->parseGrammar($src, $n->offset); |
| 48 | - if ($binding === null) { |
|
| 48 | + if ($binding === null){ |
|
| 49 | 49 | yield $n; |
| 50 | 50 | $src->replay($n->offset); |
| 51 | 51 | continue; |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | private function parseGrammar(Buffer $src, int $offset): ?array |
| 81 | 81 | { |
| 82 | 82 | $this->tokens = [ |
| 83 | - new Token(self::TYPE_OPEN_TAG, $offset, '$' . $src->next()->char), |
|
| 83 | + new Token(self::TYPE_OPEN_TAG, $offset, '$'.$src->next()->char), |
|
| 84 | 84 | ]; |
| 85 | 85 | |
| 86 | - while ($n = $src->next()) { |
|
| 87 | - if (!$n instanceof Byte) { |
|
| 86 | + while ($n = $src->next()){ |
|
| 87 | + if (!$n instanceof Byte){ |
|
| 88 | 88 | // no other grammars are allowed |
| 89 | 89 | return null; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - switch ($n->char) { |
|
| 92 | + switch ($n->char){ |
|
| 93 | 93 | case '"': |
| 94 | 94 | case "'": |
| 95 | - if ($this->default === null) { |
|
| 95 | + if ($this->default === null){ |
|
| 96 | 96 | // " and ' not allowed in names |
| 97 | 97 | return null; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $this->default[] = $n; |
| 101 | - while ($nn = $src->next()) { |
|
| 101 | + while ($nn = $src->next()){ |
|
| 102 | 102 | $this->default[] = $nn; |
| 103 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 103 | + if ($nn instanceof Byte && $nn->char === $n->char){ |
|
| 104 | 104 | break; |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -133,17 +133,17 @@ discard block |
||
| 133 | 133 | break; |
| 134 | 134 | |
| 135 | 135 | default: |
| 136 | - if ($this->default !== null) { |
|
| 136 | + if ($this->default !== null){ |
|
| 137 | 137 | // default allows spaces |
| 138 | 138 | $this->default[] = $n; |
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 142 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
| 143 | 143 | break; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if (\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 146 | + if (\preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
| 147 | 147 | $this->name[] = $n; |
| 148 | 148 | break; |
| 149 | 149 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if (!$this->isValid()) { |
|
| 155 | + if (!$this->isValid()){ |
|
| 156 | 156 | return null; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -161,25 +161,25 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | private function isValid(): bool |
| 163 | 163 | { |
| 164 | - if (\count($this->tokens) < 3) { |
|
| 164 | + if (\count($this->tokens) < 3){ |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | $hasName = false; |
| 169 | 169 | $hasDefault = null; |
| 170 | - foreach ($this->tokens as $token) { |
|
| 171 | - if ($token->type === self::TYPE_NAME) { |
|
| 170 | + foreach ($this->tokens as $token){ |
|
| 171 | + if ($token->type === self::TYPE_NAME){ |
|
| 172 | 172 | $hasName = true; |
| 173 | 173 | continue; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) { |
|
| 176 | + if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null){ |
|
| 177 | 177 | $hasDefault = false; |
| 178 | 178 | continue; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if ($token->type === self::TYPE_DEFAULT) { |
|
| 182 | - if ($hasDefault === true) { |
|
| 181 | + if ($token->type === self::TYPE_DEFAULT){ |
|
| 182 | + if ($hasDefault === true){ |
|
| 183 | 183 | // multiple default value |
| 184 | 184 | return false; |
| 185 | 185 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | private function flushName(): void |
| 198 | 198 | { |
| 199 | - if ($this->name === []) { |
|
| 199 | + if ($this->name === []){ |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | private function flushDefault(): void |
| 211 | 211 | { |
| 212 | - if ($this->default === [] || $this->default === null) { |
|
| 212 | + if ($this->default === [] || $this->default === null){ |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -38,14 +38,17 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function parse(Buffer $src): \Generator |
| 40 | 40 | { |
| 41 | - while ($n = $src->next()) { |
|
| 42 | - if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') { |
|
| 41 | + while ($n = $src->next()) |
|
| 42 | + { |
|
| 43 | + if (!$n instanceof Byte || $n->char !== '$' || $src->lookaheadByte() !== '{') |
|
| 44 | + { |
|
| 43 | 45 | yield $n; |
| 44 | 46 | continue; |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | $binding = (clone $this)->parseGrammar($src, $n->offset); |
| 48 | - if ($binding === null) { |
|
| 50 | + if ($binding === null) |
|
| 51 | + { |
|
| 49 | 52 | yield $n; |
| 50 | 53 | $src->replay($n->offset); |
| 51 | 54 | continue; |
@@ -83,24 +86,30 @@ discard block |
||
| 83 | 86 | new Token(self::TYPE_OPEN_TAG, $offset, '$' . $src->next()->char), |
| 84 | 87 | ]; |
| 85 | 88 | |
| 86 | - while ($n = $src->next()) { |
|
| 87 | - if (!$n instanceof Byte) { |
|
| 89 | + while ($n = $src->next()) |
|
| 90 | + { |
|
| 91 | + if (!$n instanceof Byte) |
|
| 92 | + { |
|
| 88 | 93 | // no other grammars are allowed |
| 89 | 94 | return null; |
| 90 | 95 | } |
| 91 | 96 | |
| 92 | - switch ($n->char) { |
|
| 97 | + switch ($n->char) |
|
| 98 | + { |
|
| 93 | 99 | case '"': |
| 94 | 100 | case "'": |
| 95 | - if ($this->default === null) { |
|
| 101 | + if ($this->default === null) |
|
| 102 | + { |
|
| 96 | 103 | // " and ' not allowed in names |
| 97 | 104 | return null; |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | 107 | $this->default[] = $n; |
| 101 | - while ($nn = $src->next()) { |
|
| 108 | + while ($nn = $src->next()) |
|
| 109 | + { |
|
| 102 | 110 | $this->default[] = $nn; |
| 103 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 111 | + if ($nn instanceof Byte && $nn->char === $n->char) |
|
| 112 | + { |
|
| 104 | 113 | break; |
| 105 | 114 | } |
| 106 | 115 | } |
@@ -133,17 +142,20 @@ discard block |
||
| 133 | 142 | break; |
| 134 | 143 | |
| 135 | 144 | default: |
| 136 | - if ($this->default !== null) { |
|
| 145 | + if ($this->default !== null) |
|
| 146 | + { |
|
| 137 | 147 | // default allows spaces |
| 138 | 148 | $this->default[] = $n; |
| 139 | 149 | break; |
| 140 | 150 | } |
| 141 | 151 | |
| 142 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 152 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
| 153 | + { |
|
| 143 | 154 | break; |
| 144 | 155 | } |
| 145 | 156 | |
| 146 | - if (\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 157 | + if (\preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
| 158 | + { |
|
| 147 | 159 | $this->name[] = $n; |
| 148 | 160 | break; |
| 149 | 161 | } |
@@ -152,7 +164,8 @@ discard block |
||
| 152 | 164 | } |
| 153 | 165 | } |
| 154 | 166 | |
| 155 | - if (!$this->isValid()) { |
|
| 167 | + if (!$this->isValid()) |
|
| 168 | + { |
|
| 156 | 169 | return null; |
| 157 | 170 | } |
| 158 | 171 | |
@@ -161,25 +174,31 @@ discard block |
||
| 161 | 174 | |
| 162 | 175 | private function isValid(): bool |
| 163 | 176 | { |
| 164 | - if (\count($this->tokens) < 3) { |
|
| 177 | + if (\count($this->tokens) < 3) |
|
| 178 | + { |
|
| 165 | 179 | return false; |
| 166 | 180 | } |
| 167 | 181 | |
| 168 | 182 | $hasName = false; |
| 169 | 183 | $hasDefault = null; |
| 170 | - foreach ($this->tokens as $token) { |
|
| 171 | - if ($token->type === self::TYPE_NAME) { |
|
| 184 | + foreach ($this->tokens as $token) |
|
| 185 | + { |
|
| 186 | + if ($token->type === self::TYPE_NAME) |
|
| 187 | + { |
|
| 172 | 188 | $hasName = true; |
| 173 | 189 | continue; |
| 174 | 190 | } |
| 175 | 191 | |
| 176 | - if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) { |
|
| 192 | + if ($token->type === self::TYPE_SEPARATOR && $hasDefault === null) |
|
| 193 | + { |
|
| 177 | 194 | $hasDefault = false; |
| 178 | 195 | continue; |
| 179 | 196 | } |
| 180 | 197 | |
| 181 | - if ($token->type === self::TYPE_DEFAULT) { |
|
| 182 | - if ($hasDefault === true) { |
|
| 198 | + if ($token->type === self::TYPE_DEFAULT) |
|
| 199 | + { |
|
| 200 | + if ($hasDefault === true) |
|
| 201 | + { |
|
| 183 | 202 | // multiple default value |
| 184 | 203 | return false; |
| 185 | 204 | } |
@@ -196,7 +215,8 @@ discard block |
||
| 196 | 215 | */ |
| 197 | 216 | private function flushName(): void |
| 198 | 217 | { |
| 199 | - if ($this->name === []) { |
|
| 218 | + if ($this->name === []) |
|
| 219 | + { |
|
| 200 | 220 | return; |
| 201 | 221 | } |
| 202 | 222 | |
@@ -209,7 +229,8 @@ discard block |
||
| 209 | 229 | */ |
| 210 | 230 | private function flushDefault(): void |
| 211 | 231 | { |
| 212 | - if ($this->default === [] || $this->default === null) { |
|
| 232 | + if ($this->default === [] || $this->default === null) |
|
| 233 | + { |
|
| 213 | 234 | return; |
| 214 | 235 | } |
| 215 | 236 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function __construct( |
| 48 | 48 | private readonly ?DirectiveRendererInterface $directiveRenderer = null |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | $this->echo = new BracesGrammar( |
| 51 | 51 | '{{', |
| 52 | 52 | '}}', |
@@ -67,33 +67,33 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function parse(Buffer $src): \Generator |
| 69 | 69 | { |
| 70 | - while ($n = $src->next()) { |
|
| 71 | - if (!$n instanceof Byte) { |
|
| 70 | + while ($n = $src->next()){ |
|
| 71 | + if (!$n instanceof Byte){ |
|
| 72 | 72 | yield $n; |
| 73 | 73 | continue; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 76 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
| 77 | 77 | if ( |
| 78 | 78 | $this->echo->nextToken($src) || |
| 79 | 79 | $this->raw->nextToken($src) || |
| 80 | 80 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
| 81 | - ) { |
|
| 81 | + ){ |
|
| 82 | 82 | // escaped echo sequence, hide directive byte |
| 83 | 83 | yield $src->next(); |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $directive = new DirectiveGrammar(); |
| 88 | - if ($directive->parse($src, $n->offset)) { |
|
| 89 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 88 | + if ($directive->parse($src, $n->offset)){ |
|
| 89 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
| 90 | 90 | // configure braces syntax |
| 91 | 91 | $this->declare($directive->getBody()); |
| 92 | - } else { |
|
| 92 | + }else{ |
|
| 93 | 93 | if ( |
| 94 | 94 | $this->directiveRenderer !== null |
| 95 | 95 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
| 96 | - ) { |
|
| 96 | + ){ |
|
| 97 | 97 | // directive opening char |
| 98 | 98 | yield $n; |
| 99 | 99 | |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | /** @var BracesGrammar|null $braces */ |
| 116 | 116 | $braces = null; |
| 117 | - if ($this->echo->starts($src, $n)) { |
|
| 117 | + if ($this->echo->starts($src, $n)){ |
|
| 118 | 118 | $braces = clone $this->echo; |
| 119 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 119 | + } elseif ($this->raw->starts($src, $n)){ |
|
| 120 | 120 | $braces = clone $this->raw; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if ($braces !== null) { |
|
| 123 | + if ($braces !== null){ |
|
| 124 | 124 | $echo = $braces->parse($src, $n); |
| 125 | - if ($echo !== null) { |
|
| 125 | + if ($echo !== null){ |
|
| 126 | 126 | yield from $echo; |
| 127 | 127 | continue; |
| 128 | 128 | } |
@@ -154,20 +154,20 @@ discard block |
||
| 154 | 154 | }; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - private function declare(?string $body): void |
|
| 157 | + private function declare(?string$body) : void |
|
| 158 | 158 | { |
| 159 | - if ($body === null) { |
|
| 159 | + if ($body === null){ |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 163 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
| 164 | 164 | $value = \trim($value, '\'" '); |
| 165 | - switch ($option) { |
|
| 165 | + switch ($option){ |
|
| 166 | 166 | case 'syntax': |
| 167 | 167 | $this->echo->setActive($value !== 'off'); |
| 168 | 168 | $this->raw->setActive($value !== 'off'); |
| 169 | 169 | |
| 170 | - if ($value === 'default') { |
|
| 170 | + if ($value === 'default'){ |
|
| 171 | 171 | $this->echo->setStartSequence('{{'); |
| 172 | 172 | $this->echo->setEndSequence('}}'); |
| 173 | 173 | $this->raw->setStartSequence('{!!'); |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | $keyword = null; |
| 205 | 205 | |
| 206 | 206 | /** @var Token $token */ |
| 207 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 208 | - switch ($token->type) { |
|
| 207 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
| 208 | + switch ($token->type){ |
|
| 209 | 209 | case DeclareGrammar::TYPE_KEYWORD: |
| 210 | - if ($keyword !== null) { |
|
| 210 | + if ($keyword !== null){ |
|
| 211 | 211 | $options[$keyword] = $token->content; |
| 212 | 212 | $keyword = null; |
| 213 | 213 | break; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $keyword = $token->content; |
| 216 | 216 | break; |
| 217 | 217 | case DeclareGrammar::TYPE_QUOTED: |
| 218 | - if ($keyword !== null) { |
|
| 218 | + if ($keyword !== null){ |
|
| 219 | 219 | $options[$keyword] = \trim($token->content, $token->content[0]); |
| 220 | 220 | $keyword = null; |
| 221 | 221 | break; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $keyword = \trim($token->content, $token->content[0]); |
| 225 | 225 | break; |
| 226 | 226 | case DeclareGrammar::TYPE_COMMA: |
| 227 | - if ($keyword !== null) { |
|
| 227 | + if ($keyword !== null){ |
|
| 228 | 228 | $options[$keyword] = null; |
| 229 | 229 | $keyword = null; |
| 230 | 230 | break; |
@@ -67,13 +67,16 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public function parse(Buffer $src): \Generator |
| 69 | 69 | { |
| 70 | - while ($n = $src->next()) { |
|
| 71 | - if (!$n instanceof Byte) { |
|
| 70 | + while ($n = $src->next()) |
|
| 71 | + { |
|
| 72 | + if (!$n instanceof Byte) |
|
| 73 | + { |
|
| 72 | 74 | yield $n; |
| 73 | 75 | continue; |
| 74 | 76 | } |
| 75 | 77 | |
| 76 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 78 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
| 79 | + { |
|
| 77 | 80 | if ( |
| 78 | 81 | $this->echo->nextToken($src) || |
| 79 | 82 | $this->raw->nextToken($src) || |
@@ -85,11 +88,15 @@ discard block |
||
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | $directive = new DirectiveGrammar(); |
| 88 | - if ($directive->parse($src, $n->offset)) { |
|
| 89 | - if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 91 | + if ($directive->parse($src, $n->offset)) |
|
| 92 | + { |
|
| 93 | + if (\strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
| 94 | + { |
|
| 90 | 95 | // configure braces syntax |
| 91 | 96 | $this->declare($directive->getBody()); |
| 92 | - } else { |
|
| 97 | + } |
|
| 98 | + else |
|
| 99 | + { |
|
| 93 | 100 | if ( |
| 94 | 101 | $this->directiveRenderer !== null |
| 95 | 102 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -114,15 +121,20 @@ discard block |
||
| 114 | 121 | |
| 115 | 122 | /** @var BracesGrammar|null $braces */ |
| 116 | 123 | $braces = null; |
| 117 | - if ($this->echo->starts($src, $n)) { |
|
| 124 | + if ($this->echo->starts($src, $n)) |
|
| 125 | + { |
|
| 118 | 126 | $braces = clone $this->echo; |
| 119 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 127 | + } |
|
| 128 | + elseif ($this->raw->starts($src, $n)) |
|
| 129 | + { |
|
| 120 | 130 | $braces = clone $this->raw; |
| 121 | 131 | } |
| 122 | 132 | |
| 123 | - if ($braces !== null) { |
|
| 133 | + if ($braces !== null) |
|
| 134 | + { |
|
| 124 | 135 | $echo = $braces->parse($src, $n); |
| 125 | - if ($echo !== null) { |
|
| 136 | + if ($echo !== null) |
|
| 137 | + { |
|
| 126 | 138 | yield from $echo; |
| 127 | 139 | continue; |
| 128 | 140 | } |
@@ -156,18 +168,22 @@ discard block |
||
| 156 | 168 | |
| 157 | 169 | private function declare(?string $body): void |
| 158 | 170 | { |
| 159 | - if ($body === null) { |
|
| 171 | + if ($body === null) |
|
| 172 | + { |
|
| 160 | 173 | return; |
| 161 | 174 | } |
| 162 | 175 | |
| 163 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 176 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
| 177 | + { |
|
| 164 | 178 | $value = \trim($value, '\'" '); |
| 165 | - switch ($option) { |
|
| 179 | + switch ($option) |
|
| 180 | + { |
|
| 166 | 181 | case 'syntax': |
| 167 | 182 | $this->echo->setActive($value !== 'off'); |
| 168 | 183 | $this->raw->setActive($value !== 'off'); |
| 169 | 184 | |
| 170 | - if ($value === 'default') { |
|
| 185 | + if ($value === 'default') |
|
| 186 | + { |
|
| 171 | 187 | $this->echo->setStartSequence('{{'); |
| 172 | 188 | $this->echo->setEndSequence('}}'); |
| 173 | 189 | $this->raw->setStartSequence('{!!'); |
@@ -204,10 +220,13 @@ discard block |
||
| 204 | 220 | $keyword = null; |
| 205 | 221 | |
| 206 | 222 | /** @var Token $token */ |
| 207 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 208 | - switch ($token->type) { |
|
| 223 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
| 224 | + { |
|
| 225 | + switch ($token->type) |
|
| 226 | + { |
|
| 209 | 227 | case DeclareGrammar::TYPE_KEYWORD: |
| 210 | - if ($keyword !== null) { |
|
| 228 | + if ($keyword !== null) |
|
| 229 | + { |
|
| 211 | 230 | $options[$keyword] = $token->content; |
| 212 | 231 | $keyword = null; |
| 213 | 232 | break; |
@@ -215,7 +234,8 @@ discard block |
||
| 215 | 234 | $keyword = $token->content; |
| 216 | 235 | break; |
| 217 | 236 | case DeclareGrammar::TYPE_QUOTED: |
| 218 | - if ($keyword !== null) { |
|
| 237 | + if ($keyword !== null) |
|
| 238 | + { |
|
| 219 | 239 | $options[$keyword] = \trim($token->content, $token->content[0]); |
| 220 | 240 | $keyword = null; |
| 221 | 241 | break; |
@@ -224,7 +244,8 @@ discard block |
||
| 224 | 244 | $keyword = \trim($token->content, $token->content[0]); |
| 225 | 245 | break; |
| 226 | 246 | case DeclareGrammar::TYPE_COMMA: |
| 227 | - if ($keyword !== null) { |
|
| 247 | + if ($keyword !== null) |
|
| 248 | + { |
|
| 228 | 249 | $options[$keyword] = null; |
| 229 | 250 | $keyword = null; |
| 230 | 251 | break; |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function parse(Buffer $src): \Generator |
| 18 | 18 | { |
| 19 | - while ($n = $src->next()) { |
|
| 20 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
| 19 | + while ($n = $src->next()){ |
|
| 20 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?'){ |
|
| 21 | 21 | yield $n; |
| 22 | 22 | continue; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
|
| 26 | - if ($php === null) { |
|
| 25 | + $php = $this->parseGrammar($n->char.$src->nextBytes(), $n->offset); |
|
| 26 | + if ($php === null){ |
|
| 27 | 27 | yield $n; |
| 28 | 28 | $src->replay($n->offset); |
| 29 | 29 | continue; |
@@ -45,25 +45,25 @@ discard block |
||
| 45 | 45 | private function parseGrammar(string $content, int $offset): ?Token |
| 46 | 46 | { |
| 47 | 47 | $tokens = null; |
| 48 | - foreach (\token_get_all($content) as $token) { |
|
| 49 | - if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
| 48 | + foreach (\token_get_all($content) as $token){ |
|
| 49 | + if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])){ |
|
| 50 | 50 | // not php |
| 51 | 51 | return null; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | $tokens[] = $token; |
| 55 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
| 55 | + if ($this->is($token, [T_CLOSE_TAG])){ |
|
| 56 | 56 | break; |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ($tokens === null) { |
|
| 60 | + if ($tokens === null){ |
|
| 61 | 61 | return null; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $buffer = ''; |
| 65 | - foreach ($tokens as $token) { |
|
| 66 | - if (!\is_array($token)) { |
|
| 65 | + foreach ($tokens as $token){ |
|
| 66 | + if (!\is_array($token)){ |
|
| 67 | 67 | $buffer .= $token; |
| 68 | 68 | continue; |
| 69 | 69 | } |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | return $token; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function is(array|string $token, array $type): bool |
|
| 79 | + private function is(array | string $token, array $type): bool |
|
| 80 | 80 | { |
| 81 | - if (!\is_array($token)) { |
|
| 81 | + if (!\is_array($token)){ |
|
| 82 | 82 | return false; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -16,14 +16,17 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | public function parse(Buffer $src): \Generator |
| 18 | 18 | { |
| 19 | - while ($n = $src->next()) { |
|
| 20 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
| 19 | + while ($n = $src->next()) |
|
| 20 | + { |
|
| 21 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') |
|
| 22 | + { |
|
| 21 | 23 | yield $n; |
| 22 | 24 | continue; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
| 26 | - if ($php === null) { |
|
| 28 | + if ($php === null) |
|
| 29 | + { |
|
| 27 | 30 | yield $n; |
| 28 | 31 | $src->replay($n->offset); |
| 29 | 32 | continue; |
@@ -45,25 +48,31 @@ discard block |
||
| 45 | 48 | private function parseGrammar(string $content, int $offset): ?Token |
| 46 | 49 | { |
| 47 | 50 | $tokens = null; |
| 48 | - foreach (\token_get_all($content) as $token) { |
|
| 49 | - if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
| 51 | + foreach (\token_get_all($content) as $token) |
|
| 52 | + { |
|
| 53 | + if ($tokens === null && !$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) |
|
| 54 | + { |
|
| 50 | 55 | // not php |
| 51 | 56 | return null; |
| 52 | 57 | } |
| 53 | 58 | |
| 54 | 59 | $tokens[] = $token; |
| 55 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
| 60 | + if ($this->is($token, [T_CLOSE_TAG])) |
|
| 61 | + { |
|
| 56 | 62 | break; |
| 57 | 63 | } |
| 58 | 64 | } |
| 59 | 65 | |
| 60 | - if ($tokens === null) { |
|
| 66 | + if ($tokens === null) |
|
| 67 | + { |
|
| 61 | 68 | return null; |
| 62 | 69 | } |
| 63 | 70 | |
| 64 | 71 | $buffer = ''; |
| 65 | - foreach ($tokens as $token) { |
|
| 66 | - if (!\is_array($token)) { |
|
| 72 | + foreach ($tokens as $token) |
|
| 73 | + { |
|
| 74 | + if (!\is_array($token)) |
|
| 75 | + { |
|
| 67 | 76 | $buffer .= $token; |
| 68 | 77 | continue; |
| 69 | 78 | } |
@@ -78,7 +87,8 @@ discard block |
||
| 78 | 87 | |
| 79 | 88 | private function is(array|string $token, array $type): bool |
| 80 | 89 | { |
| 81 | - if (!\is_array($token)) { |
|
| 90 | + if (!\is_array($token)) |
|
| 91 | + { |
|
| 82 | 92 | return false; |
| 83 | 93 | } |
| 84 | 94 | |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function parse(Buffer $src): \Generator |
| 49 | 49 | { |
| 50 | - while ($n = $src->next()) { |
|
| 51 | - if (!$n instanceof Byte || $n->char !== '<') { |
|
| 50 | + while ($n = $src->next()){ |
|
| 51 | + if (!$n instanceof Byte || $n->char !== '<'){ |
|
| 52 | 52 | yield $n; |
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // work with isolated token stream! |
| 57 | 57 | $tag = (clone $this)->parseGrammar($src); |
| 58 | - if ($tag === null) { |
|
| 58 | + if ($tag === null){ |
|
| 59 | 59 | yield $n; |
| 60 | 60 | $src->replay($n->offset); |
| 61 | 61 | continue; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $tagName = $this->tagName($tag); |
| 65 | 65 | |
| 66 | 66 | // todo: add support for custom tag list |
| 67 | - if (\in_array($tagName, self::VERBATIM_TAGS)) { |
|
| 67 | + if (\in_array($tagName, self::VERBATIM_TAGS)){ |
|
| 68 | 68 | yield from $tag; |
| 69 | 69 | yield from $this->parseVerbatim($src, $tagName); |
| 70 | 70 | continue; |
@@ -98,26 +98,26 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | $chunks = []; |
| 100 | 100 | |
| 101 | - while ($n = $src->next()) { |
|
| 102 | - if ($n instanceof Token) { |
|
| 101 | + while ($n = $src->next()){ |
|
| 102 | + if ($n instanceof Token){ |
|
| 103 | 103 | $chunks[] = $n; |
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - switch ($n->char) { |
|
| 107 | + switch ($n->char){ |
|
| 108 | 108 | case '"': |
| 109 | 109 | case "'": |
| 110 | 110 | case '`': |
| 111 | 111 | $chunks[] = $n; |
| 112 | 112 | |
| 113 | 113 | // language inclusions allow nested strings |
| 114 | - while ($nc = $src->next()) { |
|
| 114 | + while ($nc = $src->next()){ |
|
| 115 | 115 | $chunks[] = $nc; |
| 116 | - if ($nc instanceof Token) { |
|
| 116 | + if ($nc instanceof Token){ |
|
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ($nc->char === $n->char) { |
|
| 120 | + if ($nc->char === $n->char){ |
|
| 121 | 121 | break; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -128,22 +128,22 @@ discard block |
||
| 128 | 128 | $chunks[] = $n; |
| 129 | 129 | |
| 130 | 130 | $multiline = false; |
| 131 | - if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*') { |
|
| 132 | - if ($src->lookaheadByte(1) === '*') { |
|
| 131 | + if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*'){ |
|
| 132 | + if ($src->lookaheadByte(1) === '*'){ |
|
| 133 | 133 | $multiline = true; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $chunks[] = $src->next(); |
| 137 | 137 | |
| 138 | 138 | // language inclusions allow nested strings |
| 139 | - while ($nc = $src->next()) { |
|
| 140 | - if ($nc instanceof Token) { |
|
| 139 | + while ($nc = $src->next()){ |
|
| 140 | + if ($nc instanceof Token){ |
|
| 141 | 141 | continue; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ($nc->char === '<') { |
|
| 144 | + if ($nc->char === '<'){ |
|
| 145 | 145 | $tag = (clone $this)->parseGrammar($src); |
| 146 | - if ($tag === null || $this->tagName($tag) !== $verbatim) { |
|
| 146 | + if ($tag === null || $this->tagName($tag) !== $verbatim){ |
|
| 147 | 147 | $src->replay($n->offset); |
| 148 | 148 | break; |
| 149 | 149 | } |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | $chunks[] = $nc; |
| 156 | 156 | |
| 157 | - if ($multiline) { |
|
| 158 | - if ($nc->char === '*' && $src->lookaheadByte(1) === '/') { |
|
| 157 | + if ($multiline){ |
|
| 158 | + if ($nc->char === '*' && $src->lookaheadByte(1) === '/'){ |
|
| 159 | 159 | $chunks[] = $src->next(); |
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | - } elseif ($nc->char === "\n") { |
|
| 162 | + } elseif ($nc->char === "\n"){ |
|
| 163 | 163 | break; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | case '<': |
| 171 | 171 | // tag beginning? |
| 172 | 172 | $tag = (clone $this)->parseGrammar($src); |
| 173 | - if ($tag === null || $this->tagName($tag) !== $verbatim) { |
|
| 173 | + if ($tag === null || $this->tagName($tag) !== $verbatim){ |
|
| 174 | 174 | $chunks[] = $n; |
| 175 | 175 | $src->replay($n->offset); |
| 176 | 176 | break; |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | private function tagName(array $tag): string |
| 192 | 192 | { |
| 193 | - foreach ($tag as $token) { |
|
| 194 | - if ($token->type === self::TYPE_KEYWORD) { |
|
| 193 | + foreach ($tag as $token){ |
|
| 194 | + if ($token->type === self::TYPE_KEYWORD){ |
|
| 195 | 195 | return \strtolower($token->content); |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -210,28 +210,28 @@ discard block |
||
| 210 | 210 | new Token(self::TYPE_OPEN, $src->getOffset(), '<'), |
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | - if ($src->lookaheadByte() === '/') { |
|
| 213 | + if ($src->lookaheadByte() === '/'){ |
|
| 214 | 214 | $this->tokens[0]->type = self::TYPE_OPEN_SHORT; |
| 215 | 215 | $this->tokens[0]->content .= $src->next()->char; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - while ($n = $src->next()) { |
|
| 219 | - if ($this->attribute !== []) { |
|
| 218 | + while ($n = $src->next()){ |
|
| 219 | + if ($this->attribute !== []){ |
|
| 220 | 220 | $this->attribute[] = $n; |
| 221 | 221 | |
| 222 | - if ($n instanceof Byte && $n->char === $this->attribute[0]->char) { |
|
| 222 | + if ($n instanceof Byte && $n->char === $this->attribute[0]->char){ |
|
| 223 | 223 | $this->flushAttribute(); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | continue; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if ($n instanceof Token) { |
|
| 229 | + if ($n instanceof Token){ |
|
| 230 | 230 | $this->keyword[] = $n; |
| 231 | 231 | continue; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - switch ($n->char) { |
|
| 234 | + switch ($n->char){ |
|
| 235 | 235 | case '"': |
| 236 | 236 | case "'": |
| 237 | 237 | case '`': |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | break; |
| 250 | 250 | |
| 251 | 251 | case '/': |
| 252 | - if ($src->lookaheadByte() === '>') { |
|
| 252 | + if ($src->lookaheadByte() === '>'){ |
|
| 253 | 253 | $this->flush(); |
| 254 | 254 | $this->tokens[] = new Token( |
| 255 | 255 | self::TYPE_CLOSE_SHORT, |
| 256 | 256 | $n->offset, |
| 257 | - $n->char . $src->next()->char |
|
| 257 | + $n->char.$src->next()->char |
|
| 258 | 258 | ); |
| 259 | 259 | |
| 260 | 260 | break 2; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | break 2; |
| 274 | 274 | |
| 275 | 275 | default: |
| 276 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 276 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
| 277 | 277 | $this->flushKeyword(); |
| 278 | 278 | $this->whitespace[] = $n; |
| 279 | 279 | break; |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | $this->flushWhitespace(); |
| 282 | 282 | |
| 283 | 283 | |
| 284 | - if (!\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 284 | + if (!\preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
| 285 | 285 | // unexpected char |
| 286 | 286 | return null; |
| 287 | 287 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if (!$this->isValid()) { |
|
| 293 | + if (!$this->isValid()){ |
|
| 294 | 294 | return null; |
| 295 | 295 | } |
| 296 | 296 | |
@@ -300,17 +300,17 @@ discard block |
||
| 300 | 300 | private function isValid(): bool |
| 301 | 301 | { |
| 302 | 302 | // tag is too short or does not have name keyword |
| 303 | - if (\count($this->tokens) < 3) { |
|
| 303 | + if (\count($this->tokens) < 3){ |
|
| 304 | 304 | return false; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | $last = $this->tokens[\count($this->tokens) - 1]; |
| 308 | - if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT) { |
|
| 308 | + if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT){ |
|
| 309 | 309 | return false; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - foreach ($this->tokens as $token) { |
|
| 313 | - switch ($token->type) { |
|
| 312 | + foreach ($this->tokens as $token){ |
|
| 313 | + switch ($token->type){ |
|
| 314 | 314 | case self::TYPE_WHITESPACE: |
| 315 | 315 | // ignore |
| 316 | 316 | continue 2; |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | private function flushWhitespace(): void |
| 343 | 343 | { |
| 344 | - if ($this->whitespace === []) { |
|
| 344 | + if ($this->whitespace === []){ |
|
| 345 | 345 | return; |
| 346 | 346 | } |
| 347 | 347 | |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | private function flushKeyword(): void |
| 356 | 356 | { |
| 357 | - if ($this->keyword === []) { |
|
| 357 | + if ($this->keyword === []){ |
|
| 358 | 358 | return; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | */ |
| 368 | 368 | private function flushAttribute(): void |
| 369 | 369 | { |
| 370 | - if ($this->attribute === []) { |
|
| 370 | + if ($this->attribute === []){ |
|
| 371 | 371 | return; |
| 372 | 372 | } |
| 373 | 373 | |
@@ -47,15 +47,18 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function parse(Buffer $src): \Generator |
| 49 | 49 | { |
| 50 | - while ($n = $src->next()) { |
|
| 51 | - if (!$n instanceof Byte || $n->char !== '<') { |
|
| 50 | + while ($n = $src->next()) |
|
| 51 | + { |
|
| 52 | + if (!$n instanceof Byte || $n->char !== '<') |
|
| 53 | + { |
|
| 52 | 54 | yield $n; |
| 53 | 55 | continue; |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | // work with isolated token stream! |
| 57 | 59 | $tag = (clone $this)->parseGrammar($src); |
| 58 | - if ($tag === null) { |
|
| 60 | + if ($tag === null) |
|
| 61 | + { |
|
| 59 | 62 | yield $n; |
| 60 | 63 | $src->replay($n->offset); |
| 61 | 64 | continue; |
@@ -64,7 +67,8 @@ discard block |
||
| 64 | 67 | $tagName = $this->tagName($tag); |
| 65 | 68 | |
| 66 | 69 | // todo: add support for custom tag list |
| 67 | - if (\in_array($tagName, self::VERBATIM_TAGS)) { |
|
| 70 | + if (\in_array($tagName, self::VERBATIM_TAGS)) |
|
| 71 | + { |
|
| 68 | 72 | yield from $tag; |
| 69 | 73 | yield from $this->parseVerbatim($src, $tagName); |
| 70 | 74 | continue; |
@@ -98,26 +102,32 @@ discard block |
||
| 98 | 102 | { |
| 99 | 103 | $chunks = []; |
| 100 | 104 | |
| 101 | - while ($n = $src->next()) { |
|
| 102 | - if ($n instanceof Token) { |
|
| 105 | + while ($n = $src->next()) |
|
| 106 | + { |
|
| 107 | + if ($n instanceof Token) |
|
| 108 | + { |
|
| 103 | 109 | $chunks[] = $n; |
| 104 | 110 | continue; |
| 105 | 111 | } |
| 106 | 112 | |
| 107 | - switch ($n->char) { |
|
| 113 | + switch ($n->char) |
|
| 114 | + { |
|
| 108 | 115 | case '"': |
| 109 | 116 | case "'": |
| 110 | 117 | case '`': |
| 111 | 118 | $chunks[] = $n; |
| 112 | 119 | |
| 113 | 120 | // language inclusions allow nested strings |
| 114 | - while ($nc = $src->next()) { |
|
| 121 | + while ($nc = $src->next()) |
|
| 122 | + { |
|
| 115 | 123 | $chunks[] = $nc; |
| 116 | - if ($nc instanceof Token) { |
|
| 124 | + if ($nc instanceof Token) |
|
| 125 | + { |
|
| 117 | 126 | continue; |
| 118 | 127 | } |
| 119 | 128 | |
| 120 | - if ($nc->char === $n->char) { |
|
| 129 | + if ($nc->char === $n->char) |
|
| 130 | + { |
|
| 121 | 131 | break; |
| 122 | 132 | } |
| 123 | 133 | } |
@@ -128,22 +138,28 @@ discard block |
||
| 128 | 138 | $chunks[] = $n; |
| 129 | 139 | |
| 130 | 140 | $multiline = false; |
| 131 | - if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*') { |
|
| 132 | - if ($src->lookaheadByte(1) === '*') { |
|
| 141 | + if ($src->lookaheadByte(1) === '/' || $src->lookaheadByte(1) === '*') |
|
| 142 | + { |
|
| 143 | + if ($src->lookaheadByte(1) === '*') |
|
| 144 | + { |
|
| 133 | 145 | $multiline = true; |
| 134 | 146 | } |
| 135 | 147 | |
| 136 | 148 | $chunks[] = $src->next(); |
| 137 | 149 | |
| 138 | 150 | // language inclusions allow nested strings |
| 139 | - while ($nc = $src->next()) { |
|
| 140 | - if ($nc instanceof Token) { |
|
| 151 | + while ($nc = $src->next()) |
|
| 152 | + { |
|
| 153 | + if ($nc instanceof Token) |
|
| 154 | + { |
|
| 141 | 155 | continue; |
| 142 | 156 | } |
| 143 | 157 | |
| 144 | - if ($nc->char === '<') { |
|
| 158 | + if ($nc->char === '<') |
|
| 159 | + { |
|
| 145 | 160 | $tag = (clone $this)->parseGrammar($src); |
| 146 | - if ($tag === null || $this->tagName($tag) !== $verbatim) { |
|
| 161 | + if ($tag === null || $this->tagName($tag) !== $verbatim) |
|
| 162 | + { |
|
| 147 | 163 | $src->replay($n->offset); |
| 148 | 164 | break; |
| 149 | 165 | } |
@@ -154,12 +170,16 @@ discard block |
||
| 154 | 170 | |
| 155 | 171 | $chunks[] = $nc; |
| 156 | 172 | |
| 157 | - if ($multiline) { |
|
| 158 | - if ($nc->char === '*' && $src->lookaheadByte(1) === '/') { |
|
| 173 | + if ($multiline) |
|
| 174 | + { |
|
| 175 | + if ($nc->char === '*' && $src->lookaheadByte(1) === '/') |
|
| 176 | + { |
|
| 159 | 177 | $chunks[] = $src->next(); |
| 160 | 178 | break; |
| 161 | 179 | } |
| 162 | - } elseif ($nc->char === "\n") { |
|
| 180 | + } |
|
| 181 | + elseif ($nc->char === "\n") |
|
| 182 | + { |
|
| 163 | 183 | break; |
| 164 | 184 | } |
| 165 | 185 | } |
@@ -170,7 +190,8 @@ discard block |
||
| 170 | 190 | case '<': |
| 171 | 191 | // tag beginning? |
| 172 | 192 | $tag = (clone $this)->parseGrammar($src); |
| 173 | - if ($tag === null || $this->tagName($tag) !== $verbatim) { |
|
| 193 | + if ($tag === null || $this->tagName($tag) !== $verbatim) |
|
| 194 | + { |
|
| 174 | 195 | $chunks[] = $n; |
| 175 | 196 | $src->replay($n->offset); |
| 176 | 197 | break; |
@@ -190,8 +211,10 @@ discard block |
||
| 190 | 211 | |
| 191 | 212 | private function tagName(array $tag): string |
| 192 | 213 | { |
| 193 | - foreach ($tag as $token) { |
|
| 194 | - if ($token->type === self::TYPE_KEYWORD) { |
|
| 214 | + foreach ($tag as $token) |
|
| 215 | + { |
|
| 216 | + if ($token->type === self::TYPE_KEYWORD) |
|
| 217 | + { |
|
| 195 | 218 | return \strtolower($token->content); |
| 196 | 219 | } |
| 197 | 220 | } |
@@ -210,28 +233,34 @@ discard block |
||
| 210 | 233 | new Token(self::TYPE_OPEN, $src->getOffset(), '<'), |
| 211 | 234 | ]; |
| 212 | 235 | |
| 213 | - if ($src->lookaheadByte() === '/') { |
|
| 236 | + if ($src->lookaheadByte() === '/') |
|
| 237 | + { |
|
| 214 | 238 | $this->tokens[0]->type = self::TYPE_OPEN_SHORT; |
| 215 | 239 | $this->tokens[0]->content .= $src->next()->char; |
| 216 | 240 | } |
| 217 | 241 | |
| 218 | - while ($n = $src->next()) { |
|
| 219 | - if ($this->attribute !== []) { |
|
| 242 | + while ($n = $src->next()) |
|
| 243 | + { |
|
| 244 | + if ($this->attribute !== []) |
|
| 245 | + { |
|
| 220 | 246 | $this->attribute[] = $n; |
| 221 | 247 | |
| 222 | - if ($n instanceof Byte && $n->char === $this->attribute[0]->char) { |
|
| 248 | + if ($n instanceof Byte && $n->char === $this->attribute[0]->char) |
|
| 249 | + { |
|
| 223 | 250 | $this->flushAttribute(); |
| 224 | 251 | } |
| 225 | 252 | |
| 226 | 253 | continue; |
| 227 | 254 | } |
| 228 | 255 | |
| 229 | - if ($n instanceof Token) { |
|
| 256 | + if ($n instanceof Token) |
|
| 257 | + { |
|
| 230 | 258 | $this->keyword[] = $n; |
| 231 | 259 | continue; |
| 232 | 260 | } |
| 233 | 261 | |
| 234 | - switch ($n->char) { |
|
| 262 | + switch ($n->char) |
|
| 263 | + { |
|
| 235 | 264 | case '"': |
| 236 | 265 | case "'": |
| 237 | 266 | case '`': |
@@ -249,7 +278,8 @@ discard block |
||
| 249 | 278 | break; |
| 250 | 279 | |
| 251 | 280 | case '/': |
| 252 | - if ($src->lookaheadByte() === '>') { |
|
| 281 | + if ($src->lookaheadByte() === '>') |
|
| 282 | + { |
|
| 253 | 283 | $this->flush(); |
| 254 | 284 | $this->tokens[] = new Token( |
| 255 | 285 | self::TYPE_CLOSE_SHORT, |
@@ -273,7 +303,8 @@ discard block |
||
| 273 | 303 | break 2; |
| 274 | 304 | |
| 275 | 305 | default: |
| 276 | - if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 306 | + if (\preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
| 307 | + { |
|
| 277 | 308 | $this->flushKeyword(); |
| 278 | 309 | $this->whitespace[] = $n; |
| 279 | 310 | break; |
@@ -281,7 +312,8 @@ discard block |
||
| 281 | 312 | $this->flushWhitespace(); |
| 282 | 313 | |
| 283 | 314 | |
| 284 | - if (!\preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 315 | + if (!\preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
| 316 | + { |
|
| 285 | 317 | // unexpected char |
| 286 | 318 | return null; |
| 287 | 319 | } |
@@ -290,7 +322,8 @@ discard block |
||
| 290 | 322 | } |
| 291 | 323 | } |
| 292 | 324 | |
| 293 | - if (!$this->isValid()) { |
|
| 325 | + if (!$this->isValid()) |
|
| 326 | + { |
|
| 294 | 327 | return null; |
| 295 | 328 | } |
| 296 | 329 | |
@@ -300,17 +333,21 @@ discard block |
||
| 300 | 333 | private function isValid(): bool |
| 301 | 334 | { |
| 302 | 335 | // tag is too short or does not have name keyword |
| 303 | - if (\count($this->tokens) < 3) { |
|
| 336 | + if (\count($this->tokens) < 3) |
|
| 337 | + { |
|
| 304 | 338 | return false; |
| 305 | 339 | } |
| 306 | 340 | |
| 307 | 341 | $last = $this->tokens[\count($this->tokens) - 1]; |
| 308 | - if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT) { |
|
| 342 | + if ($last->type !== self::TYPE_CLOSE && $last->type !== self::TYPE_CLOSE_SHORT) |
|
| 343 | + { |
|
| 309 | 344 | return false; |
| 310 | 345 | } |
| 311 | 346 | |
| 312 | - foreach ($this->tokens as $token) { |
|
| 313 | - switch ($token->type) { |
|
| 347 | + foreach ($this->tokens as $token) |
|
| 348 | + { |
|
| 349 | + switch ($token->type) |
|
| 350 | + { |
|
| 314 | 351 | case self::TYPE_WHITESPACE: |
| 315 | 352 | // ignore |
| 316 | 353 | continue 2; |
@@ -341,7 +378,8 @@ discard block |
||
| 341 | 378 | */ |
| 342 | 379 | private function flushWhitespace(): void |
| 343 | 380 | { |
| 344 | - if ($this->whitespace === []) { |
|
| 381 | + if ($this->whitespace === []) |
|
| 382 | + { |
|
| 345 | 383 | return; |
| 346 | 384 | } |
| 347 | 385 | |
@@ -354,7 +392,8 @@ discard block |
||
| 354 | 392 | */ |
| 355 | 393 | private function flushKeyword(): void |
| 356 | 394 | { |
| 357 | - if ($this->keyword === []) { |
|
| 395 | + if ($this->keyword === []) |
|
| 396 | + { |
|
| 358 | 397 | return; |
| 359 | 398 | } |
| 360 | 399 | |
@@ -367,7 +406,8 @@ discard block |
||
| 367 | 406 | */ |
| 368 | 407 | private function flushAttribute(): void |
| 369 | 408 | { |
| 370 | - if ($this->attribute === []) { |
|
| 409 | + if ($this->attribute === []) |
|
| 410 | + { |
|
| 371 | 411 | return; |
| 372 | 412 | } |
| 373 | 413 | |
@@ -9,6 +9,6 @@ |
||
| 9 | 9 | public function __construct( |
| 10 | 10 | public int $offset, |
| 11 | 11 | public string $char |
| 12 | - ) { |
|
| 12 | + ){ |
|
| 13 | 13 | } |
| 14 | 14 | } |
@@ -31,20 +31,20 @@ discard block |
||
| 31 | 31 | public function parse(StreamInterface $src): \Generator |
| 32 | 32 | { |
| 33 | 33 | $stream = new Buffer($this->generate($src)); |
| 34 | - foreach ($this->grammars as $grammar) { |
|
| 34 | + foreach ($this->grammars as $grammar){ |
|
| 35 | 35 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // always group raw bytes into raw tokens |
| 39 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
| 39 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n){ |
|
| 40 | 40 | yield $n; |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
| 45 | 45 | { |
| 46 | - foreach ($grammar->parse($stream) as $n) { |
|
| 47 | - if ($n instanceof Token && $n->grammar === null) { |
|
| 46 | + foreach ($grammar->parse($stream) as $n){ |
|
| 47 | + if ($n instanceof Token && $n->grammar === null){ |
|
| 48 | 48 | $n->grammar = $grammar::class; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | private function generate(StreamInterface $src): \Generator |
| 61 | 61 | { |
| 62 | - while (!$src->isEOI()) { |
|
| 62 | + while (!$src->isEOI()){ |
|
| 63 | 63 | yield new Byte($src->getOffset(), $src->peak()); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -31,20 +31,24 @@ discard block |
||
| 31 | 31 | public function parse(StreamInterface $src): \Generator |
| 32 | 32 | { |
| 33 | 33 | $stream = new Buffer($this->generate($src)); |
| 34 | - foreach ($this->grammars as $grammar) { |
|
| 34 | + foreach ($this->grammars as $grammar) |
|
| 35 | + { |
|
| 35 | 36 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
| 36 | 37 | } |
| 37 | 38 | |
| 38 | 39 | // always group raw bytes into raw tokens |
| 39 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
| 40 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n) |
|
| 41 | + { |
|
| 40 | 42 | yield $n; |
| 41 | 43 | } |
| 42 | 44 | } |
| 43 | 45 | |
| 44 | 46 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
| 45 | 47 | { |
| 46 | - foreach ($grammar->parse($stream) as $n) { |
|
| 47 | - if ($n instanceof Token && $n->grammar === null) { |
|
| 48 | + foreach ($grammar->parse($stream) as $n) |
|
| 49 | + { |
|
| 50 | + if ($n instanceof Token && $n->grammar === null) |
|
| 51 | + { |
|
| 48 | 52 | $n->grammar = $grammar::class; |
| 49 | 53 | } |
| 50 | 54 | |
@@ -59,7 +63,8 @@ discard block |
||
| 59 | 63 | */ |
| 60 | 64 | private function generate(StreamInterface $src): \Generator |
| 61 | 65 | { |
| 62 | - while (!$src->isEOI()) { |
|
| 66 | + while (!$src->isEOI()) |
|
| 67 | + { |
|
| 63 | 68 | yield new Byte($src->getOffset(), $src->peak()); |
| 64 | 69 | } |
| 65 | 70 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | { |
| 14 | 14 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
| 15 | 15 | { |
| 16 | - if ($node instanceof PHP) { |
|
| 16 | + if ($node instanceof PHP){ |
|
| 17 | 17 | $result->push($node->content, $node->getContext()); |
| 18 | 18 | return true; |
| 19 | 19 | } |
@@ -13,7 +13,8 @@ |
||
| 13 | 13 | { |
| 14 | 14 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
| 15 | 15 | { |
| 16 | - if ($node instanceof PHP) { |
|
| 16 | + if ($node instanceof PHP) |
|
| 17 | + { |
|
| 17 | 18 | $result->push($node->content, $node->getContext()); |
| 18 | 19 | return true; |
| 19 | 20 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
| 18 | 18 | { |
| 19 | - switch (true) { |
|
| 19 | + switch (true){ |
|
| 20 | 20 | case $node instanceof Tag: |
| 21 | 21 | $this->tag($compiler, $result, $node); |
| 22 | 22 | return true; |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $result->push(\sprintf('<%s', $node->name), $node->getContext()); |
| 40 | 40 | |
| 41 | - foreach ($node->attrs as $attr) { |
|
| 42 | - if (!$attr instanceof Attr) { |
|
| 41 | + foreach ($node->attrs as $attr){ |
|
| 42 | + if (!$attr instanceof Attr){ |
|
| 43 | 43 | $compiler->compile($attr, $result); |
| 44 | 44 | continue; |
| 45 | 45 | } |
@@ -49,30 +49,30 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $result->push(\sprintf('%s>', $node->void ? '/' : ''), null); |
| 51 | 51 | |
| 52 | - foreach ($node->nodes as $child) { |
|
| 52 | + foreach ($node->nodes as $child){ |
|
| 53 | 53 | $compiler->compile($child, $result); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if (!$node->void) { |
|
| 56 | + if (!$node->void){ |
|
| 57 | 57 | $result->push(\sprintf('</%s>', $node->name), null); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | private function attribute(Compiler $compiler, Compiler\Result $result, Attr $node): void |
| 62 | 62 | { |
| 63 | - if ($node->name instanceof NodeInterface) { |
|
| 63 | + if ($node->name instanceof NodeInterface){ |
|
| 64 | 64 | $result->push(' ', null); |
| 65 | 65 | $compiler->compile($node->name, $result); |
| 66 | - } else { |
|
| 66 | + }else{ |
|
| 67 | 67 | $result->push(\sprintf(' %s', $node->name), $node->getContext()); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $value = $node->value; |
| 71 | - if ($value instanceof Nil) { |
|
| 71 | + if ($value instanceof Nil){ |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($value instanceof NodeInterface) { |
|
| 75 | + if ($value instanceof NodeInterface){ |
|
| 76 | 76 | $result->push('=', null); |
| 77 | 77 | $compiler->compile($value, $result); |
| 78 | 78 | return; |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | private function verbatim(Compiler $compiler, Compiler\Result $result, Verbatim $node): void |
| 85 | 85 | { |
| 86 | - foreach ($node->nodes as $child) { |
|
| 87 | - if (\is_string($child)) { |
|
| 86 | + foreach ($node->nodes as $child){ |
|
| 87 | + if (\is_string($child)){ |
|
| 88 | 88 | $result->push($child, null); |
| 89 | 89 | continue; |
| 90 | 90 | } |
@@ -16,7 +16,8 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
| 18 | 18 | { |
| 19 | - switch (true) { |
|
| 19 | + switch (true) |
|
| 20 | + { |
|
| 20 | 21 | case $node instanceof Tag: |
| 21 | 22 | $this->tag($compiler, $result, $node); |
| 22 | 23 | return true; |
@@ -38,8 +39,10 @@ discard block |
||
| 38 | 39 | { |
| 39 | 40 | $result->push(\sprintf('<%s', $node->name), $node->getContext()); |
| 40 | 41 | |
| 41 | - foreach ($node->attrs as $attr) { |
|
| 42 | - if (!$attr instanceof Attr) { |
|
| 42 | + foreach ($node->attrs as $attr) |
|
| 43 | + { |
|
| 44 | + if (!$attr instanceof Attr) |
|
| 45 | + { |
|
| 43 | 46 | $compiler->compile($attr, $result); |
| 44 | 47 | continue; |
| 45 | 48 | } |
@@ -49,30 +52,37 @@ discard block |
||
| 49 | 52 | |
| 50 | 53 | $result->push(\sprintf('%s>', $node->void ? '/' : ''), null); |
| 51 | 54 | |
| 52 | - foreach ($node->nodes as $child) { |
|
| 55 | + foreach ($node->nodes as $child) |
|
| 56 | + { |
|
| 53 | 57 | $compiler->compile($child, $result); |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | - if (!$node->void) { |
|
| 60 | + if (!$node->void) |
|
| 61 | + { |
|
| 57 | 62 | $result->push(\sprintf('</%s>', $node->name), null); |
| 58 | 63 | } |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | 66 | private function attribute(Compiler $compiler, Compiler\Result $result, Attr $node): void |
| 62 | 67 | { |
| 63 | - if ($node->name instanceof NodeInterface) { |
|
| 68 | + if ($node->name instanceof NodeInterface) |
|
| 69 | + { |
|
| 64 | 70 | $result->push(' ', null); |
| 65 | 71 | $compiler->compile($node->name, $result); |
| 66 | - } else { |
|
| 72 | + } |
|
| 73 | + else |
|
| 74 | + { |
|
| 67 | 75 | $result->push(\sprintf(' %s', $node->name), $node->getContext()); |
| 68 | 76 | } |
| 69 | 77 | |
| 70 | 78 | $value = $node->value; |
| 71 | - if ($value instanceof Nil) { |
|
| 79 | + if ($value instanceof Nil) |
|
| 80 | + { |
|
| 72 | 81 | return; |
| 73 | 82 | } |
| 74 | 83 | |
| 75 | - if ($value instanceof NodeInterface) { |
|
| 84 | + if ($value instanceof NodeInterface) |
|
| 85 | + { |
|
| 76 | 86 | $result->push('=', null); |
| 77 | 87 | $compiler->compile($value, $result); |
| 78 | 88 | return; |
@@ -83,8 +93,10 @@ discard block |
||
| 83 | 93 | |
| 84 | 94 | private function verbatim(Compiler $compiler, Compiler\Result $result, Verbatim $node): void |
| 85 | 95 | { |
| 86 | - foreach ($node->nodes as $child) { |
|
| 87 | - if (\is_string($child)) { |
|
| 96 | + foreach ($node->nodes as $child) |
|
| 97 | + { |
|
| 98 | + if (\is_string($child)) |
|
| 99 | + { |
|
| 88 | 100 | $result->push($child, null); |
| 89 | 101 | continue; |
| 90 | 102 | } |