@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | // We can scan top level only |
41 | 41 | |
42 | 42 | /** @var Location $loc */ |
43 | - foreach ($this->lines as $line) { |
|
44 | - if (!in_array($this->paths[$line[0]], $paths, true)) { |
|
43 | + foreach ($this->lines as $line){ |
|
44 | + if (!in_array($this->paths[$line[0]], $paths, true)){ |
|
45 | 45 | $paths[] = $this->paths[$line[0]]; |
46 | 46 | } |
47 | 47 | } |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | public function getStack(int $line): array |
60 | 60 | { |
61 | 61 | $found = null; |
62 | - foreach ($this->lines as $linen => $ctx) { |
|
63 | - if ($linen <= $line) { |
|
62 | + foreach ($this->lines as $linen => $ctx){ |
|
63 | + if ($linen <= $line){ |
|
64 | 64 | $found = $ctx; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - if ($found === null) { |
|
68 | + if ($found === null){ |
|
69 | 69 | return []; |
70 | 70 | } |
71 | 71 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | { |
110 | 110 | $map = new self(); |
111 | 111 | |
112 | - foreach ($locations as $offset => $location) { |
|
112 | + foreach ($locations as $offset => $location){ |
|
113 | 113 | $line = Source::resolveLine($content, $offset); |
114 | - if (!isset($map->lines[$line])) { |
|
114 | + if (!isset($map->lines[$line])){ |
|
115 | 115 | $map->lines[$line] = $map->calculateLine($location, $loader); |
116 | 116 | } |
117 | 117 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | 'line' => $line[1], |
133 | 133 | ]; |
134 | 134 | |
135 | - if ($line[2] !== null) { |
|
135 | + if ($line[2] !== null){ |
|
136 | 136 | $this->unpack($result, $line[2]); |
137 | 137 | } |
138 | 138 | } |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | */ |
145 | 145 | private function calculateLine(Location $location, LoaderInterface $loader): array |
146 | 146 | { |
147 | - if (!isset($this->sourceCache[$location->path])) { |
|
147 | + if (!isset($this->sourceCache[$location->path])){ |
|
148 | 148 | $this->sourceCache[$location->path] = $loader->load($location->path); |
149 | 149 | } |
150 | 150 | $path = $this->sourceCache[$location->path]->getFilename(); |
151 | 151 | |
152 | - if (!in_array($path, $this->paths, true)) { |
|
152 | + if (!in_array($path, $this->paths, true)){ |
|
153 | 153 | $this->paths[] = $path; |
154 | 154 | } |
155 | 155 |
@@ -40,8 +40,10 @@ discard block |
||
40 | 40 | // We can scan top level only |
41 | 41 | |
42 | 42 | /** @var Location $loc */ |
43 | - foreach ($this->lines as $line) { |
|
44 | - if (!in_array($this->paths[$line[0]], $paths, true)) { |
|
43 | + foreach ($this->lines as $line) |
|
44 | + { |
|
45 | + if (!in_array($this->paths[$line[0]], $paths, true)) |
|
46 | + { |
|
45 | 47 | $paths[] = $this->paths[$line[0]]; |
46 | 48 | } |
47 | 49 | } |
@@ -59,13 +61,16 @@ discard block |
||
59 | 61 | public function getStack(int $line): array |
60 | 62 | { |
61 | 63 | $found = null; |
62 | - foreach ($this->lines as $linen => $ctx) { |
|
63 | - if ($linen <= $line) { |
|
64 | + foreach ($this->lines as $linen => $ctx) |
|
65 | + { |
|
66 | + if ($linen <= $line) |
|
67 | + { |
|
64 | 68 | $found = $ctx; |
65 | 69 | } |
66 | 70 | } |
67 | 71 | |
68 | - if ($found === null) { |
|
72 | + if ($found === null) |
|
73 | + { |
|
69 | 74 | return []; |
70 | 75 | } |
71 | 76 | |
@@ -109,9 +114,11 @@ discard block |
||
109 | 114 | { |
110 | 115 | $map = new self(); |
111 | 116 | |
112 | - foreach ($locations as $offset => $location) { |
|
117 | + foreach ($locations as $offset => $location) |
|
118 | + { |
|
113 | 119 | $line = Source::resolveLine($content, $offset); |
114 | - if (!isset($map->lines[$line])) { |
|
120 | + if (!isset($map->lines[$line])) |
|
121 | + { |
|
115 | 122 | $map->lines[$line] = $map->calculateLine($location, $loader); |
116 | 123 | } |
117 | 124 | } |
@@ -132,7 +139,8 @@ discard block |
||
132 | 139 | 'line' => $line[1], |
133 | 140 | ]; |
134 | 141 | |
135 | - if ($line[2] !== null) { |
|
142 | + if ($line[2] !== null) |
|
143 | + { |
|
136 | 144 | $this->unpack($result, $line[2]); |
137 | 145 | } |
138 | 146 | } |
@@ -144,12 +152,14 @@ discard block |
||
144 | 152 | */ |
145 | 153 | private function calculateLine(Location $location, LoaderInterface $loader): array |
146 | 154 | { |
147 | - if (!isset($this->sourceCache[$location->path])) { |
|
155 | + if (!isset($this->sourceCache[$location->path])) |
|
156 | + { |
|
148 | 157 | $this->sourceCache[$location->path] = $loader->load($location->path); |
149 | 158 | } |
150 | 159 | $path = $this->sourceCache[$location->path]->getFilename(); |
151 | 160 | |
152 | - if (!in_array($path, $this->paths, true)) { |
|
161 | + if (!in_array($path, $this->paths, true)) |
|
162 | + { |
|
153 | 163 | $this->paths[] = $path; |
154 | 164 | } |
155 | 165 |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*'){ |
|
53 | 53 | // accept everything |
54 | 54 | return $name; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
58 | + foreach (explode(';', $this->pattern) as $condition){ |
|
59 | + if (strpos($condition, ':') === false){ |
|
60 | 60 | //Invalid |
61 | 61 | continue; |
62 | 62 | } |
@@ -65,27 +65,27 @@ discard block |
||
65 | 65 | $conditions[$option] = $value; |
66 | 66 | } |
67 | 67 | |
68 | - if (isset($conditions['include'])) { |
|
68 | + if (isset($conditions['include'])){ |
|
69 | 69 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
70 | + if (in_array($name, $include)){ |
|
71 | 71 | return $name; |
72 | 72 | } |
73 | 73 | |
74 | 74 | return null; |
75 | 75 | } |
76 | 76 | |
77 | - if (isset($conditions['exclude'])) { |
|
77 | + if (isset($conditions['exclude'])){ |
|
78 | 78 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
79 | + if (in_array($name, $exclude)){ |
|
80 | 80 | return null; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return $name; |
84 | 84 | } |
85 | 85 | |
86 | - if (isset($conditions['prefix'])) { |
|
86 | + if (isset($conditions['prefix'])){ |
|
87 | 87 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
88 | + if (strpos($name, $conditions['prefix']) === 0){ |
|
89 | 89 | return substr($name, strlen($conditions['prefix'])); |
90 | 90 | } |
91 | 91 |
@@ -49,14 +49,17 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function accepts(string $name): ?string |
51 | 51 | { |
52 | - if ($this->pattern === '' || $this->pattern === '*') { |
|
52 | + if ($this->pattern === '' || $this->pattern === '*') |
|
53 | + { |
|
53 | 54 | // accept everything |
54 | 55 | return $name; |
55 | 56 | } |
56 | 57 | |
57 | 58 | $conditions = []; |
58 | - foreach (explode(';', $this->pattern) as $condition) { |
|
59 | - if (strpos($condition, ':') === false) { |
|
59 | + foreach (explode(';', $this->pattern) as $condition) |
|
60 | + { |
|
61 | + if (strpos($condition, ':') === false) |
|
62 | + { |
|
60 | 63 | //Invalid |
61 | 64 | continue; |
62 | 65 | } |
@@ -65,27 +68,33 @@ discard block |
||
65 | 68 | $conditions[$option] = $value; |
66 | 69 | } |
67 | 70 | |
68 | - if (isset($conditions['include'])) { |
|
71 | + if (isset($conditions['include'])) |
|
72 | + { |
|
69 | 73 | $include = explode(',', $conditions['include']); |
70 | - if (in_array($name, $include)) { |
|
74 | + if (in_array($name, $include)) |
|
75 | + { |
|
71 | 76 | return $name; |
72 | 77 | } |
73 | 78 | |
74 | 79 | return null; |
75 | 80 | } |
76 | 81 | |
77 | - if (isset($conditions['exclude'])) { |
|
82 | + if (isset($conditions['exclude'])) |
|
83 | + { |
|
78 | 84 | $exclude = explode(',', $conditions['exclude']); |
79 | - if (in_array($name, $exclude)) { |
|
85 | + if (in_array($name, $exclude)) |
|
86 | + { |
|
80 | 87 | return null; |
81 | 88 | } |
82 | 89 | |
83 | 90 | return $name; |
84 | 91 | } |
85 | 92 | |
86 | - if (isset($conditions['prefix'])) { |
|
93 | + if (isset($conditions['prefix'])) |
|
94 | + { |
|
87 | 95 | $conditions['prefix'] = rtrim($conditions['prefix'], ' *'); |
88 | - if (strpos($name, $conditions['prefix']) === 0) { |
|
96 | + if (strpos($name, $conditions['prefix']) === 0) |
|
97 | + { |
|
89 | 98 | return substr($name, strlen($conditions['prefix'])); |
90 | 99 | } |
91 | 100 |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | public function parse(StreamInterface $src): \Generator |
45 | 45 | { |
46 | 46 | $stream = new Buffer($this->generate($src)); |
47 | - foreach ($this->grammars as $grammar) { |
|
47 | + foreach ($this->grammars as $grammar){ |
|
48 | 48 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
49 | 49 | } |
50 | 50 | |
51 | 51 | // always group raw bytes into raw tokens |
52 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
52 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n){ |
|
53 | 53 | yield $n; |
54 | 54 | } |
55 | 55 | } |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
63 | 63 | { |
64 | - foreach ($grammar->parse($stream) as $n) { |
|
65 | - if ($n instanceof Token && $n->grammar === null) { |
|
64 | + foreach ($grammar->parse($stream) as $n){ |
|
65 | + if ($n instanceof Token && $n->grammar === null){ |
|
66 | 66 | $n->grammar = get_class($grammar); |
67 | 67 | } |
68 | 68 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | private function generate(StreamInterface $src) |
80 | 80 | { |
81 | - while (!$src->isEOI()) { |
|
81 | + while (!$src->isEOI()){ |
|
82 | 82 | yield new Byte($src->getOffset(), $src->peak()); |
83 | 83 | } |
84 | 84 | } |
@@ -44,12 +44,14 @@ discard block |
||
44 | 44 | public function parse(StreamInterface $src): \Generator |
45 | 45 | { |
46 | 46 | $stream = new Buffer($this->generate($src)); |
47 | - foreach ($this->grammars as $grammar) { |
|
47 | + foreach ($this->grammars as $grammar) |
|
48 | + { |
|
48 | 49 | $stream = new Buffer($this->wrap(clone $grammar, $stream)); |
49 | 50 | } |
50 | 51 | |
51 | 52 | // always group raw bytes into raw tokens |
52 | - foreach ($this->wrap(new RawGrammar(), $stream) as $n) { |
|
53 | + foreach ($this->wrap(new RawGrammar(), $stream) as $n) |
|
54 | + { |
|
53 | 55 | yield $n; |
54 | 56 | } |
55 | 57 | } |
@@ -61,8 +63,10 @@ discard block |
||
61 | 63 | */ |
62 | 64 | private function wrap(GrammarInterface $grammar, Buffer $stream): \Generator |
63 | 65 | { |
64 | - foreach ($grammar->parse($stream) as $n) { |
|
65 | - if ($n instanceof Token && $n->grammar === null) { |
|
66 | + foreach ($grammar->parse($stream) as $n) |
|
67 | + { |
|
68 | + if ($n instanceof Token && $n->grammar === null) |
|
69 | + { |
|
66 | 70 | $n->grammar = get_class($grammar); |
67 | 71 | } |
68 | 72 | |
@@ -78,7 +82,8 @@ discard block |
||
78 | 82 | */ |
79 | 83 | private function generate(StreamInterface $src) |
80 | 84 | { |
81 | - while (!$src->isEOI()) { |
|
85 | + while (!$src->isEOI()) |
|
86 | + { |
|
82 | 87 | yield new Byte($src->getOffset(), $src->peak()); |
83 | 88 | } |
84 | 89 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 |
@@ -53,7 +53,8 @@ |
||
53 | 53 | */ |
54 | 54 | public function peak(): ?string |
55 | 55 | { |
56 | - if ($this->offset + 1 > $this->length) { |
|
56 | + if ($this->offset + 1 > $this->length) |
|
57 | + { |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getIterator() |
48 | 48 | { |
49 | - while ($n = $this->next()) { |
|
49 | + while ($n = $this->next()){ |
|
50 | 50 | yield $n; |
51 | 51 | } |
52 | 52 | } |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function next() |
66 | 66 | { |
67 | - if ($this->replay !== []) { |
|
67 | + if ($this->replay !== []){ |
|
68 | 68 | $n = array_shift($this->replay); |
69 | - } else { |
|
69 | + }else{ |
|
70 | 70 | $n = $this->generator->current(); |
71 | - if ($n === null) { |
|
71 | + if ($n === null){ |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | $this->generator->next(); |
75 | 75 | $this->buffer[] = $n; |
76 | 76 | } |
77 | 77 | |
78 | - if ($n !== null) { |
|
78 | + if ($n !== null){ |
|
79 | 79 | $this->offset = $n->offset; |
80 | 80 | } |
81 | 81 | |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | public function nextBytes(): string |
91 | 91 | { |
92 | 92 | $result = ''; |
93 | - while ($n = $this->next()) { |
|
94 | - if ($n instanceof Byte) { |
|
93 | + while ($n = $this->next()){ |
|
94 | + if ($n instanceof Byte){ |
|
95 | 95 | $result .= $n->char; |
96 | - } else { |
|
96 | + }else{ |
|
97 | 97 | break; |
98 | 98 | } |
99 | 99 | } |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function lookahead() |
108 | 108 | { |
109 | - if ($this->replay !== []) { |
|
109 | + if ($this->replay !== []){ |
|
110 | 110 | return $this->replay[0]; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $n = $this->next(); |
114 | - if ($n !== null) { |
|
114 | + if ($n !== null){ |
|
115 | 115 | array_unshift($this->replay, $n); |
116 | 116 | } |
117 | 117 | |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | { |
129 | 129 | $result = ''; |
130 | 130 | $replay = []; |
131 | - for ($i = 0; $i < $size; $i++) { |
|
131 | + for ($i = 0; $i < $size; $i++){ |
|
132 | 132 | $n = $this->next(); |
133 | - if ($n !== null) { |
|
133 | + if ($n !== null){ |
|
134 | 134 | $replay[] = $n; |
135 | 135 | } |
136 | 136 | |
137 | - if (!$n instanceof Byte) { |
|
137 | + if (!$n instanceof Byte){ |
|
138 | 138 | break; |
139 | 139 | } |
140 | 140 | |
141 | 141 | $result .= $n->char; |
142 | 142 | } |
143 | 143 | |
144 | - foreach (array_reverse($replay) as $n) { |
|
144 | + foreach (array_reverse($replay) as $n){ |
|
145 | 145 | array_unshift($this->replay, $n); |
146 | 146 | } |
147 | 147 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function replay(int $offset): void |
157 | 157 | { |
158 | - foreach ($this->buffer as $n) { |
|
159 | - if ($n->offset > $offset) { |
|
158 | + foreach ($this->buffer as $n){ |
|
159 | + if ($n->offset > $offset){ |
|
160 | 160 | $this->replay[] = $n; |
161 | 161 | } |
162 | 162 | } |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getIterator() |
48 | 48 | { |
49 | - while ($n = $this->next()) { |
|
49 | + while ($n = $this->next()) |
|
50 | + { |
|
50 | 51 | yield $n; |
51 | 52 | } |
52 | 53 | } |
@@ -64,18 +65,23 @@ discard block |
||
64 | 65 | */ |
65 | 66 | public function next() |
66 | 67 | { |
67 | - if ($this->replay !== []) { |
|
68 | + if ($this->replay !== []) |
|
69 | + { |
|
68 | 70 | $n = array_shift($this->replay); |
69 | - } else { |
|
71 | + } |
|
72 | + else |
|
73 | + { |
|
70 | 74 | $n = $this->generator->current(); |
71 | - if ($n === null) { |
|
75 | + if ($n === null) |
|
76 | + { |
|
72 | 77 | return null; |
73 | 78 | } |
74 | 79 | $this->generator->next(); |
75 | 80 | $this->buffer[] = $n; |
76 | 81 | } |
77 | 82 | |
78 | - if ($n !== null) { |
|
83 | + if ($n !== null) |
|
84 | + { |
|
79 | 85 | $this->offset = $n->offset; |
80 | 86 | } |
81 | 87 | |
@@ -90,10 +96,14 @@ discard block |
||
90 | 96 | public function nextBytes(): string |
91 | 97 | { |
92 | 98 | $result = ''; |
93 | - while ($n = $this->next()) { |
|
94 | - if ($n instanceof Byte) { |
|
99 | + while ($n = $this->next()) |
|
100 | + { |
|
101 | + if ($n instanceof Byte) |
|
102 | + { |
|
95 | 103 | $result .= $n->char; |
96 | - } else { |
|
104 | + } |
|
105 | + else |
|
106 | + { |
|
97 | 107 | break; |
98 | 108 | } |
99 | 109 | } |
@@ -106,12 +116,14 @@ discard block |
||
106 | 116 | */ |
107 | 117 | public function lookahead() |
108 | 118 | { |
109 | - if ($this->replay !== []) { |
|
119 | + if ($this->replay !== []) |
|
120 | + { |
|
110 | 121 | return $this->replay[0]; |
111 | 122 | } |
112 | 123 | |
113 | 124 | $n = $this->next(); |
114 | - if ($n !== null) { |
|
125 | + if ($n !== null) |
|
126 | + { |
|
115 | 127 | array_unshift($this->replay, $n); |
116 | 128 | } |
117 | 129 | |
@@ -128,20 +140,24 @@ discard block |
||
128 | 140 | { |
129 | 141 | $result = ''; |
130 | 142 | $replay = []; |
131 | - for ($i = 0; $i < $size; $i++) { |
|
143 | + for ($i = 0; $i < $size; $i++) |
|
144 | + { |
|
132 | 145 | $n = $this->next(); |
133 | - if ($n !== null) { |
|
146 | + if ($n !== null) |
|
147 | + { |
|
134 | 148 | $replay[] = $n; |
135 | 149 | } |
136 | 150 | |
137 | - if (!$n instanceof Byte) { |
|
151 | + if (!$n instanceof Byte) |
|
152 | + { |
|
138 | 153 | break; |
139 | 154 | } |
140 | 155 | |
141 | 156 | $result .= $n->char; |
142 | 157 | } |
143 | 158 | |
144 | - foreach (array_reverse($replay) as $n) { |
|
159 | + foreach (array_reverse($replay) as $n) |
|
160 | + { |
|
145 | 161 | array_unshift($this->replay, $n); |
146 | 162 | } |
147 | 163 | |
@@ -155,8 +171,10 @@ discard block |
||
155 | 171 | */ |
156 | 172 | public function replay(int $offset): void |
157 | 173 | { |
158 | - foreach ($this->buffer as $n) { |
|
159 | - if ($n->offset > $offset) { |
|
174 | + foreach ($this->buffer as $n) |
|
175 | + { |
|
176 | + if ($n->offset > $offset) |
|
177 | + { |
|
160 | 178 | $this->replay[] = $n; |
161 | 179 | } |
162 | 180 | } |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function parse(Buffer $src): \Generator |
28 | 28 | { |
29 | - while ($n = $src->next()) { |
|
30 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
29 | + while ($n = $src->next()){ |
|
30 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?'){ |
|
31 | 31 | yield $n; |
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
|
36 | - if ($php === null) { |
|
35 | + $php = $this->parseGrammar($n->char.$src->nextBytes(), $n->offset); |
|
36 | + if ($php === null){ |
|
37 | 37 | yield $n; |
38 | 38 | $src->replay($n->offset); |
39 | 39 | continue; |
@@ -61,27 +61,27 @@ discard block |
||
61 | 61 | private function parseGrammar(string $content, int $offset): ?Token |
62 | 62 | { |
63 | 63 | $tokens = null; |
64 | - foreach (token_get_all($content) as $token) { |
|
65 | - if ($tokens === null) { |
|
66 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
64 | + foreach (token_get_all($content) as $token){ |
|
65 | + if ($tokens === null){ |
|
66 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])){ |
|
67 | 67 | // not php |
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | $tokens[] = $token; |
73 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
73 | + if ($this->is($token, [T_CLOSE_TAG])){ |
|
74 | 74 | break; |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | - if ($tokens === null) { |
|
78 | + if ($tokens === null){ |
|
79 | 79 | return null; |
80 | 80 | } |
81 | 81 | |
82 | 82 | $buffer = ''; |
83 | - foreach ($tokens as $token) { |
|
84 | - if (!is_array($token)) { |
|
83 | + foreach ($tokens as $token){ |
|
84 | + if (!is_array($token)){ |
|
85 | 85 | $buffer .= $token; |
86 | 86 | continue; |
87 | 87 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | private function is($token, array $type): bool |
103 | 103 | { |
104 | - if (!is_array($token)) { |
|
104 | + if (!is_array($token)){ |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 |
@@ -26,14 +26,17 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function parse(Buffer $src): \Generator |
28 | 28 | { |
29 | - while ($n = $src->next()) { |
|
30 | - if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') { |
|
29 | + while ($n = $src->next()) |
|
30 | + { |
|
31 | + if (!$n instanceof Byte || $n->char !== '<' || $src->lookaheadByte() !== '?') |
|
32 | + { |
|
31 | 33 | yield $n; |
32 | 34 | continue; |
33 | 35 | } |
34 | 36 | |
35 | 37 | $php = $this->parseGrammar($n->char . $src->nextBytes(), $n->offset); |
36 | - if ($php === null) { |
|
38 | + if ($php === null) |
|
39 | + { |
|
37 | 40 | yield $n; |
38 | 41 | $src->replay($n->offset); |
39 | 42 | continue; |
@@ -61,27 +64,34 @@ discard block |
||
61 | 64 | private function parseGrammar(string $content, int $offset): ?Token |
62 | 65 | { |
63 | 66 | $tokens = null; |
64 | - foreach (token_get_all($content) as $token) { |
|
65 | - if ($tokens === null) { |
|
66 | - if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) { |
|
67 | + foreach (token_get_all($content) as $token) |
|
68 | + { |
|
69 | + if ($tokens === null) |
|
70 | + { |
|
71 | + if (!$this->is($token, [T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) |
|
72 | + { |
|
67 | 73 | // not php |
68 | 74 | return null; |
69 | 75 | } |
70 | 76 | } |
71 | 77 | |
72 | 78 | $tokens[] = $token; |
73 | - if ($this->is($token, [T_CLOSE_TAG])) { |
|
79 | + if ($this->is($token, [T_CLOSE_TAG])) |
|
80 | + { |
|
74 | 81 | break; |
75 | 82 | } |
76 | 83 | } |
77 | 84 | |
78 | - if ($tokens === null) { |
|
85 | + if ($tokens === null) |
|
86 | + { |
|
79 | 87 | return null; |
80 | 88 | } |
81 | 89 | |
82 | 90 | $buffer = ''; |
83 | - foreach ($tokens as $token) { |
|
84 | - if (!is_array($token)) { |
|
91 | + foreach ($tokens as $token) |
|
92 | + { |
|
93 | + if (!is_array($token)) |
|
94 | + { |
|
85 | 95 | $buffer .= $token; |
86 | 96 | continue; |
87 | 97 | } |
@@ -101,7 +111,8 @@ discard block |
||
101 | 111 | */ |
102 | 112 | private function is($token, array $type): bool |
103 | 113 | { |
104 | - if (!is_array($token)) { |
|
114 | + if (!is_array($token)) |
|
115 | + { |
|
105 | 116 | return false; |
106 | 117 | } |
107 | 118 |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | $buffer = null; |
33 | 33 | $bufferOffset = 0; |
34 | 34 | |
35 | - foreach ($inner as $n) { |
|
35 | + foreach ($inner as $n){ |
|
36 | 36 | $token->offset = $token->offset ?? $n->offset; |
37 | 37 | |
38 | - if ($n instanceof Byte) { |
|
39 | - if ($buffer === null) { |
|
38 | + if ($n instanceof Byte){ |
|
39 | + if ($buffer === null){ |
|
40 | 40 | $buffer = ''; |
41 | 41 | $bufferOffset = $n->offset; |
42 | 42 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | |
50 | - if ($buffer !== null) { |
|
50 | + if ($buffer !== null){ |
|
51 | 51 | $token->tokens[] = new Token( |
52 | 52 | Token::TYPE_RAW, |
53 | 53 | $bufferOffset, |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $token->tokens[] = $n; |
62 | 62 | } |
63 | 63 | |
64 | - if ($buffer !== null) { |
|
64 | + if ($buffer !== null){ |
|
65 | 65 | $token->tokens[] = new Token( |
66 | 66 | Token::TYPE_RAW, |
67 | 67 | $bufferOffset, |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
73 | - 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 | 74 | $token->tokens = []; |
75 | 75 | } |
76 | 76 |
@@ -32,11 +32,14 @@ discard block |
||
32 | 32 | $buffer = null; |
33 | 33 | $bufferOffset = 0; |
34 | 34 | |
35 | - foreach ($inner as $n) { |
|
35 | + foreach ($inner as $n) |
|
36 | + { |
|
36 | 37 | $token->offset = $token->offset ?? $n->offset; |
37 | 38 | |
38 | - if ($n instanceof Byte) { |
|
39 | - if ($buffer === null) { |
|
39 | + if ($n instanceof Byte) |
|
40 | + { |
|
41 | + if ($buffer === null) |
|
42 | + { |
|
40 | 43 | $buffer = ''; |
41 | 44 | $bufferOffset = $n->offset; |
42 | 45 | } |
@@ -47,7 +50,8 @@ discard block |
||
47 | 50 | continue; |
48 | 51 | } |
49 | 52 | |
50 | - if ($buffer !== null) { |
|
53 | + if ($buffer !== null) |
|
54 | + { |
|
51 | 55 | $token->tokens[] = new Token( |
52 | 56 | Token::TYPE_RAW, |
53 | 57 | $bufferOffset, |
@@ -61,7 +65,8 @@ discard block |
||
61 | 65 | $token->tokens[] = $n; |
62 | 66 | } |
63 | 67 | |
64 | - if ($buffer !== null) { |
|
68 | + if ($buffer !== null) |
|
69 | + { |
|
65 | 70 | $token->tokens[] = new Token( |
66 | 71 | Token::TYPE_RAW, |
67 | 72 | $bufferOffset, |
@@ -70,7 +75,8 @@ discard block |
||
70 | 75 | ); |
71 | 76 | } |
72 | 77 | |
73 | - if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW) { |
|
78 | + if (count($token->tokens) === 1 && $token->tokens[0]->type === Token::TYPE_RAW) |
|
79 | + { |
|
74 | 80 | $token->tokens = []; |
75 | 81 | } |
76 | 82 |
@@ -84,33 +84,33 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function parse(Buffer $src): \Generator |
86 | 86 | { |
87 | - while ($n = $src->next()) { |
|
88 | - if (!$n instanceof Byte) { |
|
87 | + while ($n = $src->next()){ |
|
88 | + if (!$n instanceof Byte){ |
|
89 | 89 | yield $n; |
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | |
93 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
93 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR){ |
|
94 | 94 | if ( |
95 | 95 | $this->echo->nextToken($src) || |
96 | 96 | $this->raw->nextToken($src) || |
97 | 97 | $src->lookaheadByte() === DirectiveGrammar::DIRECTIVE_CHAR |
98 | - ) { |
|
98 | + ){ |
|
99 | 99 | // escaped echo sequence, hide directive byte |
100 | 100 | yield $src->next(); |
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $directive = new DirectiveGrammar(); |
105 | - if ($directive->parse($src, $n->offset)) { |
|
106 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
105 | + if ($directive->parse($src, $n->offset)){ |
|
106 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE){ |
|
107 | 107 | // configure braces syntax |
108 | 108 | $this->declare($directive->getBody()); |
109 | - } else { |
|
109 | + }else{ |
|
110 | 110 | if ( |
111 | 111 | $this->directiveRenderer !== null |
112 | 112 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
113 | - ) { |
|
113 | + ){ |
|
114 | 114 | // directive opening char |
115 | 115 | yield $n; |
116 | 116 | |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | |
132 | 132 | /** @var BracesGrammar|null $braces */ |
133 | 133 | $braces = null; |
134 | - if ($this->echo->starts($src, $n)) { |
|
134 | + if ($this->echo->starts($src, $n)){ |
|
135 | 135 | $braces = clone $this->echo; |
136 | - } elseif ($this->raw->starts($src, $n)) { |
|
136 | + } elseif ($this->raw->starts($src, $n)){ |
|
137 | 137 | $braces = clone $this->raw; |
138 | 138 | } |
139 | 139 | |
140 | - if ($braces !== null) { |
|
140 | + if ($braces !== null){ |
|
141 | 141 | $echo = $braces->parse($src, $n); |
142 | - if ($echo !== null) { |
|
142 | + if ($echo !== null){ |
|
143 | 143 | yield from $echo; |
144 | 144 | continue; |
145 | 145 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function tokenName(int $token): string |
161 | 161 | { |
162 | - switch ($token) { |
|
162 | + switch ($token){ |
|
163 | 163 | case self::TYPE_OPEN_TAG: |
164 | 164 | return 'DYNAMIC:OPEN_TAG'; |
165 | 165 | case self::TYPE_CLOSE_TAG: |
@@ -184,20 +184,20 @@ discard block |
||
184 | 184 | /** |
185 | 185 | * @param string $body |
186 | 186 | */ |
187 | - private function declare(?string $body): void |
|
187 | + private function declare(?string$body) : void |
|
188 | 188 | { |
189 | - if ($body === null) { |
|
189 | + if ($body === null){ |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | |
193 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
193 | + foreach ($this->fetchOptions($body) as $option => $value){ |
|
194 | 194 | $value = trim($value, '\'" '); |
195 | - switch ($option) { |
|
195 | + switch ($option){ |
|
196 | 196 | case 'syntax': |
197 | 197 | $this->echo->setActive($value !== 'off'); |
198 | 198 | $this->raw->setActive($value !== 'off'); |
199 | 199 | |
200 | - if ($value === 'default') { |
|
200 | + if ($value === 'default'){ |
|
201 | 201 | $this->echo->setStartSequence('{{'); |
202 | 202 | $this->echo->setEndSequence('}}'); |
203 | 203 | $this->raw->setStartSequence('{!!'); |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | $keyword = null; |
239 | 239 | |
240 | 240 | /** @var Token $token */ |
241 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
242 | - switch ($token->type) { |
|
241 | + foreach ($lexer->parse(new StringStream($body)) as $token){ |
|
242 | + switch ($token->type){ |
|
243 | 243 | case DeclareGrammar::TYPE_KEYWORD: |
244 | - if ($keyword !== null) { |
|
244 | + if ($keyword !== null){ |
|
245 | 245 | $options[$keyword] = $token->content; |
246 | 246 | $keyword = null; |
247 | 247 | break; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $keyword = $token->content; |
250 | 250 | break; |
251 | 251 | case DeclareGrammar::TYPE_QUOTED: |
252 | - if ($keyword !== null) { |
|
252 | + if ($keyword !== null){ |
|
253 | 253 | $options[$keyword] = trim($token->content, $token->content[0]); |
254 | 254 | $keyword = null; |
255 | 255 | break; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $keyword = trim($token->content, $token->content[0]); |
259 | 259 | break; |
260 | 260 | case DeclareGrammar::TYPE_COMMA: |
261 | - if ($keyword !== null) { |
|
261 | + if ($keyword !== null){ |
|
262 | 262 | $options[$keyword] = null; |
263 | 263 | $keyword = null; |
264 | 264 | break; |
@@ -84,13 +84,16 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function parse(Buffer $src): \Generator |
86 | 86 | { |
87 | - while ($n = $src->next()) { |
|
88 | - if (!$n instanceof Byte) { |
|
87 | + while ($n = $src->next()) |
|
88 | + { |
|
89 | + if (!$n instanceof Byte) |
|
90 | + { |
|
89 | 91 | yield $n; |
90 | 92 | continue; |
91 | 93 | } |
92 | 94 | |
93 | - if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) { |
|
95 | + if ($n->char === DirectiveGrammar::DIRECTIVE_CHAR) |
|
96 | + { |
|
94 | 97 | if ( |
95 | 98 | $this->echo->nextToken($src) || |
96 | 99 | $this->raw->nextToken($src) || |
@@ -102,11 +105,15 @@ discard block |
||
102 | 105 | } |
103 | 106 | |
104 | 107 | $directive = new DirectiveGrammar(); |
105 | - if ($directive->parse($src, $n->offset)) { |
|
106 | - if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) { |
|
108 | + if ($directive->parse($src, $n->offset)) |
|
109 | + { |
|
110 | + if (strtolower($directive->getKeyword()) === self::DECLARE_DIRECTIVE) |
|
111 | + { |
|
107 | 112 | // configure braces syntax |
108 | 113 | $this->declare($directive->getBody()); |
109 | - } else { |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
110 | 117 | if ( |
111 | 118 | $this->directiveRenderer !== null |
112 | 119 | && !$this->directiveRenderer->hasDirective($directive->getKeyword()) |
@@ -131,15 +138,20 @@ discard block |
||
131 | 138 | |
132 | 139 | /** @var BracesGrammar|null $braces */ |
133 | 140 | $braces = null; |
134 | - if ($this->echo->starts($src, $n)) { |
|
141 | + if ($this->echo->starts($src, $n)) |
|
142 | + { |
|
135 | 143 | $braces = clone $this->echo; |
136 | - } elseif ($this->raw->starts($src, $n)) { |
|
144 | + } |
|
145 | + elseif ($this->raw->starts($src, $n)) |
|
146 | + { |
|
137 | 147 | $braces = clone $this->raw; |
138 | 148 | } |
139 | 149 | |
140 | - if ($braces !== null) { |
|
150 | + if ($braces !== null) |
|
151 | + { |
|
141 | 152 | $echo = $braces->parse($src, $n); |
142 | - if ($echo !== null) { |
|
153 | + if ($echo !== null) |
|
154 | + { |
|
143 | 155 | yield from $echo; |
144 | 156 | continue; |
145 | 157 | } |
@@ -159,7 +171,8 @@ discard block |
||
159 | 171 | */ |
160 | 172 | public static function tokenName(int $token): string |
161 | 173 | { |
162 | - switch ($token) { |
|
174 | + switch ($token) |
|
175 | + { |
|
163 | 176 | case self::TYPE_OPEN_TAG: |
164 | 177 | return 'DYNAMIC:OPEN_TAG'; |
165 | 178 | case self::TYPE_CLOSE_TAG: |
@@ -186,18 +199,22 @@ discard block |
||
186 | 199 | */ |
187 | 200 | private function declare(?string $body): void |
188 | 201 | { |
189 | - if ($body === null) { |
|
202 | + if ($body === null) |
|
203 | + { |
|
190 | 204 | return; |
191 | 205 | } |
192 | 206 | |
193 | - foreach ($this->fetchOptions($body) as $option => $value) { |
|
207 | + foreach ($this->fetchOptions($body) as $option => $value) |
|
208 | + { |
|
194 | 209 | $value = trim($value, '\'" '); |
195 | - switch ($option) { |
|
210 | + switch ($option) |
|
211 | + { |
|
196 | 212 | case 'syntax': |
197 | 213 | $this->echo->setActive($value !== 'off'); |
198 | 214 | $this->raw->setActive($value !== 'off'); |
199 | 215 | |
200 | - if ($value === 'default') { |
|
216 | + if ($value === 'default') |
|
217 | + { |
|
201 | 218 | $this->echo->setStartSequence('{{'); |
202 | 219 | $this->echo->setEndSequence('}}'); |
203 | 220 | $this->raw->setStartSequence('{!!'); |
@@ -238,10 +255,13 @@ discard block |
||
238 | 255 | $keyword = null; |
239 | 256 | |
240 | 257 | /** @var Token $token */ |
241 | - foreach ($lexer->parse(new StringStream($body)) as $token) { |
|
242 | - switch ($token->type) { |
|
258 | + foreach ($lexer->parse(new StringStream($body)) as $token) |
|
259 | + { |
|
260 | + switch ($token->type) |
|
261 | + { |
|
243 | 262 | case DeclareGrammar::TYPE_KEYWORD: |
244 | - if ($keyword !== null) { |
|
263 | + if ($keyword !== null) |
|
264 | + { |
|
245 | 265 | $options[$keyword] = $token->content; |
246 | 266 | $keyword = null; |
247 | 267 | break; |
@@ -249,7 +269,8 @@ discard block |
||
249 | 269 | $keyword = $token->content; |
250 | 270 | break; |
251 | 271 | case DeclareGrammar::TYPE_QUOTED: |
252 | - if ($keyword !== null) { |
|
272 | + if ($keyword !== null) |
|
273 | + { |
|
253 | 274 | $options[$keyword] = trim($token->content, $token->content[0]); |
254 | 275 | $keyword = null; |
255 | 276 | break; |
@@ -258,7 +279,8 @@ discard block |
||
258 | 279 | $keyword = trim($token->content, $token->content[0]); |
259 | 280 | break; |
260 | 281 | case DeclareGrammar::TYPE_COMMA: |
261 | - if ($keyword !== null) { |
|
282 | + if ($keyword !== null) |
|
283 | + { |
|
262 | 284 | $options[$keyword] = null; |
263 | 285 | $keyword = null; |
264 | 286 | break; |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n){ |
|
31 | + if ($n instanceof Byte){ |
|
32 | + if ($buffer === null){ |
|
33 | 33 | $buffer = ''; |
34 | 34 | $bufferOffset = $n->offset; |
35 | 35 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - if ($buffer !== null) { |
|
41 | + if ($buffer !== null){ |
|
42 | 42 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 43 | $buffer = null; |
44 | 44 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | yield $n; |
47 | 47 | } |
48 | 48 | |
49 | - if ($buffer !== null) { |
|
49 | + if ($buffer !== null){ |
|
50 | 50 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 51 | } |
52 | 52 | } |
@@ -27,9 +27,12 @@ discard block |
||
27 | 27 | $buffer = null; |
28 | 28 | $bufferOffset = 0; |
29 | 29 | |
30 | - foreach ($src as $n) { |
|
31 | - if ($n instanceof Byte) { |
|
32 | - if ($buffer === null) { |
|
30 | + foreach ($src as $n) |
|
31 | + { |
|
32 | + if ($n instanceof Byte) |
|
33 | + { |
|
34 | + if ($buffer === null) |
|
35 | + { |
|
33 | 36 | $buffer = ''; |
34 | 37 | $bufferOffset = $n->offset; |
35 | 38 | } |
@@ -38,7 +41,8 @@ discard block |
||
38 | 41 | continue; |
39 | 42 | } |
40 | 43 | |
41 | - if ($buffer !== null) { |
|
44 | + if ($buffer !== null) |
|
45 | + { |
|
42 | 46 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
43 | 47 | $buffer = null; |
44 | 48 | } |
@@ -46,7 +50,8 @@ discard block |
||
46 | 50 | yield $n; |
47 | 51 | } |
48 | 52 | |
49 | - if ($buffer !== null) { |
|
53 | + if ($buffer !== null) |
|
54 | + { |
|
50 | 55 | yield new Token(Token::TYPE_RAW, $bufferOffset, $buffer); |
51 | 56 | } |
52 | 57 | } |