@@ -25,8 +25,9 @@ discard block |
||
| 25 | 25 | $tree = new AST; |
| 26 | 26 | $objects = new Stack; |
| 27 | 27 | |
| 28 | - if (file_exists ($vst)) |
|
| 29 | - $vst = file_get_contents ($vst); |
|
| 28 | + if (file_exists ($vst)) { |
|
| 29 | + $vst = file_get_contents ($vst); |
|
| 30 | + } |
|
| 30 | 31 | |
| 31 | 32 | $lines = explode (self::$divider, $vst); |
| 32 | 33 | $skip_at = -1; |
@@ -35,24 +36,26 @@ discard block |
||
| 35 | 36 | { |
| 36 | 37 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
| 37 | 38 | |
| 38 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
| 39 | - continue; |
|
| 39 | + if ($skip_at > $line_num || !self::filter ($line)) { |
|
| 40 | + continue; |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | $height = self::getHeight ($line); |
| 42 | 44 | $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
| 43 | 45 | $poped = false; |
| 44 | 46 | |
| 45 | 47 | # Очищаем стек объектов |
| 46 | - while ($objects->size () > 0) |
|
| 47 | - if ($objects->current ()->height >= $height) |
|
| 48 | + while ($objects->size () > 0) { |
|
| 49 | + if ($objects->current ()->height >= $height) |
|
| 48 | 50 | { |
| 49 | 51 | $objects->pop (); |
| 52 | + } |
|
| 50 | 53 | |
| 51 | 54 | $poped = true; |
| 55 | + } else { |
|
| 56 | + break; |
|
| 52 | 57 | } |
| 53 | 58 | |
| 54 | - else break; |
|
| 55 | - |
|
| 56 | 59 | # Создаём новую ссылку на объект |
| 57 | 60 | if ($poped && $objects->size () > 0) |
| 58 | 61 | { |
@@ -72,10 +75,11 @@ discard block |
||
| 72 | 75 | */ |
| 73 | 76 | if (isset ($words[0][1])) |
| 74 | 77 | { |
| 75 | - if ($words[0][1] == '^') |
|
| 76 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 77 | - |
|
| 78 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 78 | + if ($words[0][1] == '^') { |
|
| 79 | + $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 80 | + } else { |
|
| 81 | + throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 82 | + } |
|
| 79 | 83 | } |
| 80 | 84 | |
| 81 | 85 | continue; |
@@ -97,17 +101,19 @@ discard block |
||
| 97 | 101 | { |
| 98 | 102 | $parents = trim (substr ($line, $pos + 1)); |
| 99 | 103 | |
| 100 | - if (strlen ($parents) == 0) |
|
| 101 | - $parents = null; |
|
| 102 | - |
|
| 103 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
| 104 | + if (strlen ($parents) == 0) { |
|
| 105 | + $parents = null; |
|
| 106 | + } else { |
|
| 107 | + $parents = array_map ('trim', explode (',', $parents)); |
|
| 108 | + } |
|
| 104 | 109 | } |
| 110 | + } else { |
|
| 111 | + $name = trim (substr ($line, 1)); |
|
| 105 | 112 | } |
| 106 | 113 | |
| 107 | - else $name = trim (substr ($line, 1)); |
|
| 108 | - |
|
| 109 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
| 110 | - $parents = [$objects->current ()->args['name']]; |
|
| 114 | + if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) { |
|
| 115 | + $parents = [$objects->current ()->args['name']]; |
|
| 116 | + } |
|
| 111 | 117 | |
| 112 | 118 | $objects->push (new Node ([ |
| 113 | 119 | 'type' => \VLF\STYLE_DEFINITION, |
@@ -141,17 +147,19 @@ discard block |
||
| 141 | 147 | { |
| 142 | 148 | $parents = trim (substr ($line, $pos + 1)); |
| 143 | 149 | |
| 144 | - if (strlen ($parents) == 0) |
|
| 145 | - $parents = null; |
|
| 146 | - |
|
| 147 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
| 150 | + if (strlen ($parents) == 0) { |
|
| 151 | + $parents = null; |
|
| 152 | + } else { |
|
| 153 | + $parents = array_map ('trim', explode (',', $parents)); |
|
| 154 | + } |
|
| 148 | 155 | } |
| 156 | + } else { |
|
| 157 | + $name = trim (substr ($line, 1)); |
|
| 149 | 158 | } |
| 150 | 159 | |
| 151 | - else $name = trim (substr ($line, 1)); |
|
| 152 | - |
|
| 153 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
| 154 | - $parents = [$objects->current ()->args['name']]; |
|
| 160 | + if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) { |
|
| 161 | + $parents = [$objects->current ()->args['name']]; |
|
| 162 | + } |
|
| 155 | 163 | |
| 156 | 164 | $objects->push (new Node ([ |
| 157 | 165 | 'type' => \VLF\STYLE_DEFINITION, |
@@ -174,11 +182,13 @@ discard block |
||
| 174 | 182 | */ |
| 175 | 183 | elseif (($pos = strpos ($line, ':')) !== false) |
| 176 | 184 | { |
| 177 | - if ($objects->size () == 0) |
|
| 178 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 185 | + if ($objects->size () == 0) { |
|
| 186 | + throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 187 | + } |
|
| 179 | 188 | |
| 180 | - if (!isset ($words[1])) |
|
| 181 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 189 | + if (!isset ($words[1])) { |
|
| 190 | + throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 191 | + } |
|
| 182 | 192 | |
| 183 | 193 | $propertyName = substr ($line, 0, $pos); |
| 184 | 194 | $propertyValue = substr ($line, $pos + 1); |
@@ -212,25 +222,27 @@ discard block |
||
| 212 | 222 | */ |
| 213 | 223 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
| 214 | 224 | { |
| 215 | - if ($objects->size () == 0) |
|
| 216 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 225 | + if ($objects->size () == 0) { |
|
| 226 | + throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 227 | + } |
|
| 217 | 228 | |
| 218 | 229 | $methodArgs = []; |
| 219 | 230 | |
| 220 | 231 | if (($pos = strpos ($line, '(')) !== false) |
| 221 | 232 | { |
| 222 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 223 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 233 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
| 234 | + throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 235 | + } |
|
| 224 | 236 | |
| 225 | 237 | $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
| 226 | 238 | |
| 227 | 239 | $methodName = trim (substr ($line, 2, $pos - 2)); |
| 228 | 240 | $methodArgs = self::filter ($methodArgs) ? |
| 229 | 241 | self::parseArguments ($methodArgs) : []; |
| 242 | + } else { |
|
| 243 | + $methodName = trim (substr ($line, 2)); |
|
| 230 | 244 | } |
| 231 | 245 | |
| 232 | - else $methodName = trim (substr ($line, 2)); |
|
| 233 | - |
|
| 234 | 246 | $objects->current ()->push (new Node ([ |
| 235 | 247 | 'type' => \VLF\METHOD_CALL, |
| 236 | 248 | 'line' => $line, |
@@ -247,7 +259,9 @@ discard block |
||
| 247 | 259 | /** |
| 248 | 260 | * Неопознанная структура |
| 249 | 261 | */ |
| 250 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 262 | + else { |
|
| 263 | + throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 264 | + } |
|
| 251 | 265 | } |
| 252 | 266 | |
| 253 | 267 | return $tree; |
@@ -36,22 +36,24 @@ |
||
| 36 | 36 | $name = $node->args['name']; |
| 37 | 37 | $nodes = $node->getNodes (); |
| 38 | 38 | |
| 39 | - if ($node->args['parents'] !== null) |
|
| 40 | - foreach ($node->args['parents'] as $parent) |
|
| 39 | + if ($node->args['parents'] !== null) { |
|
| 40 | + foreach ($node->args['parents'] as $parent) |
|
| 41 | 41 | if (!isset (self::$styles[$parent]) && !isset (self::$default_styles[$parent])) |
| 42 | 42 | { |
| 43 | 43 | if (self::$throw_errors) |
| 44 | 44 | throw new \Exception ('Style "'. $parent .'" not founded'); |
| 45 | + } |
|
| 46 | + } else { |
|
| 47 | + $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
| 45 | 48 | } |
| 46 | 49 | |
| 47 | - else $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
| 48 | - |
|
| 49 | - if ($node->args['is_default']) |
|
| 50 | - self::$default_styles[$name] = isset (self::$objects[$name]) ? |
|
| 50 | + if ($node->args['is_default']) { |
|
| 51 | + self::$default_styles[$name] = isset (self::$objects[$name]) ? |
|
| 51 | 52 | array_merge (self::$default_styles[$name], $nodes) : $nodes; |
| 52 | - |
|
| 53 | - else self::$styles[$name] = isset (self::$objects[$name]) ? |
|
| 53 | + } else { |
|
| 54 | + self::$styles[$name] = isset (self::$objects[$name]) ? |
|
| 54 | 55 | array_merge (self::$styles[$name], $nodes) : $nodes; |
| 56 | + } |
|
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | list (self::$styles, self::$default_styles) = self::run (new AST (array_map ( |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | $tree = new AST; |
| 23 | 23 | $objects = new Stack; |
| 24 | 24 | |
| 25 | - if (file_exists ($vlf)) |
|
| 26 | - $vlf = file_get_contents ($vlf); |
|
| 25 | + if (file_exists ($vlf)) { |
|
| 26 | + $vlf = file_get_contents ($vlf); |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $lines = explode (self::$divider, $vlf); |
| 29 | 30 | $skip_at = -1; |
@@ -32,24 +33,26 @@ discard block |
||
| 32 | 33 | { |
| 33 | 34 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
| 34 | 35 | |
| 35 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
| 36 | - continue; |
|
| 36 | + if ($skip_at > $line_num || !self::filter ($line)) { |
|
| 37 | + continue; |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | $height = self::getHeight ($line); |
| 39 | 41 | $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
| 40 | 42 | $poped = false; |
| 41 | 43 | |
| 42 | 44 | # Очищаем стек объектов |
| 43 | - while ($objects->size () > 0) |
|
| 44 | - if ($objects->current ()->height >= $height) |
|
| 45 | + while ($objects->size () > 0) { |
|
| 46 | + if ($objects->current ()->height >= $height) |
|
| 45 | 47 | { |
| 46 | 48 | $objects->pop (); |
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | $poped = true; |
| 52 | + } else { |
|
| 53 | + break; |
|
| 49 | 54 | } |
| 50 | 55 | |
| 51 | - else break; |
|
| 52 | - |
|
| 53 | 56 | # Создаём новую ссылку на объект |
| 54 | 57 | if ($poped && $objects->size () > 0) |
| 55 | 58 | { |
@@ -95,10 +98,11 @@ discard block |
||
| 95 | 98 | */ |
| 96 | 99 | if (isset ($words[0][1])) |
| 97 | 100 | { |
| 98 | - if ($words[0][1] == '^') |
|
| 99 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 100 | - |
|
| 101 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 101 | + if ($words[0][1] == '^') { |
|
| 102 | + $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 103 | + } else { |
|
| 104 | + throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 105 | + } |
|
| 102 | 106 | } |
| 103 | 107 | |
| 104 | 108 | continue; |
@@ -122,9 +126,9 @@ discard block |
||
| 122 | 126 | |
| 123 | 127 | $code .= $parsed[0]; |
| 124 | 128 | $skip_at = $parsed[1]; |
| 129 | + } else { |
|
| 130 | + throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
| 125 | 131 | } |
| 126 | - |
|
| 127 | - else throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
| 128 | 132 | } |
| 129 | 133 | |
| 130 | 134 | $tree->push (new Node ([ |
@@ -144,11 +148,13 @@ discard block |
||
| 144 | 148 | */ |
| 145 | 149 | elseif (($pos = strpos ($line, ':')) !== false) |
| 146 | 150 | { |
| 147 | - if ($objects->size () == 0) |
|
| 148 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 151 | + if ($objects->size () == 0) { |
|
| 152 | + throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 153 | + } |
|
| 149 | 154 | |
| 150 | - if (!isset ($words[1])) |
|
| 151 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 155 | + if (!isset ($words[1])) { |
|
| 156 | + throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 157 | + } |
|
| 152 | 158 | |
| 153 | 159 | $propertyName = substr ($line, 0, $pos); |
| 154 | 160 | $propertyValue = substr ($line, $pos + 1); |
@@ -182,25 +188,27 @@ discard block |
||
| 182 | 188 | */ |
| 183 | 189 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
| 184 | 190 | { |
| 185 | - if ($objects->size () == 0) |
|
| 186 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 191 | + if ($objects->size () == 0) { |
|
| 192 | + throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 193 | + } |
|
| 187 | 194 | |
| 188 | 195 | $methodArgs = []; |
| 189 | 196 | |
| 190 | 197 | if (($pos = strpos ($line, '(')) !== false) |
| 191 | 198 | { |
| 192 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 193 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 199 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
| 200 | + throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 201 | + } |
|
| 194 | 202 | |
| 195 | 203 | $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
| 196 | 204 | |
| 197 | 205 | $methodName = trim (substr ($line, 2, $pos - 2)); |
| 198 | 206 | $methodArgs = self::filter ($methodArgs) ? |
| 199 | 207 | self::parseArguments ($methodArgs) : []; |
| 208 | + } else { |
|
| 209 | + $methodName = trim (substr ($line, 2)); |
|
| 200 | 210 | } |
| 201 | 211 | |
| 202 | - else $methodName = trim (substr ($line, 2)); |
|
| 203 | - |
|
| 204 | 212 | $objects->current ()->push (new Node ([ |
| 205 | 213 | 'type' => METHOD_CALL, |
| 206 | 214 | 'line' => $line, |
@@ -224,13 +232,15 @@ discard block |
||
| 224 | 232 | $args = []; |
| 225 | 233 | $styles = []; |
| 226 | 234 | |
| 227 | - if ($objects->size () > 0 && $objects->current ()->height < $height) |
|
| 228 | - $args[] = $objects->current ()->args['name']; |
|
| 235 | + if ($objects->size () > 0 && $objects->current ()->height < $height) { |
|
| 236 | + $args[] = $objects->current ()->args['name']; |
|
| 237 | + } |
|
| 229 | 238 | |
| 230 | 239 | if (($pos = strpos ($line, '(')) !== false) |
| 231 | 240 | { |
| 232 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 233 | - throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
| 241 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
| 242 | + throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
| 243 | + } |
|
| 234 | 244 | |
| 235 | 245 | $args = substr ($line, $pos + 1, $end - $pos - 1); |
| 236 | 246 | |
@@ -243,8 +253,9 @@ discard block |
||
| 243 | 253 | { |
| 244 | 254 | $styles = trim (substr ($line, $end + 3)); |
| 245 | 255 | |
| 246 | - if (strlen ($styles) == 0) |
|
| 247 | - throw new \Exception ('Trying to set empty style to object'); |
|
| 256 | + if (strlen ($styles) == 0) { |
|
| 257 | + throw new \Exception ('Trying to set empty style to object'); |
|
| 258 | + } |
|
| 248 | 259 | |
| 249 | 260 | $styles = array_map ('trim', explode (',', $styles)); |
| 250 | 261 | } |
@@ -269,7 +280,9 @@ discard block |
||
| 269 | 280 | /** |
| 270 | 281 | * Неопознанная структура |
| 271 | 282 | */ |
| 272 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 283 | + else { |
|
| 284 | + throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 285 | + } |
|
| 273 | 286 | } |
| 274 | 287 | |
| 275 | 288 | return $tree; |
@@ -291,8 +304,9 @@ discard block |
||
| 291 | 304 | { |
| 292 | 305 | ++$height; |
| 293 | 306 | |
| 294 | - if ($line[$i] == "\t") |
|
| 295 | - $height += 3; |
|
| 307 | + if ($line[$i] == "\t") { |
|
| 308 | + $height += 3; |
|
| 309 | + } |
|
| 296 | 310 | |
| 297 | 311 | ++$i; |
| 298 | 312 | } |
@@ -329,8 +343,9 @@ discard block |
||
| 329 | 343 | |
| 330 | 344 | foreach ($lines as $line_id => $line) |
| 331 | 345 | { |
| 332 | - if ($line_id <= $begin_id) |
|
| 333 | - continue; |
|
| 346 | + if ($line_id <= $begin_id) { |
|
| 347 | + continue; |
|
| 348 | + } |
|
| 334 | 349 | |
| 335 | 350 | if (!self::filter ($line)) |
| 336 | 351 | { |
@@ -341,10 +356,11 @@ discard block |
||
| 341 | 356 | |
| 342 | 357 | $height = self::getHeight ($line); |
| 343 | 358 | |
| 344 | - if ($height > $down_height) |
|
| 345 | - $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
| 346 | - |
|
| 347 | - else return [$parsed, $line_id]; |
|
| 359 | + if ($height > $down_height) { |
|
| 360 | + $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
| 361 | + } else { |
|
| 362 | + return [$parsed, $line_id]; |
|
| 363 | + } |
|
| 348 | 364 | } |
| 349 | 365 | |
| 350 | 366 | return [$parsed, $line_id + 1]; |
@@ -370,18 +386,15 @@ discard block |
||
| 370 | 386 | { |
| 371 | 387 | $t .= $arguments[$i]; |
| 372 | 388 | |
| 373 | - if ($arguments[$i] == '\\') |
|
| 374 | - $canSplit = $i + 1; |
|
| 375 | - |
|
| 376 | - elseif ($canSplit < $i) |
|
| 389 | + if ($arguments[$i] == '\\') { |
|
| 390 | + $canSplit = $i + 1; |
|
| 391 | + } elseif ($canSplit < $i) |
|
| 377 | 392 | { |
| 378 | - if ($arguments[$i] == '\'' && !$split2) |
|
| 379 | - $split1 = !$split1; |
|
| 380 | - |
|
| 381 | - elseif ($arguments[$i] == '"' && !$split1) |
|
| 382 | - $split2 = !$split2; |
|
| 383 | - |
|
| 384 | - elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
|
| 393 | + if ($arguments[$i] == '\'' && !$split2) { |
|
| 394 | + $split1 = !$split1; |
|
| 395 | + } elseif ($arguments[$i] == '"' && !$split1) { |
|
| 396 | + $split2 = !$split2; |
|
| 397 | + } elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
|
| 385 | 398 | { |
| 386 | 399 | $args[] = substr ($t, 0, -1); |
| 387 | 400 | $t = ''; |
@@ -33,15 +33,17 @@ discard block |
||
| 33 | 33 | $name = $node->args['name']; |
| 34 | 34 | $args = []; |
| 35 | 35 | |
| 36 | - if (isset (self::$objects[$name])) |
|
| 37 | - break; |
|
| 36 | + if (isset (self::$objects[$name])) { |
|
| 37 | + break; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | if (isset ($node->args['args'])) |
| 40 | 41 | { |
| 41 | 42 | $args = $node->args['args']; |
| 42 | 43 | |
| 43 | - foreach ($args as $arg_id => $arg) |
|
| 44 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 44 | + foreach ($args as $arg_id => $arg) { |
|
| 45 | + $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | try |
@@ -51,15 +53,12 @@ discard block |
||
| 51 | 53 | try |
| 52 | 54 | { |
| 53 | 55 | self::$objects[$name]->name = $name; |
| 54 | - } |
|
| 55 | - |
|
| 56 | - catch (\Throwable $e) {} |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - catch (\Throwable $e) |
|
| 56 | + } catch (\Throwable $e) {} |
|
| 57 | + } catch (\Throwable $e) |
|
| 60 | 58 | { |
| 61 | - if (self::$throw_errors) |
|
| 62 | - throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 59 | + if (self::$throw_errors) { |
|
| 60 | + throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 61 | + } |
|
| 63 | 62 | } |
| 64 | 63 | break; |
| 65 | 64 | |
@@ -78,13 +77,15 @@ discard block |
||
| 78 | 77 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
| 79 | 78 | $use = explode (' ', $use); |
| 80 | 79 | |
| 81 | - foreach ($use as $id => $useParam) |
|
| 82 | - if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 80 | + foreach ($use as $id => $useParam) { |
|
| 81 | + if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 83 | 82 | { |
| 84 | 83 | $fname = $use[$id + 1]; |
| 84 | + } |
|
| 85 | 85 | |
| 86 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
| 87 | - $fname = substr ($fname, 0, -1); |
|
| 86 | + if (substr ($fname, strlen ($fname) - 1) == ',') { |
|
| 87 | + $fname = substr ($fname, 0, -1); |
|
| 88 | + } |
|
| 88 | 89 | |
| 89 | 90 | $preset .= "$fname = $useParam; "; |
| 90 | 91 | |
@@ -93,27 +94,26 @@ discard block |
||
| 93 | 94 | |
| 94 | 95 | $preset = self::formatLine ($preset, self::$objects); |
| 95 | 96 | $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
| 97 | + } else { |
|
| 98 | + $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 96 | 99 | } |
| 97 | 100 | |
| 98 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 99 | - |
|
| 100 | 101 | try |
| 101 | 102 | { |
| 102 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
| 103 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
| 104 | - |
|
| 105 | - else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - catch (\Throwable $e) |
|
| 103 | + if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) { |
|
| 104 | + eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
| 105 | + } else { |
|
| 106 | + self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
| 107 | + } |
|
| 108 | + } catch (\Throwable $e) |
|
| 109 | 109 | { |
| 110 | - if (self::$throw_errors) |
|
| 111 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 110 | + if (self::$throw_errors) { |
|
| 111 | + throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 112 | + } |
|
| 112 | 113 | } |
| 114 | + } elseif (self::$throw_errors) { |
|
| 115 | + throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 113 | 116 | } |
| 114 | - |
|
| 115 | - elseif (self::$throw_errors) |
|
| 116 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 117 | 117 | break; |
| 118 | 118 | |
| 119 | 119 | case METHOD_CALL: |
@@ -124,29 +124,28 @@ discard block |
||
| 124 | 124 | $methodName = $node->args['name']; |
| 125 | 125 | $methodArgs = $node->args['args']; |
| 126 | 126 | |
| 127 | - foreach ($methodArgs as $arg_id => $arg) |
|
| 128 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 127 | + foreach ($methodArgs as $arg_id => $arg) { |
|
| 128 | + $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 129 | + } |
|
| 129 | 130 | |
| 130 | 131 | try |
| 131 | 132 | { |
| 132 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
| 133 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 134 | - |
|
| 135 | - elseif (sizeof ($methodArgs) > 0) |
|
| 136 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 137 | - |
|
| 138 | - else self::$objects[$name]->$methodName (); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - catch (\Throwable $e) |
|
| 133 | + if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) { |
|
| 134 | + eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 135 | + } elseif (sizeof ($methodArgs) > 0) { |
|
| 136 | + self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 137 | + } else { |
|
| 138 | + self::$objects[$name]->$methodName (); |
|
| 139 | + } |
|
| 140 | + } catch (\Throwable $e) |
|
| 142 | 141 | { |
| 143 | - if (self::$throw_errors) |
|
| 144 | - throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 142 | + if (self::$throw_errors) { |
|
| 143 | + throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 144 | + } |
|
| 145 | 145 | } |
| 146 | + } elseif (self::$throw_errors) { |
|
| 147 | + throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 146 | 148 | } |
| 147 | - |
|
| 148 | - elseif (self::$throw_errors) |
|
| 149 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 150 | 149 | break; |
| 151 | 150 | |
| 152 | 151 | case STYLES_IMPORTING: |
@@ -156,11 +155,10 @@ discard block |
||
| 156 | 155 | |
| 157 | 156 | if (!file_exists ($path)) |
| 158 | 157 | { |
| 159 | - if (self::$throw_errors) |
|
| 160 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - elseif (!isset (self::$imported_styles[$path])) |
|
| 158 | + if (self::$throw_errors) { |
|
| 159 | + throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 160 | + } |
|
| 161 | + } elseif (!isset (self::$imported_styles[$path])) |
|
| 164 | 162 | { |
| 165 | 163 | \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
| 166 | 164 | |
@@ -178,16 +176,17 @@ discard block |
||
| 178 | 176 | |
| 179 | 177 | if ($node->type == OBJECT_DEFINITION) |
| 180 | 178 | { |
| 181 | - if (isset (\VLF\VST\Interpreter::$default_styles[$node->args['class']])) |
|
| 182 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
| 179 | + if (isset (\VLF\VST\Interpreter::$default_styles[$node->args['class']])) { |
|
| 180 | + $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
| 181 | + } |
|
| 183 | 182 | |
| 184 | - if (isset ($node->args['styles'])) |
|
| 185 | - foreach ($node->args['styles'] as $style) |
|
| 183 | + if (isset ($node->args['styles'])) { |
|
| 184 | + foreach ($node->args['styles'] as $style) |
|
| 186 | 185 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
| 187 | 186 | $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
| 188 | - |
|
| 189 | - elseif (self::$throw_errors) |
|
| 190 | - throw new \Exception ('Trying to set undefined style "'. $style .'" to object at line "'. $node->line .'"'); |
|
| 187 | + } elseif (self::$throw_errors) { |
|
| 188 | + throw new \Exception ('Trying to set undefined style "'. $style .'" to object at line "'. $node->line .'"'); |
|
| 189 | + } |
|
| 191 | 190 | } |
| 192 | 191 | |
| 193 | 192 | self::$objects = self::run (new AST (array_map ( |
@@ -228,8 +227,9 @@ discard block |
||
| 228 | 227 | |
| 229 | 228 | $nReplacement = []; |
| 230 | 229 | |
| 231 | - foreach ($replacement as $replaceTo => $nLn) |
|
| 232 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 230 | + foreach ($replacement as $replaceTo => $nLn) { |
|
| 231 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | $replacement = $nReplacement; |
| 235 | 235 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -238,10 +238,11 @@ discard block |
||
| 238 | 238 | { |
| 239 | 239 | $replaced = false; |
| 240 | 240 | |
| 241 | - foreach ($replacement as $name => $replaceAt) |
|
| 242 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 241 | + foreach ($replacement as $name => $replaceAt) { |
|
| 242 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 243 | 243 | { |
| 244 | 244 | $newLine .= $replaceAt; |
| 245 | + } |
|
| 245 | 246 | |
| 246 | 247 | $i += $l - 1; |
| 247 | 248 | $replaced = true; |
@@ -249,8 +250,9 @@ discard block |
||
| 249 | 250 | break; |
| 250 | 251 | } |
| 251 | 252 | |
| 252 | - if (!$replaced) |
|
| 253 | - $newLine .= $line[$i]; |
|
| 253 | + if (!$replaced) { |
|
| 254 | + $newLine .= $line[$i]; |
|
| 255 | + } |
|
| 254 | 256 | } |
| 255 | 257 | |
| 256 | 258 | $line = $newLine; |
@@ -12,16 +12,17 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function __construct ($name, $assembly = false, ...$args) |
| 14 | 14 | { |
| 15 | - foreach ($args as $id => $arg) |
|
| 16 | - $args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
| 15 | + foreach ($args as $id => $arg) { |
|
| 16 | + $args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
| 17 | + } |
|
| 17 | 18 | |
| 18 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
| 19 | - $this->selector = $name; |
|
| 20 | - |
|
| 21 | - elseif (is_string ($name)) |
|
| 22 | - $this->selector = VoidCore::createObject ($name, $assembly, ...$args); |
|
| 23 | - |
|
| 24 | - else throw new \Exception ('Incorrect params passed'); |
|
| 19 | + if (is_int ($name) && VoidCore::objectExists ($name)) { |
|
| 20 | + $this->selector = $name; |
|
| 21 | + } elseif (is_string ($name)) { |
|
| 22 | + $this->selector = VoidCore::createObject ($name, $assembly, ...$args); |
|
| 23 | + } else { |
|
| 24 | + throw new \Exception ('Incorrect params passed'); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | /*$this->isCollection = $this->getType () |
| 27 | 28 | ->isSubclassOf (VoidCore::typeof ('System.Collectons.Generic.ICollection'));*/ |
@@ -43,9 +44,7 @@ discard block |
||
| 43 | 44 | try |
| 44 | 45 | { |
| 45 | 46 | return $this->getProperty ('Count'); |
| 46 | - } |
|
| 47 | - |
|
| 48 | - catch (\WinformsException $e) |
|
| 47 | + } catch (\WinformsException $e) |
|
| 49 | 48 | { |
| 50 | 49 | return $this->getProperty ('Length'); |
| 51 | 50 | } |
@@ -55,8 +54,9 @@ discard block |
||
| 55 | 54 | $size = $this->count; |
| 56 | 55 | $list = []; |
| 57 | 56 | |
| 58 | - for ($i = 0; $i < $size; ++$i) |
|
| 59 | - $list[] = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $i)); |
|
| 57 | + for ($i = 0; $i < $size; ++$i) { |
|
| 58 | + $list[] = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $i)); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | return $list; |
| 62 | 62 | break; |
@@ -65,13 +65,12 @@ discard block |
||
| 65 | 65 | $size = $this->count; |
| 66 | 66 | $names = []; |
| 67 | 67 | |
| 68 | - for ($i = 0; $i < $size; ++$i) |
|
| 69 | - try |
|
| 68 | + for ($i = 0; $i < $size; ++$i) { |
|
| 69 | + try |
|
| 70 | 70 | { |
| 71 | 71 | $names[] = VoidCore::getProperty (VoidCore::getArrayValue ($this->selector, [$i, VC_OBJECT]), 'Text'); |
| 72 | - } |
|
| 73 | - |
|
| 74 | - catch (\WinformsException $e) |
|
| 72 | + } |
|
| 73 | + } catch (\WinformsException $e) |
|
| 75 | 74 | { |
| 76 | 75 | $names[] = VoidCore::getArrayValue ($this->selector, [$i, VC_STRING]); |
| 77 | 76 | } |
@@ -80,8 +79,9 @@ discard block |
||
| 80 | 79 | break; |
| 81 | 80 | } |
| 82 | 81 | |
| 83 | - if (method_exists ($this, $method = 'get_'. $name)) |
|
| 84 | - return $this->$method (); |
|
| 82 | + if (method_exists ($this, $method = 'get_'. $name)) { |
|
| 83 | + return $this->$method (); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | return isset ($this->$name) ? |
| 87 | 87 | $this->$name : EngineAdditions::coupleSelector ($this->getProperty ($name)); |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | public function __set (string $name, $value): void |
| 91 | 91 | { |
| 92 | - if (substr ($name, -5) == 'Event') |
|
| 93 | - Events::setEvent ($this->selector, substr ($name, 0, -5), $value); |
|
| 94 | - |
|
| 95 | - elseif (method_exists ($this, $method = 'set_'. $name)) |
|
| 96 | - $this->$method ($value); |
|
| 97 | - |
|
| 98 | - else $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
| 92 | + if (substr ($name, -5) == 'Event') { |
|
| 93 | + Events::setEvent ($this->selector, substr ($name, 0, -5), $value); |
|
| 94 | + } elseif (method_exists ($this, $method = 'set_'. $name)) { |
|
| 95 | + $this->$method ($value); |
|
| 96 | + } else { |
|
| 97 | + $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function __call (string $name, array $args) |
@@ -130,9 +130,7 @@ discard block |
||
| 130 | 130 | $index === null ? |
| 131 | 131 | $this->callMethod ('Add', EngineAdditions::uncoupleSelector ($value)) : |
| 132 | 132 | $this->callMethod ('Insert', $index, EngineAdditions::uncoupleSelector ($value)); |
| 133 | - } |
|
| 134 | - |
|
| 135 | - catch (\Throwable $e) |
|
| 133 | + } catch (\Throwable $e) |
|
| 136 | 134 | { |
| 137 | 135 | $index === null ? |
| 138 | 136 | VoidCore::setArrayValue ($this->selector, $this->count, EngineAdditions::uncoupleSelector ($value)) : |
@@ -155,9 +153,7 @@ discard block |
||
| 155 | 153 | try |
| 156 | 154 | { |
| 157 | 155 | $this->offsetGet ($index); |
| 158 | - } |
|
| 159 | - |
|
| 160 | - catch (\WinformsException $e) |
|
| 156 | + } catch (\WinformsException $e) |
|
| 161 | 157 | { |
| 162 | 158 | return false; |
| 163 | 159 | } |
@@ -171,8 +167,9 @@ discard block |
||
| 171 | 167 | { |
| 172 | 168 | $size = $this->count; |
| 173 | 169 | |
| 174 | - for ($i = 0; $i < $size; ++$i) |
|
| 175 | - $callback (EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
| 170 | + for ($i = 0; $i < $size; ++$i) { |
|
| 171 | + $callback (EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
| 172 | + } |
|
| 176 | 173 | } |
| 177 | 174 | |
| 178 | 175 | public function where (callable $comparator, string $type = null): array |
@@ -180,9 +177,10 @@ discard block |
||
| 180 | 177 | $size = $this->count; |
| 181 | 178 | $return = []; |
| 182 | 179 | |
| 183 | - for ($i = 0; $i < $size; ++$i) |
|
| 184 | - if ($comparator ($value = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
| 180 | + for ($i = 0; $i < $size; ++$i) { |
|
| 181 | + if ($comparator ($value = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
| 185 | 182 | $return[] = $value; |
| 183 | + } |
|
| 186 | 184 | |
| 187 | 185 | return $return; |
| 188 | 186 | } |
@@ -206,16 +204,12 @@ discard block |
||
| 206 | 204 | try |
| 207 | 205 | { |
| 208 | 206 | $info['name'] = $this->getProperty ('Name'); |
| 209 | - } |
|
| 210 | - |
|
| 211 | - catch (\WinformsException $e) {} |
|
| 207 | + } catch (\WinformsException $e) {} |
|
| 212 | 208 | |
| 213 | 209 | try |
| 214 | 210 | { |
| 215 | 211 | $info['info'] = $this->callMethod ('ToString'); |
| 216 | - } |
|
| 217 | - |
|
| 218 | - catch (\WinformsException $e) {} |
|
| 212 | + } catch (\WinformsException $e) {} |
|
| 219 | 213 | |
| 220 | 214 | return $info; |
| 221 | 215 | } |
@@ -225,13 +219,13 @@ discard block |
||
| 225 | 219 | { |
| 226 | 220 | public function __construct ($name, $assembly = false) |
| 227 | 221 | { |
| 228 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
| 229 | - $this->selector = $name; |
|
| 230 | - |
|
| 231 | - elseif (is_string ($name)) |
|
| 232 | - $this->selector = VoidCore::getClass ($name, $assembly); |
|
| 233 | - |
|
| 234 | - else throw new \Exception ('Incorrect params passed'); |
|
| 222 | + if (is_int ($name) && VoidCore::objectExists ($name)) { |
|
| 223 | + $this->selector = $name; |
|
| 224 | + } elseif (is_string ($name)) { |
|
| 225 | + $this->selector = VoidCore::getClass ($name, $assembly); |
|
| 226 | + } else { |
|
| 227 | + throw new \Exception ('Incorrect params passed'); |
|
| 228 | + } |
|
| 235 | 229 | } |
| 236 | 230 | } |
| 237 | 231 | |