@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function enterNode($node, VisitorContext $ctx) |
| 34 | 34 | { |
| 35 | - if ($node instanceof Tag) { |
|
| 35 | + if ($node instanceof Tag){ |
|
| 36 | 36 | return $this->makeBlock($node); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if ($node instanceof Inline) { |
|
| 39 | + if ($node instanceof Inline){ |
|
| 40 | 40 | $block = new Block($node->name, $node->getContext()); |
| 41 | - if ($node->value !== null) { |
|
| 41 | + if ($node->value !== null){ |
|
| 42 | 42 | $block->nodes[] = new Raw($node->value); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | private function makeBlock(Tag $node): ?NodeInterface |
| 62 | 62 | { |
| 63 | 63 | $name = null; |
| 64 | - foreach ($this->prefix as $prefix) { |
|
| 65 | - if (strpos($node->name, (string) $prefix) === 0) { |
|
| 64 | + foreach ($this->prefix as $prefix){ |
|
| 65 | + if (strpos($node->name, (string)$prefix) === 0){ |
|
| 66 | 66 | $name = substr($node->name, strlen($prefix)); |
| 67 | 67 | break; |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if ($name === null) { |
|
| 71 | + if ($name === null){ |
|
| 72 | 72 | return null; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -32,13 +32,16 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function enterNode($node, VisitorContext $ctx) |
| 34 | 34 | { |
| 35 | - if ($node instanceof Tag) { |
|
| 35 | + if ($node instanceof Tag) |
|
| 36 | + { |
|
| 36 | 37 | return $this->makeBlock($node); |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | - if ($node instanceof Inline) { |
|
| 40 | + if ($node instanceof Inline) |
|
| 41 | + { |
|
| 40 | 42 | $block = new Block($node->name, $node->getContext()); |
| 41 | - if ($node->value !== null) { |
|
| 43 | + if ($node->value !== null) |
|
| 44 | + { |
|
| 42 | 45 | $block->nodes[] = new Raw($node->value); |
| 43 | 46 | } |
| 44 | 47 | |
@@ -61,14 +64,17 @@ discard block |
||
| 61 | 64 | private function makeBlock(Tag $node): ?NodeInterface |
| 62 | 65 | { |
| 63 | 66 | $name = null; |
| 64 | - foreach ($this->prefix as $prefix) { |
|
| 65 | - if (strpos($node->name, (string) $prefix) === 0) { |
|
| 67 | + foreach ($this->prefix as $prefix) |
|
| 68 | + { |
|
| 69 | + if (strpos($node->name, (string) $prefix) === 0) |
|
| 70 | + { |
|
| 66 | 71 | $name = substr($node->name, strlen($prefix)); |
| 67 | 72 | break; |
| 68 | 73 | } |
| 69 | 74 | } |
| 70 | 75 | |
| 71 | - if ($name === null) { |
|
| 76 | + if ($name === null) |
|
| 77 | + { |
|
| 72 | 78 | return null; |
| 73 | 79 | } |
| 74 | 80 | |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
| 43 | 43 | { |
| 44 | - foreach ($this->getStacks() as $stack) { |
|
| 45 | - if ($stack->accepts($name) !== $name) { |
|
| 44 | + foreach ($this->getStacks() as $stack){ |
|
| 45 | + if ($stack->accepts($name) !== $name){ |
|
| 46 | 46 | continue; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
| 49 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
| 50 | 50 | return true; |
| 51 | 51 | } |
| 52 | 52 | $stack->uniqueIDs[$uniqueID] = true; |
| 53 | 53 | |
| 54 | - foreach ($child->nodes as $child) { |
|
| 54 | + foreach ($child->nodes as $child){ |
|
| 55 | 55 | $stack->nodes[] = $child; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
| 68 | 68 | { |
| 69 | - foreach ($this->getStacks() as $stack) { |
|
| 70 | - if ($stack->accepts($name) !== $name) { |
|
| 69 | + foreach ($this->getStacks() as $stack){ |
|
| 70 | + if ($stack->accepts($name) !== $name){ |
|
| 71 | 71 | continue; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
| 74 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])){ |
|
| 75 | 75 | return true; |
| 76 | 76 | } |
| 77 | 77 | $stack->uniqueIDs[$uniqueID] = true; |
| 78 | 78 | |
| 79 | - foreach ($child->nodes as $child) { |
|
| 79 | + foreach ($child->nodes as $child){ |
|
| 80 | 80 | array_unshift($stack->nodes, $child); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | public function getStacks(): array |
| 95 | 95 | { |
| 96 | 96 | $stacks = []; |
| 97 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
| 98 | - if ($node instanceof AttributedInterface) { |
|
| 99 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
| 97 | + foreach (array_reverse($this->ctx->getScope()) as $node){ |
|
| 98 | + if ($node instanceof AttributedInterface){ |
|
| 99 | + foreach ($node->getAttribute(self::class, []) as $stack){ |
|
| 100 | 100 | $stacks[] = $stack; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | private function getStackRootNode(int $level): AttributedInterface |
| 114 | 114 | { |
| 115 | - if ($level === 0) { |
|
| 115 | + if ($level === 0){ |
|
| 116 | 116 | $node = $this->ctx->getParentNode(); |
| 117 | - } else { |
|
| 117 | + }else{ |
|
| 118 | 118 | $scope = $this->ctx->getScope(); |
| 119 | 119 | |
| 120 | 120 | // looking for the parent node via given nesting level |
| 121 | 121 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if (!$node instanceof AttributedInterface) { |
|
| 124 | + if (!$node instanceof AttributedInterface){ |
|
| 125 | 125 | throw new LogicException( |
| 126 | 126 | sprintf( |
| 127 | 127 | 'Unable to create import on node without attribute storage (%s)', |
@@ -41,17 +41,21 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function push(string $name, Tag $child, string $uniqueID = null): bool |
| 43 | 43 | { |
| 44 | - foreach ($this->getStacks() as $stack) { |
|
| 45 | - if ($stack->accepts($name) !== $name) { |
|
| 44 | + foreach ($this->getStacks() as $stack) |
|
| 45 | + { |
|
| 46 | + if ($stack->accepts($name) !== $name) |
|
| 47 | + { |
|
| 46 | 48 | continue; |
| 47 | 49 | } |
| 48 | 50 | |
| 49 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
| 51 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
| 52 | + { |
|
| 50 | 53 | return true; |
| 51 | 54 | } |
| 52 | 55 | $stack->uniqueIDs[$uniqueID] = true; |
| 53 | 56 | |
| 54 | - foreach ($child->nodes as $child) { |
|
| 57 | + foreach ($child->nodes as $child) |
|
| 58 | + { |
|
| 55 | 59 | $stack->nodes[] = $child; |
| 56 | 60 | } |
| 57 | 61 | |
@@ -66,17 +70,21 @@ discard block |
||
| 66 | 70 | */ |
| 67 | 71 | public function prepend(string $name, Tag $child, string $uniqueID = null): bool |
| 68 | 72 | { |
| 69 | - foreach ($this->getStacks() as $stack) { |
|
| 70 | - if ($stack->accepts($name) !== $name) { |
|
| 73 | + foreach ($this->getStacks() as $stack) |
|
| 74 | + { |
|
| 75 | + if ($stack->accepts($name) !== $name) |
|
| 76 | + { |
|
| 71 | 77 | continue; |
| 72 | 78 | } |
| 73 | 79 | |
| 74 | - if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) { |
|
| 80 | + if ($uniqueID !== null && isset($stack->uniqueIDs[$uniqueID])) |
|
| 81 | + { |
|
| 75 | 82 | return true; |
| 76 | 83 | } |
| 77 | 84 | $stack->uniqueIDs[$uniqueID] = true; |
| 78 | 85 | |
| 79 | - foreach ($child->nodes as $child) { |
|
| 86 | + foreach ($child->nodes as $child) |
|
| 87 | + { |
|
| 80 | 88 | array_unshift($stack->nodes, $child); |
| 81 | 89 | } |
| 82 | 90 | |
@@ -94,9 +102,12 @@ discard block |
||
| 94 | 102 | public function getStacks(): array |
| 95 | 103 | { |
| 96 | 104 | $stacks = []; |
| 97 | - foreach (array_reverse($this->ctx->getScope()) as $node) { |
|
| 98 | - if ($node instanceof AttributedInterface) { |
|
| 99 | - foreach ($node->getAttribute(self::class, []) as $stack) { |
|
| 105 | + foreach (array_reverse($this->ctx->getScope()) as $node) |
|
| 106 | + { |
|
| 107 | + if ($node instanceof AttributedInterface) |
|
| 108 | + { |
|
| 109 | + foreach ($node->getAttribute(self::class, []) as $stack) |
|
| 110 | + { |
|
| 100 | 111 | $stacks[] = $stack; |
| 101 | 112 | } |
| 102 | 113 | } |
@@ -112,16 +123,20 @@ discard block |
||
| 112 | 123 | |
| 113 | 124 | private function getStackRootNode(int $level): AttributedInterface |
| 114 | 125 | { |
| 115 | - if ($level === 0) { |
|
| 126 | + if ($level === 0) |
|
| 127 | + { |
|
| 116 | 128 | $node = $this->ctx->getParentNode(); |
| 117 | - } else { |
|
| 129 | + } |
|
| 130 | + else |
|
| 131 | + { |
|
| 118 | 132 | $scope = $this->ctx->getScope(); |
| 119 | 133 | |
| 120 | 134 | // looking for the parent node via given nesting level |
| 121 | 135 | $node = $scope[count($scope) - 2 - $level] ?? $this->ctx->getFirstNode(); |
| 122 | 136 | } |
| 123 | 137 | |
| 124 | - if (!$node instanceof AttributedInterface) { |
|
| 138 | + if (!$node instanceof AttributedInterface) |
|
| 139 | + { |
|
| 125 | 140 | throw new LogicException( |
| 126 | 141 | sprintf( |
| 127 | 142 | 'Unable to create import on node without attribute storage (%s)', |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function getIterator(): Traversable |
| 47 | 47 | { |
| 48 | - while ($n = $this->next()) { |
|
| 48 | + while ($n = $this->next()){ |
|
| 49 | 49 | yield $n; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -60,18 +60,18 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function next() |
| 62 | 62 | { |
| 63 | - if ($this->replay !== []) { |
|
| 63 | + if ($this->replay !== []){ |
|
| 64 | 64 | $n = array_shift($this->replay); |
| 65 | - } else { |
|
| 65 | + }else{ |
|
| 66 | 66 | $n = $this->generator->current(); |
| 67 | - if ($n === null) { |
|
| 67 | + if ($n === null){ |
|
| 68 | 68 | return null; |
| 69 | 69 | } |
| 70 | 70 | $this->generator->next(); |
| 71 | 71 | $this->buffer[] = $n; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($n !== null) { |
|
| 74 | + if ($n !== null){ |
|
| 75 | 75 | $this->offset = $n->offset; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | public function nextBytes(): string |
| 85 | 85 | { |
| 86 | 86 | $result = ''; |
| 87 | - while ($n = $this->next()) { |
|
| 88 | - if ($n instanceof Byte) { |
|
| 87 | + while ($n = $this->next()){ |
|
| 88 | + if ($n instanceof Byte){ |
|
| 89 | 89 | $result .= $n->char; |
| 90 | - } else { |
|
| 90 | + }else{ |
|
| 91 | 91 | break; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -100,12 +100,12 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function lookahead() |
| 102 | 102 | { |
| 103 | - if ($this->replay !== []) { |
|
| 103 | + if ($this->replay !== []){ |
|
| 104 | 104 | return $this->replay[0]; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $n = $this->next(); |
| 108 | - if ($n !== null) { |
|
| 108 | + if ($n !== null){ |
|
| 109 | 109 | array_unshift($this->replay, $n); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -121,20 +121,20 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | $result = ''; |
| 123 | 123 | $replay = []; |
| 124 | - for ($i = 0; $i < $size; $i++) { |
|
| 124 | + for ($i = 0; $i < $size; $i++){ |
|
| 125 | 125 | $n = $this->next(); |
| 126 | - if ($n !== null) { |
|
| 126 | + if ($n !== null){ |
|
| 127 | 127 | $replay[] = $n; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if (!$n instanceof Byte) { |
|
| 130 | + if (!$n instanceof Byte){ |
|
| 131 | 131 | break; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | $result .= $n->char; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - foreach (array_reverse($replay) as $n) { |
|
| 137 | + foreach (array_reverse($replay) as $n){ |
|
| 138 | 138 | array_unshift($this->replay, $n); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function replay(int $offset): void |
| 148 | 148 | { |
| 149 | - foreach ($this->buffer as $n) { |
|
| 150 | - if ($n->offset > $offset) { |
|
| 149 | + foreach ($this->buffer as $n){ |
|
| 150 | + if ($n->offset > $offset){ |
|
| 151 | 151 | $this->replay[] = $n; |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -45,7 +45,8 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function getIterator(): Traversable |
| 47 | 47 | { |
| 48 | - while ($n = $this->next()) { |
|
| 48 | + while ($n = $this->next()) |
|
| 49 | + { |
|
| 49 | 50 | yield $n; |
| 50 | 51 | } |
| 51 | 52 | } |
@@ -60,18 +61,23 @@ discard block |
||
| 60 | 61 | */ |
| 61 | 62 | public function next() |
| 62 | 63 | { |
| 63 | - if ($this->replay !== []) { |
|
| 64 | + if ($this->replay !== []) |
|
| 65 | + { |
|
| 64 | 66 | $n = array_shift($this->replay); |
| 65 | - } else { |
|
| 67 | + } |
|
| 68 | + else |
|
| 69 | + { |
|
| 66 | 70 | $n = $this->generator->current(); |
| 67 | - if ($n === null) { |
|
| 71 | + if ($n === null) |
|
| 72 | + { |
|
| 68 | 73 | return null; |
| 69 | 74 | } |
| 70 | 75 | $this->generator->next(); |
| 71 | 76 | $this->buffer[] = $n; |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | - if ($n !== null) { |
|
| 79 | + if ($n !== null) |
|
| 80 | + { |
|
| 75 | 81 | $this->offset = $n->offset; |
| 76 | 82 | } |
| 77 | 83 | |
@@ -84,10 +90,14 @@ discard block |
||
| 84 | 90 | public function nextBytes(): string |
| 85 | 91 | { |
| 86 | 92 | $result = ''; |
| 87 | - while ($n = $this->next()) { |
|
| 88 | - if ($n instanceof Byte) { |
|
| 93 | + while ($n = $this->next()) |
|
| 94 | + { |
|
| 95 | + if ($n instanceof Byte) |
|
| 96 | + { |
|
| 89 | 97 | $result .= $n->char; |
| 90 | - } else { |
|
| 98 | + } |
|
| 99 | + else |
|
| 100 | + { |
|
| 91 | 101 | break; |
| 92 | 102 | } |
| 93 | 103 | } |
@@ -100,12 +110,14 @@ discard block |
||
| 100 | 110 | */ |
| 101 | 111 | public function lookahead() |
| 102 | 112 | { |
| 103 | - if ($this->replay !== []) { |
|
| 113 | + if ($this->replay !== []) |
|
| 114 | + { |
|
| 104 | 115 | return $this->replay[0]; |
| 105 | 116 | } |
| 106 | 117 | |
| 107 | 118 | $n = $this->next(); |
| 108 | - if ($n !== null) { |
|
| 119 | + if ($n !== null) |
|
| 120 | + { |
|
| 109 | 121 | array_unshift($this->replay, $n); |
| 110 | 122 | } |
| 111 | 123 | |
@@ -121,20 +133,24 @@ discard block |
||
| 121 | 133 | { |
| 122 | 134 | $result = ''; |
| 123 | 135 | $replay = []; |
| 124 | - for ($i = 0; $i < $size; $i++) { |
|
| 136 | + for ($i = 0; $i < $size; $i++) |
|
| 137 | + { |
|
| 125 | 138 | $n = $this->next(); |
| 126 | - if ($n !== null) { |
|
| 139 | + if ($n !== null) |
|
| 140 | + { |
|
| 127 | 141 | $replay[] = $n; |
| 128 | 142 | } |
| 129 | 143 | |
| 130 | - if (!$n instanceof Byte) { |
|
| 144 | + if (!$n instanceof Byte) |
|
| 145 | + { |
|
| 131 | 146 | break; |
| 132 | 147 | } |
| 133 | 148 | |
| 134 | 149 | $result .= $n->char; |
| 135 | 150 | } |
| 136 | 151 | |
| 137 | - foreach (array_reverse($replay) as $n) { |
|
| 152 | + foreach (array_reverse($replay) as $n) |
|
| 153 | + { |
|
| 138 | 154 | array_unshift($this->replay, $n); |
| 139 | 155 | } |
| 140 | 156 | |
@@ -146,8 +162,10 @@ discard block |
||
| 146 | 162 | */ |
| 147 | 163 | public function replay(int $offset): void |
| 148 | 164 | { |
| 149 | - foreach ($this->buffer as $n) { |
|
| 150 | - if ($n->offset > $offset) { |
|
| 165 | + foreach ($this->buffer as $n) |
|
| 166 | + { |
|
| 167 | + if ($n->offset > $offset) |
|
| 168 | + { |
|
| 151 | 169 | $this->replay[] = $n; |
| 152 | 170 | } |
| 153 | 171 | } |
@@ -39,20 +39,20 @@ discard block |
||
| 39 | 39 | public function parse(StreamInterface $src): Generator |
| 40 | 40 | { |
| 41 | 41 | $stream = new Buffer($this->generate($src)); |
| 42 | - foreach ($this->grammars as $grammar) { |
|
| 42 | + foreach ($this->grammars as $grammar){ |
|
| 43 | 43 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // always group raw bytes into raw tokens |
| 47 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
| 47 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n){ |
|
| 48 | 48 | yield $n; |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | private function wrap(GrammarInterface $grammar, Buffer $stream): Generator |
| 53 | 53 | { |
| 54 | - foreach ($grammar->parse($stream) as $n) { |
|
| 55 | - if ($n instanceof Token && $n->grammar === null) { |
|
| 54 | + foreach ($grammar->parse($stream) as $n){ |
|
| 55 | + if ($n instanceof Token && $n->grammar === null){ |
|
| 56 | 56 | $n->grammar = get_class($grammar); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | private function generate(StreamInterface $src) |
| 69 | 69 | { |
| 70 | - while (!$src->isEOI()) { |
|
| 70 | + while (!$src->isEOI()){ |
|
| 71 | 71 | yield new Byte($src->getOffset(), $src->peak()); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -39,20 +39,24 @@ discard block |
||
| 39 | 39 | public function parse(StreamInterface $src): Generator |
| 40 | 40 | { |
| 41 | 41 | $stream = new Buffer($this->generate($src)); |
| 42 | - foreach ($this->grammars as $grammar) { |
|
| 42 | + foreach ($this->grammars as $grammar) |
|
| 43 | + { |
|
| 43 | 44 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | // always group raw bytes into raw tokens |
| 47 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
| 48 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n) |
|
| 49 | + { |
|
| 48 | 50 | yield $n; |
| 49 | 51 | } |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | private function wrap(GrammarInterface $grammar, Buffer $stream): Generator |
| 53 | 55 | { |
| 54 | - foreach ($grammar->parse($stream) as $n) { |
|
| 55 | - if ($n instanceof Token && $n->grammar === null) { |
|
| 56 | + foreach ($grammar->parse($stream) as $n) |
|
| 57 | + { |
|
| 58 | + if ($n instanceof Token && $n->grammar === null) |
|
| 59 | + { |
|
| 56 | 60 | $n->grammar = get_class($grammar); |
| 57 | 61 | } |
| 58 | 62 | |
@@ -67,7 +71,8 @@ discard block |
||
| 67 | 71 | */ |
| 68 | 72 | private function generate(StreamInterface $src) |
| 69 | 73 | { |
| 70 | - while (!$src->isEOI()) { |
|
| 74 | + while (!$src->isEOI()) |
|
| 75 | + { |
|
| 71 | 76 | yield new Byte($src->getOffset(), $src->peak()); |
| 72 | 77 | } |
| 73 | 78 | } |
@@ -41,19 +41,19 @@ discard block |
||
| 41 | 41 | public function parse(Buffer $src): Generator |
| 42 | 42 | { |
| 43 | 43 | $quoted = []; |
| 44 | - while ($n = $src->next()) { |
|
| 45 | - switch ($n->char) { |
|
| 44 | + while ($n = $src->next()){ |
|
| 45 | + switch ($n->char){ |
|
| 46 | 46 | case '"': |
| 47 | 47 | case "'": |
| 48 | - if ($this->keyword !== []) { |
|
| 48 | + if ($this->keyword !== []){ |
|
| 49 | 49 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 50 | 50 | $this->keyword = []; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $quoted[] = $n; |
| 54 | - while ($nn = $src->next()) { |
|
| 54 | + while ($nn = $src->next()){ |
|
| 55 | 55 | $quoted[] = $nn; |
| 56 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 56 | + if ($nn instanceof Byte && $nn->char === $n->char){ |
|
| 57 | 57 | break; |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | break; |
| 65 | 65 | case '=': |
| 66 | - if ($this->keyword !== []) { |
|
| 66 | + if ($this->keyword !== []){ |
|
| 67 | 67 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 68 | 68 | $this->keyword = []; |
| 69 | 69 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | yield new Token(self::TYPE_EQUAL, $n->offset, '='); |
| 72 | 72 | break; |
| 73 | 73 | case ',': |
| 74 | - if ($this->keyword !== []) { |
|
| 74 | + if ($this->keyword !== []){ |
|
| 75 | 75 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 76 | 76 | $this->keyword = []; |
| 77 | 77 | } |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | yield new Token(self::TYPE_COMMA, $n->offset, ','); |
| 80 | 80 | break; |
| 81 | 81 | default: |
| 82 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 83 | - if ($this->keyword !== []) { |
|
| 82 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
| 83 | + if ($this->keyword !== []){ |
|
| 84 | 84 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 85 | 85 | $this->keyword = []; |
| 86 | 86 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ($this->keyword !== []) { |
|
| 95 | + if ($this->keyword !== []){ |
|
| 96 | 96 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public static function tokenName(int $token): string |
| 104 | 104 | { |
| 105 | - switch ($token) { |
|
| 105 | + switch ($token){ |
|
| 106 | 106 | case self::TYPE_KEYWORD: |
| 107 | 107 | return 'DECLARE:KEYWORD'; |
| 108 | 108 | case self::TYPE_EQUAL: |
@@ -41,19 +41,24 @@ discard block |
||
| 41 | 41 | public function parse(Buffer $src): Generator |
| 42 | 42 | { |
| 43 | 43 | $quoted = []; |
| 44 | - while ($n = $src->next()) { |
|
| 45 | - switch ($n->char) { |
|
| 44 | + while ($n = $src->next()) |
|
| 45 | + { |
|
| 46 | + switch ($n->char) |
|
| 47 | + { |
|
| 46 | 48 | case '"': |
| 47 | 49 | case "'": |
| 48 | - if ($this->keyword !== []) { |
|
| 50 | + if ($this->keyword !== []) |
|
| 51 | + { |
|
| 49 | 52 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 50 | 53 | $this->keyword = []; |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | $quoted[] = $n; |
| 54 | - while ($nn = $src->next()) { |
|
| 57 | + while ($nn = $src->next()) |
|
| 58 | + { |
|
| 55 | 59 | $quoted[] = $nn; |
| 56 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
| 60 | + if ($nn instanceof Byte && $nn->char === $n->char) |
|
| 61 | + { |
|
| 57 | 62 | break; |
| 58 | 63 | } |
| 59 | 64 | } |
@@ -63,7 +68,8 @@ discard block |
||
| 63 | 68 | |
| 64 | 69 | break; |
| 65 | 70 | case '=': |
| 66 | - if ($this->keyword !== []) { |
|
| 71 | + if ($this->keyword !== []) |
|
| 72 | + { |
|
| 67 | 73 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 68 | 74 | $this->keyword = []; |
| 69 | 75 | } |
@@ -71,7 +77,8 @@ discard block |
||
| 71 | 77 | yield new Token(self::TYPE_EQUAL, $n->offset, '='); |
| 72 | 78 | break; |
| 73 | 79 | case ',': |
| 74 | - if ($this->keyword !== []) { |
|
| 80 | + if ($this->keyword !== []) |
|
| 81 | + { |
|
| 75 | 82 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 76 | 83 | $this->keyword = []; |
| 77 | 84 | } |
@@ -79,8 +86,10 @@ discard block |
||
| 79 | 86 | yield new Token(self::TYPE_COMMA, $n->offset, ','); |
| 80 | 87 | break; |
| 81 | 88 | default: |
| 82 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 83 | - if ($this->keyword !== []) { |
|
| 89 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
| 90 | + { |
|
| 91 | + if ($this->keyword !== []) |
|
| 92 | + { |
|
| 84 | 93 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 85 | 94 | $this->keyword = []; |
| 86 | 95 | } |
@@ -92,7 +101,8 @@ discard block |
||
| 92 | 101 | } |
| 93 | 102 | } |
| 94 | 103 | |
| 95 | - if ($this->keyword !== []) { |
|
| 104 | + if ($this->keyword !== []) |
|
| 105 | + { |
|
| 96 | 106 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
| 97 | 107 | } |
| 98 | 108 | } |
@@ -102,7 +112,8 @@ discard block |
||
| 102 | 112 | */ |
| 103 | 113 | public static function tokenName(int $token): string |
| 104 | 114 | { |
| 105 | - switch ($token) { |
|
| 115 | + switch ($token) |
|
| 116 | + { |
|
| 106 | 117 | case self::TYPE_KEYWORD: |
| 107 | 118 | return 'DECLARE:KEYWORD'; |
| 108 | 119 | case self::TYPE_EQUAL: |
@@ -51,39 +51,39 @@ discard block |
||
| 51 | 51 | $this->body = null; |
| 52 | 52 | $hasWhitespace = false; |
| 53 | 53 | |
| 54 | - while ($n = $src->next()) { |
|
| 55 | - if (!$n instanceof Byte) { |
|
| 54 | + while ($n = $src->next()){ |
|
| 55 | + if (!$n instanceof Byte){ |
|
| 56 | 56 | // no other grammars are allowed |
| 57 | 57 | break; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - switch ($n->char) { |
|
| 60 | + switch ($n->char){ |
|
| 61 | 61 | case '(': |
| 62 | 62 | $this->flushName(); |
| 63 | 63 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
| 64 | 64 | |
| 65 | 65 | return $this->parseBody($src); |
| 66 | 66 | default: |
| 67 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 67 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
| 68 | 68 | $hasWhitespace = true; |
| 69 | - if ($this->name !== []) { |
|
| 69 | + if ($this->name !== []){ |
|
| 70 | 70 | $this->flushName(); |
| 71 | 71 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
| 72 | 72 | break; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
| 75 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE){ |
|
| 76 | 76 | $this->getLastToken()->content .= $n->char; |
| 77 | 77 | break; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // invalid directive |
| 81 | 81 | return false; |
| 82 | - } elseif ($hasWhitespace) { |
|
| 82 | + } elseif ($hasWhitespace){ |
|
| 83 | 83 | return $this->finalize(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 86 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
| 87 | 87 | $this->flushName(); |
| 88 | 88 | |
| 89 | 89 | return $this->finalize(); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getIterator(): Traversable |
| 105 | 105 | { |
| 106 | - if ($this->tokens === []) { |
|
| 106 | + if ($this->tokens === []){ |
|
| 107 | 107 | throw new LogicException('Directive not parsed'); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function getKeyword(): string |
| 125 | 125 | { |
| 126 | - foreach ($this->tokens as $token) { |
|
| 127 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
| 126 | + foreach ($this->tokens as $token){ |
|
| 127 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD){ |
|
| 128 | 128 | return $token->content; |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function getBody(): ?string |
| 141 | 141 | { |
| 142 | - foreach ($this->tokens as $token) { |
|
| 143 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
| 142 | + foreach ($this->tokens as $token){ |
|
| 143 | + if ($token->type === DynamicGrammar::TYPE_BODY){ |
|
| 144 | 144 | return $token->content; |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | private function flushName(): void |
| 155 | 155 | { |
| 156 | - if ($this->name === []) { |
|
| 156 | + if ($this->name === []){ |
|
| 157 | 157 | return; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -169,17 +169,17 @@ discard block |
||
| 169 | 169 | $this->body = []; |
| 170 | 170 | $level = 1; |
| 171 | 171 | |
| 172 | - while ($nn = $src->next()) { |
|
| 173 | - if (!$nn instanceof Byte) { |
|
| 172 | + while ($nn = $src->next()){ |
|
| 173 | + if (!$nn instanceof Byte){ |
|
| 174 | 174 | $this->flushBody(); |
| 175 | 175 | return $this->finalize(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if (in_array($nn->char, ['"', '"'])) { |
|
| 178 | + if (in_array($nn->char, ['"', '"'])){ |
|
| 179 | 179 | $this->body[] = $nn; |
| 180 | - while ($nnn = $src->next()) { |
|
| 180 | + while ($nnn = $src->next()){ |
|
| 181 | 181 | $this->body[] = $nnn; |
| 182 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
| 182 | + if ($nnn instanceof Byte && $nnn->char === $nn->char){ |
|
| 183 | 183 | break; |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | $this->body[] = $nn; |
| 190 | 190 | |
| 191 | - if ($nn->char === '(') { |
|
| 191 | + if ($nn->char === '('){ |
|
| 192 | 192 | $level++; |
| 193 | 193 | continue; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if ($nn->char === ')') { |
|
| 196 | + if ($nn->char === ')'){ |
|
| 197 | 197 | $level--; |
| 198 | 198 | |
| 199 | - if ($level === 0) { |
|
| 199 | + if ($level === 0){ |
|
| 200 | 200 | $n = array_pop($this->body); |
| 201 | 201 | |
| 202 | 202 | $this->flushBody(); |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | private function flushBody(): void |
| 219 | 219 | { |
| 220 | - if ($this->body === []) { |
|
| 220 | + if ($this->body === []){ |
|
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | 223 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | private function getLastToken(): Token |
| 229 | 229 | { |
| 230 | - if ($this->tokens === []) { |
|
| 230 | + if ($this->tokens === []){ |
|
| 231 | 231 | throw new LogicException('Directive not parsed'); |
| 232 | 232 | } |
| 233 | 233 | |
@@ -241,8 +241,8 @@ discard block |
||
| 241 | 241 | { |
| 242 | 242 | $tokens = $this->tokens; |
| 243 | 243 | |
| 244 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
| 245 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
| 244 | + foreach (array_reverse($tokens, true) as $i => $t){ |
|
| 245 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE){ |
|
| 246 | 246 | break; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $body = null; |
| 253 | - foreach ($tokens as $t) { |
|
| 254 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
| 253 | + foreach ($tokens as $t){ |
|
| 254 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN){ |
|
| 255 | 255 | $body = false; |
| 256 | 256 | continue; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
| 259 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE){ |
|
| 260 | 260 | $body = null; |
| 261 | 261 | continue; |
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ($body !== null) { |
|
| 265 | + if ($body !== null){ |
|
| 266 | 266 | return false; |
| 267 | 267 | } |
| 268 | 268 | |
@@ -51,39 +51,48 @@ discard block |
||
| 51 | 51 | $this->body = null; |
| 52 | 52 | $hasWhitespace = false; |
| 53 | 53 | |
| 54 | - while ($n = $src->next()) { |
|
| 55 | - if (!$n instanceof Byte) { |
|
| 54 | + while ($n = $src->next()) |
|
| 55 | + { |
|
| 56 | + if (!$n instanceof Byte) |
|
| 57 | + { |
|
| 56 | 58 | // no other grammars are allowed |
| 57 | 59 | break; |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | - switch ($n->char) { |
|
| 62 | + switch ($n->char) |
|
| 63 | + { |
|
| 61 | 64 | case '(': |
| 62 | 65 | $this->flushName(); |
| 63 | 66 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
| 64 | 67 | |
| 65 | 68 | return $this->parseBody($src); |
| 66 | 69 | default: |
| 67 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
| 70 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
| 71 | + { |
|
| 68 | 72 | $hasWhitespace = true; |
| 69 | - if ($this->name !== []) { |
|
| 73 | + if ($this->name !== []) |
|
| 74 | + { |
|
| 70 | 75 | $this->flushName(); |
| 71 | 76 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
| 72 | 77 | break; |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
| 80 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) |
|
| 81 | + { |
|
| 76 | 82 | $this->getLastToken()->content .= $n->char; |
| 77 | 83 | break; |
| 78 | 84 | } |
| 79 | 85 | |
| 80 | 86 | // invalid directive |
| 81 | 87 | return false; |
| 82 | - } elseif ($hasWhitespace) { |
|
| 88 | + } |
|
| 89 | + elseif ($hasWhitespace) |
|
| 90 | + { |
|
| 83 | 91 | return $this->finalize(); |
| 84 | 92 | } |
| 85 | 93 | |
| 86 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
| 94 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
| 95 | + { |
|
| 87 | 96 | $this->flushName(); |
| 88 | 97 | |
| 89 | 98 | return $this->finalize(); |
@@ -103,7 +112,8 @@ discard block |
||
| 103 | 112 | */ |
| 104 | 113 | public function getIterator(): Traversable |
| 105 | 114 | { |
| 106 | - if ($this->tokens === []) { |
|
| 115 | + if ($this->tokens === []) |
|
| 116 | + { |
|
| 107 | 117 | throw new LogicException('Directive not parsed'); |
| 108 | 118 | } |
| 109 | 119 | |
@@ -123,8 +133,10 @@ discard block |
||
| 123 | 133 | */ |
| 124 | 134 | public function getKeyword(): string |
| 125 | 135 | { |
| 126 | - foreach ($this->tokens as $token) { |
|
| 127 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
| 136 | + foreach ($this->tokens as $token) |
|
| 137 | + { |
|
| 138 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD) |
|
| 139 | + { |
|
| 128 | 140 | return $token->content; |
| 129 | 141 | } |
| 130 | 142 | } |
@@ -139,8 +151,10 @@ discard block |
||
| 139 | 151 | */ |
| 140 | 152 | public function getBody(): ?string |
| 141 | 153 | { |
| 142 | - foreach ($this->tokens as $token) { |
|
| 143 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
| 154 | + foreach ($this->tokens as $token) |
|
| 155 | + { |
|
| 156 | + if ($token->type === DynamicGrammar::TYPE_BODY) |
|
| 157 | + { |
|
| 144 | 158 | return $token->content; |
| 145 | 159 | } |
| 146 | 160 | } |
@@ -153,7 +167,8 @@ discard block |
||
| 153 | 167 | */ |
| 154 | 168 | private function flushName(): void |
| 155 | 169 | { |
| 156 | - if ($this->name === []) { |
|
| 170 | + if ($this->name === []) |
|
| 171 | + { |
|
| 157 | 172 | return; |
| 158 | 173 | } |
| 159 | 174 | |
@@ -169,17 +184,22 @@ discard block |
||
| 169 | 184 | $this->body = []; |
| 170 | 185 | $level = 1; |
| 171 | 186 | |
| 172 | - while ($nn = $src->next()) { |
|
| 173 | - if (!$nn instanceof Byte) { |
|
| 187 | + while ($nn = $src->next()) |
|
| 188 | + { |
|
| 189 | + if (!$nn instanceof Byte) |
|
| 190 | + { |
|
| 174 | 191 | $this->flushBody(); |
| 175 | 192 | return $this->finalize(); |
| 176 | 193 | } |
| 177 | 194 | |
| 178 | - if (in_array($nn->char, ['"', '"'])) { |
|
| 195 | + if (in_array($nn->char, ['"', '"'])) |
|
| 196 | + { |
|
| 179 | 197 | $this->body[] = $nn; |
| 180 | - while ($nnn = $src->next()) { |
|
| 198 | + while ($nnn = $src->next()) |
|
| 199 | + { |
|
| 181 | 200 | $this->body[] = $nnn; |
| 182 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
| 201 | + if ($nnn instanceof Byte && $nnn->char === $nn->char) |
|
| 202 | + { |
|
| 183 | 203 | break; |
| 184 | 204 | } |
| 185 | 205 | } |
@@ -188,15 +208,18 @@ discard block |
||
| 188 | 208 | |
| 189 | 209 | $this->body[] = $nn; |
| 190 | 210 | |
| 191 | - if ($nn->char === '(') { |
|
| 211 | + if ($nn->char === '(') |
|
| 212 | + { |
|
| 192 | 213 | $level++; |
| 193 | 214 | continue; |
| 194 | 215 | } |
| 195 | 216 | |
| 196 | - if ($nn->char === ')') { |
|
| 217 | + if ($nn->char === ')') |
|
| 218 | + { |
|
| 197 | 219 | $level--; |
| 198 | 220 | |
| 199 | - if ($level === 0) { |
|
| 221 | + if ($level === 0) |
|
| 222 | + { |
|
| 200 | 223 | $n = array_pop($this->body); |
| 201 | 224 | |
| 202 | 225 | $this->flushBody(); |
@@ -217,7 +240,8 @@ discard block |
||
| 217 | 240 | */ |
| 218 | 241 | private function flushBody(): void |
| 219 | 242 | { |
| 220 | - if ($this->body === []) { |
|
| 243 | + if ($this->body === []) |
|
| 244 | + { |
|
| 221 | 245 | return; |
| 222 | 246 | } |
| 223 | 247 | |
@@ -227,7 +251,8 @@ discard block |
||
| 227 | 251 | |
| 228 | 252 | private function getLastToken(): Token |
| 229 | 253 | { |
| 230 | - if ($this->tokens === []) { |
|
| 254 | + if ($this->tokens === []) |
|
| 255 | + { |
|
| 231 | 256 | throw new LogicException('Directive not parsed'); |
| 232 | 257 | } |
| 233 | 258 | |
@@ -241,8 +266,10 @@ discard block |
||
| 241 | 266 | { |
| 242 | 267 | $tokens = $this->tokens; |
| 243 | 268 | |
| 244 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
| 245 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
| 269 | + foreach (array_reverse($tokens, true) as $i => $t) |
|
| 270 | + { |
|
| 271 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) |
|
| 272 | + { |
|
| 246 | 273 | break; |
| 247 | 274 | } |
| 248 | 275 | |
@@ -250,19 +277,23 @@ discard block |
||
| 250 | 277 | } |
| 251 | 278 | |
| 252 | 279 | $body = null; |
| 253 | - foreach ($tokens as $t) { |
|
| 254 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
| 280 | + foreach ($tokens as $t) |
|
| 281 | + { |
|
| 282 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) |
|
| 283 | + { |
|
| 255 | 284 | $body = false; |
| 256 | 285 | continue; |
| 257 | 286 | } |
| 258 | 287 | |
| 259 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
| 288 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) |
|
| 289 | + { |
|
| 260 | 290 | $body = null; |
| 261 | 291 | continue; |
| 262 | 292 | } |
| 263 | 293 | } |
| 264 | 294 | |
| 265 | - if ($body !== null) { |
|
| 295 | + if ($body !== null) |
|
| 296 | + { |
|
| 266 | 297 | return false; |
| 267 | 298 | } |
| 268 | 299 | |
@@ -82,33 +82,33 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function parse(Buffer $src): Generator |
| 84 | 84 | { |
| 85 | - while ($n = $src->next()) { |
|
| 86 | - if (!$n instanceof Byte) { |
|
| 85 | + while ($n = $src->next()){ |
|
| 86 | + if (!$n instanceof Byte){ |
|
| 87 | 87 | yield $n; |
| 88 | 88 | continue; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 91 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
| 92 | 92 | if ( |
| 93 | 93 | $this->echo->nextToken($src) || |
| 94 | 94 | $this->raw->nextToken($src) || |
| 95 | 95 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
| 96 | - ) { |
|
| 96 | + ){ |
|
| 97 | 97 | // escaped echo sequence, hide directive byte |
| 98 | 98 | yield $src->next(); |
| 99 | 99 | continue; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $directive = new DirectiveGrammar(); |
| 103 | - if ($directive->parse($src, $n->offset)) { |
|
| 104 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 103 | + if ($directive->parse($src, $n->offset)){ |
|
| 104 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
| 105 | 105 | // configure braces syntax |
| 106 | 106 | $this->declare($directive->getBody()); |
| 107 | - } else { |
|
| 107 | + }else{ |
|
| 108 | 108 | if ( |
| 109 | 109 | $this->directiveRenderer !== null |
| 110 | 110 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
| 111 | - ) { |
|
| 111 | + ){ |
|
| 112 | 112 | // directive opening char |
| 113 | 113 | yield $n; |
| 114 | 114 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | /** @var BracesGrammar|null $braces */ |
| 131 | 131 | $braces = null; |
| 132 | - if ($this->echo->starts($src, $n)) { |
|
| 132 | + if ($this->echo->starts($src, $n)){ |
|
| 133 | 133 | $braces = clone $this->echo; |
| 134 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 134 | + } elseif ($this->raw->starts($src, $n)){ |
|
| 135 | 135 | $braces = clone $this->raw; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if ($braces !== null) { |
|
| 138 | + if ($braces !== null){ |
|
| 139 | 139 | $echo = $braces->parse($src, $n); |
| 140 | - if ($echo !== null) { |
|
| 140 | + if ($echo !== null){ |
|
| 141 | 141 | yield from $echo; |
| 142 | 142 | continue; |
| 143 | 143 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public static function tokenName(int $token): string |
| 159 | 159 | { |
| 160 | - switch ($token) { |
|
| 160 | + switch ($token){ |
|
| 161 | 161 | case self::TYPE_OPEN_TAG: |
| 162 | 162 | return 'DYNAMIC:OPEN_TAG'; |
| 163 | 163 | case self::TYPE_CLOSE_TAG: |
@@ -182,20 +182,20 @@ discard block |
||
| 182 | 182 | /** |
| 183 | 183 | * @param string $body |
| 184 | 184 | */ |
| 185 | - private function declare(?string $body): void |
|
| 185 | + private function declare(?string$body) : void |
|
| 186 | 186 | { |
| 187 | - if ($body === null) { |
|
| 187 | + if ($body === null){ |
|
| 188 | 188 | return; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 191 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
| 192 | 192 | $value = trim($value, '\'" '); |
| 193 | - switch ($option) { |
|
| 193 | + switch ($option){ |
|
| 194 | 194 | case 'syntax': |
| 195 | 195 | $this->echo->setActive($value !== 'off'); |
| 196 | 196 | $this->raw->setActive($value !== 'off'); |
| 197 | 197 | |
| 198 | - if ($value === 'default') { |
|
| 198 | + if ($value === 'default'){ |
|
| 199 | 199 | $this->echo->setStartSequence('{{'); |
| 200 | 200 | $this->echo->setEndSequence('}}'); |
| 201 | 201 | $this->raw->setStartSequence('{!!'); |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | $keyword = null; |
| 233 | 233 | |
| 234 | 234 | /** @var Token $token */ |
| 235 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 236 | - switch ($token->type) { |
|
| 235 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
| 236 | + switch ($token->type){ |
|
| 237 | 237 | case DeclareGrammar::TYPE_KEYWORD: |
| 238 | - if ($keyword !== null) { |
|
| 238 | + if ($keyword !== null){ |
|
| 239 | 239 | $options[$keyword] = $token->content; |
| 240 | 240 | $keyword = null; |
| 241 | 241 | break; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $keyword = $token->content; |
| 244 | 244 | break; |
| 245 | 245 | case DeclareGrammar::TYPE_QUOTED: |
| 246 | - if ($keyword !== null) { |
|
| 246 | + if ($keyword !== null){ |
|
| 247 | 247 | $options[$keyword] = trim($token->content, $token->content[0]); |
| 248 | 248 | $keyword = null; |
| 249 | 249 | break; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $keyword = trim($token->content, $token->content[0]); |
| 253 | 253 | break; |
| 254 | 254 | case DeclareGrammar::TYPE_COMMA: |
| 255 | - if ($keyword !== null) { |
|
| 255 | + if ($keyword !== null){ |
|
| 256 | 256 | $options[$keyword] = null; |
| 257 | 257 | $keyword = null; |
| 258 | 258 | break; |
@@ -82,13 +82,16 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function parse(Buffer $src): Generator |
| 84 | 84 | { |
| 85 | - while ($n = $src->next()) { |
|
| 86 | - if (!$n instanceof Byte) { |
|
| 85 | + while ($n = $src->next()) |
|
| 86 | + { |
|
| 87 | + if (!$n instanceof Byte) |
|
| 88 | + { |
|
| 87 | 89 | yield $n; |
| 88 | 90 | continue; |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
| 93 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
| 94 | + { |
|
| 92 | 95 | if ( |
| 93 | 96 | $this->echo->nextToken($src) || |
| 94 | 97 | $this->raw->nextToken($src) || |
@@ -100,11 +103,15 @@ discard block |
||
| 100 | 103 | } |
| 101 | 104 | |
| 102 | 105 | $directive = new DirectiveGrammar(); |
| 103 | - if ($directive->parse($src, $n->offset)) { |
|
| 104 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
| 106 | + if ($directive->parse($src, $n->offset)) |
|
| 107 | + { |
|
| 108 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
| 109 | + { |
|
| 105 | 110 | // configure braces syntax |
| 106 | 111 | $this->declare($directive->getBody()); |
| 107 | - } else { |
|
| 112 | + } |
|
| 113 | + else |
|
| 114 | + { |
|
| 108 | 115 | if ( |
| 109 | 116 | $this->directiveRenderer !== null |
| 110 | 117 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -129,15 +136,20 @@ discard block |
||
| 129 | 136 | |
| 130 | 137 | /** @var BracesGrammar|null $braces */ |
| 131 | 138 | $braces = null; |
| 132 | - if ($this->echo->starts($src, $n)) { |
|
| 139 | + if ($this->echo->starts($src, $n)) |
|
| 140 | + { |
|
| 133 | 141 | $braces = clone $this->echo; |
| 134 | - } elseif ($this->raw->starts($src, $n)) { |
|
| 142 | + } |
|
| 143 | + elseif ($this->raw->starts($src, $n)) |
|
| 144 | + { |
|
| 135 | 145 | $braces = clone $this->raw; |
| 136 | 146 | } |
| 137 | 147 | |
| 138 | - if ($braces !== null) { |
|
| 148 | + if ($braces !== null) |
|
| 149 | + { |
|
| 139 | 150 | $echo = $braces->parse($src, $n); |
| 140 | - if ($echo !== null) { |
|
| 151 | + if ($echo !== null) |
|
| 152 | + { |
|
| 141 | 153 | yield from $echo; |
| 142 | 154 | continue; |
| 143 | 155 | } |
@@ -157,7 +169,8 @@ discard block |
||
| 157 | 169 | */ |
| 158 | 170 | public static function tokenName(int $token): string |
| 159 | 171 | { |
| 160 | - switch ($token) { |
|
| 172 | + switch ($token) |
|
| 173 | + { |
|
| 161 | 174 | case self::TYPE_OPEN_TAG: |
| 162 | 175 | return 'DYNAMIC:OPEN_TAG'; |
| 163 | 176 | case self::TYPE_CLOSE_TAG: |
@@ -184,18 +197,22 @@ discard block |
||
| 184 | 197 | */ |
| 185 | 198 | private function declare(?string $body): void |
| 186 | 199 | { |
| 187 | - if ($body === null) { |
|
| 200 | + if ($body === null) |
|
| 201 | + { |
|
| 188 | 202 | return; |
| 189 | 203 | } |
| 190 | 204 | |
| 191 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
| 205 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
| 206 | + { |
|
| 192 | 207 | $value = trim($value, '\'" '); |
| 193 | - switch ($option) { |
|
| 208 | + switch ($option) |
|
| 209 | + { |
|
| 194 | 210 | case 'syntax': |
| 195 | 211 | $this->echo->setActive($value !== 'off'); |
| 196 | 212 | $this->raw->setActive($value !== 'off'); |
| 197 | 213 | |
| 198 | - if ($value === 'default') { |
|
| 214 | + if ($value === 'default') |
|
| 215 | + { |
|
| 199 | 216 | $this->echo->setStartSequence('{{'); |
| 200 | 217 | $this->echo->setEndSequence('}}'); |
| 201 | 218 | $this->raw->setStartSequence('{!!'); |
@@ -232,10 +249,13 @@ discard block |
||
| 232 | 249 | $keyword = null; |
| 233 | 250 | |
| 234 | 251 | /** @var Token $token */ |
| 235 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
| 236 | - switch ($token->type) { |
|
| 252 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
| 253 | + { |
|
| 254 | + switch ($token->type) |
|
| 255 | + { |
|
| 237 | 256 | case DeclareGrammar::TYPE_KEYWORD: |
| 238 | - if ($keyword !== null) { |
|
| 257 | + if ($keyword !== null) |
|
| 258 | + { |
|
| 239 | 259 | $options[$keyword] = $token->content; |
| 240 | 260 | $keyword = null; |
| 241 | 261 | break; |
@@ -243,7 +263,8 @@ discard block |
||
| 243 | 263 | $keyword = $token->content; |
| 244 | 264 | break; |
| 245 | 265 | case DeclareGrammar::TYPE_QUOTED: |
| 246 | - if ($keyword !== null) { |
|
| 266 | + if ($keyword !== null) |
|
| 267 | + { |
|
| 247 | 268 | $options[$keyword] = trim($token->content, $token->content[0]); |
| 248 | 269 | $keyword = null; |
| 249 | 270 | break; |
@@ -252,7 +273,8 @@ discard block |
||
| 252 | 273 | $keyword = trim($token->content, $token->content[0]); |
| 253 | 274 | break; |
| 254 | 275 | case DeclareGrammar::TYPE_COMMA: |
| 255 | - if ($keyword !== null) { |
|
| 276 | + if ($keyword !== null) |
|
| 277 | + { |
|
| 256 | 278 | $options[$keyword] = null; |
| 257 | 279 | $keyword = null; |
| 258 | 280 | break; |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | $buffer = null; |
| 28 | 28 | $bufferOffset = 0; |
| 29 | 29 | |
| 30 | - foreach ($inner as $n) { |
|
| 30 | + foreach ($inner as $n){ |
|
| 31 | 31 | $token->offset ??= $n->offset; |
| 32 | 32 | |
| 33 | - if ($n instanceof Byte) { |
|
| 34 | - if ($buffer === null) { |
|
| 33 | + if ($n instanceof Byte){ |
|
| 34 | + if ($buffer === null){ |
|
| 35 | 35 | $buffer = ''; |
| 36 | 36 | $bufferOffset = $n->offset; |
| 37 | 37 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | continue; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ($buffer !== null) { |
|
| 45 | + if ($buffer !== null){ |
|
| 46 | 46 | $token->tokens[] = new Token( |
| 47 | 47 | Token::TYPE_RAW, |
| 48 | 48 | $bufferOffset, |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $token->tokens[] = $n; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ($buffer !== null) { |
|
| 59 | + if ($buffer !== null){ |
|
| 60 | 60 | $token->tokens[] = new Token( |
| 61 | 61 | Token::TYPE_RAW, |
| 62 | 62 | $bufferOffset, |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW) { |
|
| 68 | + if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW){ |
|
| 69 | 69 | $token->tokens = []; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -27,11 +27,14 @@ discard block |
||
| 27 | 27 | $buffer = null; |
| 28 | 28 | $bufferOffset = 0; |
| 29 | 29 | |
| 30 | - foreach ($inner as $n) { |
|
| 30 | + foreach ($inner as $n) |
|
| 31 | + { |
|
| 31 | 32 | $token->offset ??= $n->offset; |
| 32 | 33 | |
| 33 | - if ($n instanceof Byte) { |
|
| 34 | - if ($buffer === null) { |
|
| 34 | + if ($n instanceof Byte) |
|
| 35 | + { |
|
| 36 | + if ($buffer === null) |
|
| 37 | + { |
|
| 35 | 38 | $buffer = ''; |
| 36 | 39 | $bufferOffset = $n->offset; |
| 37 | 40 | } |
@@ -42,7 +45,8 @@ discard block |
||
| 42 | 45 | continue; |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | - if ($buffer !== null) { |
|
| 48 | + if ($buffer !== null) |
|
| 49 | + { |
|
| 46 | 50 | $token->tokens[] = new Token( |
| 47 | 51 | Token::TYPE_RAW, |
| 48 | 52 | $bufferOffset, |
@@ -56,7 +60,8 @@ discard block |
||
| 56 | 60 | $token->tokens[] = $n; |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | - if ($buffer !== null) { |
|
| 63 | + if ($buffer !== null) |
|
| 64 | + { |
|
| 60 | 65 | $token->tokens[] = new Token( |
| 61 | 66 | Token::TYPE_RAW, |
| 62 | 67 | $bufferOffset, |
@@ -65,7 +70,8 @@ discard block |
||
| 65 | 70 | ); |
| 66 | 71 | } |
| 67 | 72 | |
| 68 | - if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW) { |
|
| 73 | + if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW) |
|
| 74 | + { |
|
| 69 | 75 | $token->tokens = []; |
| 70 | 76 | } |
| 71 | 77 | |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function parse(Buffer $src): Generator |
| 29 | 29 | { |
| 30 | - while ($n = $src->next()) { |
|
| 31 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
| 30 | + while ($n = $src->next()){ |
|
| 31 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?'){ |
|
| 32 | 32 | yield $n; |
| 33 | 33 | continue; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
|
| 37 | - if ($php === null) { |
|
| 36 | + $php = $this->parseGrammar($n->char.$src->nextBytes(), $n->offset); |
|
| 37 | + if ($php === null){ |
|
| 38 | 38 | yield $n; |
| 39 | 39 | $src->replay($n->offset); |
| 40 | 40 | continue; |
@@ -57,27 +57,27 @@ discard block |
||
| 57 | 57 | private function parseGrammar(string $content, int $offset): ?Token |
| 58 | 58 | { |
| 59 | 59 | $tokens = null; |
| 60 | - foreach (token_get_all($content) as $token) { |
|
| 61 | - if ($tokens === null) { |
|
| 62 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
| 60 | + foreach (token_get_all($content) as $token){ |
|
| 61 | + if ($tokens === null){ |
|
| 62 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])){ |
|
| 63 | 63 | // not php |
| 64 | 64 | return null; |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $tokens[] = $token; |
| 69 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
| 69 | + if ($this->is($token, [T_CLOSE_TAG])){ |
|
| 70 | 70 | break; |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($tokens === null) { |
|
| 74 | + if ($tokens === null){ |
|
| 75 | 75 | return null; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $buffer = ''; |
| 79 | - foreach ($tokens as $token) { |
|
| 80 | - if (!is_array($token)) { |
|
| 79 | + foreach ($tokens as $token){ |
|
| 80 | + if (!is_array($token)){ |
|
| 81 | 81 | $buffer .= $token; |
| 82 | 82 | continue; |
| 83 | 83 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | private function is($token, array $type): bool |
| 97 | 97 | { |
| 98 | - if (!is_array($token)) { |
|
| 98 | + if (!is_array($token)){ |
|
| 99 | 99 | return false; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -27,14 +27,17 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function parse(Buffer $src): Generator |
| 29 | 29 | { |
| 30 | - while ($n = $src->next()) { |
|
| 31 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
| 30 | + while ($n = $src->next()) |
|
| 31 | + { |
|
| 32 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') |
|
| 33 | + { |
|
| 32 | 34 | yield $n; |
| 33 | 35 | continue; |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
| 37 | - if ($php === null) { |
|
| 39 | + if ($php === null) |
|
| 40 | + { |
|
| 38 | 41 | yield $n; |
| 39 | 42 | $src->replay($n->offset); |
| 40 | 43 | continue; |
@@ -57,27 +60,34 @@ discard block |
||
| 57 | 60 | private function parseGrammar(string $content, int $offset): ?Token |
| 58 | 61 | { |
| 59 | 62 | $tokens = null; |
| 60 | - foreach (token_get_all($content) as $token) { |
|
| 61 | - if ($tokens === null) { |
|
| 62 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
| 63 | + foreach (token_get_all($content) as $token) |
|
| 64 | + { |
|
| 65 | + if ($tokens === null) |
|
| 66 | + { |
|
| 67 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) |
|
| 68 | + { |
|
| 63 | 69 | // not php |
| 64 | 70 | return null; |
| 65 | 71 | } |
| 66 | 72 | } |
| 67 | 73 | |
| 68 | 74 | $tokens[] = $token; |
| 69 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
| 75 | + if ($this->is($token, [T_CLOSE_TAG])) |
|
| 76 | + { |
|
| 70 | 77 | break; |
| 71 | 78 | } |
| 72 | 79 | } |
| 73 | 80 | |
| 74 | - if ($tokens === null) { |
|
| 81 | + if ($tokens === null) |
|
| 82 | + { |
|
| 75 | 83 | return null; |
| 76 | 84 | } |
| 77 | 85 | |
| 78 | 86 | $buffer = ''; |
| 79 | - foreach ($tokens as $token) { |
|
| 80 | - if (!is_array($token)) { |
|
| 87 | + foreach ($tokens as $token) |
|
| 88 | + { |
|
| 89 | + if (!is_array($token)) |
|
| 90 | + { |
|
| 81 | 91 | $buffer .= $token; |
| 82 | 92 | continue; |
| 83 | 93 | } |
@@ -95,7 +105,8 @@ discard block |
||
| 95 | 105 | */ |
| 96 | 106 | private function is($token, array $type): bool |
| 97 | 107 | { |
| 98 | - if (!is_array($token)) { |
|
| 108 | + if (!is_array($token)) |
|
| 109 | + { |
|
| 99 | 110 | return false; |
| 100 | 111 | } |
| 101 | 112 | |