@@ -5,18 +5,21 @@ |
||
| 5 | 5 | const CORE_DIR = __DIR__; |
| 6 | 6 | chdir (CORE_DIR); |
| 7 | 7 | |
| 8 | -foreach (glob ('ext/php_*.dll') as $ext) |
|
| 8 | +foreach (glob ('ext/php_*.dll') as $ext) { |
|
| 9 | 9 | if (!extension_loaded (substr (basename ($ext), 4, -4))) |
| 10 | 10 | load_extension ($ext); |
| 11 | +} |
|
| 11 | 12 | |
| 12 | -if (file_exists ('../engine/VoidEngine.php')) |
|
| 13 | +if (file_exists ('../engine/VoidEngine.php')) { |
|
| 13 | 14 | require '../engine/VoidEngine.php'; |
| 14 | - |
|
| 15 | -else message ('VoidEngine not founded'); |
|
| 15 | +} else { |
|
| 16 | + message ('VoidEngine not founded'); |
|
| 17 | +} |
|
| 16 | 18 | |
| 17 | 19 | $app = '../../app/start.php'; |
| 18 | 20 | |
| 19 | -if (file_exists ($app)) |
|
| 21 | +if (file_exists ($app)) { |
|
| 20 | 22 | require $app; |
| 21 | - |
|
| 22 | -else \VoidCore::callMethod (\VoidCore::createObject ('WinForms_PHP.DebugForm'), 'ShowDialog'); |
|
| 23 | +} else { |
|
| 24 | + \VoidCore::callMethod (\VoidCore::createObject ('WinForms_PHP.DebugForm'), 'ShowDialog'); |
|
| 25 | +} |
|
@@ -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 + 1)); |
| 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 = ''; |
@@ -31,15 +31,17 @@ discard block |
||
| 31 | 31 | $name = $node->args['name']; |
| 32 | 32 | $args = []; |
| 33 | 33 | |
| 34 | - if (isset (self::$objects[$name])) |
|
| 35 | - break; |
|
| 34 | + if (isset (self::$objects[$name])) { |
|
| 35 | + break; |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | if (isset ($node->args['args'])) |
| 38 | 39 | { |
| 39 | 40 | $args = $node->args['args']; |
| 40 | 41 | |
| 41 | - foreach ($args as $arg_id => $arg) |
|
| 42 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 42 | + foreach ($args as $arg_id => $arg) { |
|
| 43 | + $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | try |
@@ -49,15 +51,12 @@ discard block |
||
| 49 | 51 | try |
| 50 | 52 | { |
| 51 | 53 | self::$objects[$name]->name = $name; |
| 52 | - } |
|
| 53 | - |
|
| 54 | - catch (\Throwable $e) {} |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - catch (\Throwable $e) |
|
| 54 | + } catch (\Throwable $e) {} |
|
| 55 | + } catch (\Throwable $e) |
|
| 58 | 56 | { |
| 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); |
|
| 57 | + if (self::$throw_errors) { |
|
| 58 | + 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 | + } |
|
| 61 | 60 | } |
| 62 | 61 | break; |
| 63 | 62 | |
@@ -76,13 +75,15 @@ discard block |
||
| 76 | 75 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
| 77 | 76 | $use = explode (' ', $use); |
| 78 | 77 | |
| 79 | - foreach ($use as $id => $useParam) |
|
| 80 | - if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 78 | + foreach ($use as $id => $useParam) { |
|
| 79 | + if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 81 | 80 | { |
| 82 | 81 | $fname = $use[$id + 1]; |
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
| 85 | - $fname = substr ($fname, 0, -1); |
|
| 84 | + if (substr ($fname, strlen ($fname) - 1) == ',') { |
|
| 85 | + $fname = substr ($fname, 0, -1); |
|
| 86 | + } |
|
| 86 | 87 | |
| 87 | 88 | $preset .= "$fname = $useParam; "; |
| 88 | 89 | |
@@ -91,24 +92,22 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | $preset = self::formatLine ($preset, self::$objects); |
| 93 | 94 | $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
| 95 | + } else { |
|
| 96 | + $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 94 | 97 | } |
| 95 | 98 | |
| 96 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 97 | - |
|
| 98 | 99 | try |
| 99 | 100 | { |
| 100 | 101 | self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
| 101 | - } |
|
| 102 | - |
|
| 103 | - catch (\Throwable $e) |
|
| 102 | + } catch (\Throwable $e) |
|
| 104 | 103 | { |
| 105 | - if (self::$throw_errors) |
|
| 106 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 104 | + if (self::$throw_errors) { |
|
| 105 | + throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | + } elseif (self::$throw_errors) { |
|
| 109 | + throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 108 | 110 | } |
| 109 | - |
|
| 110 | - elseif (self::$throw_errors) |
|
| 111 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 112 | 111 | break; |
| 113 | 112 | |
| 114 | 113 | case METHOD_CALL: |
@@ -119,29 +118,28 @@ discard block |
||
| 119 | 118 | $methodName = $node->args['name']; |
| 120 | 119 | $methodArgs = $node->args['args']; |
| 121 | 120 | |
| 122 | - foreach ($methodArgs as $arg_id => $arg) |
|
| 123 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 121 | + foreach ($methodArgs as $arg_id => $arg) { |
|
| 122 | + $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | try |
| 126 | 126 | { |
| 127 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
| 128 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 129 | - |
|
| 130 | - elseif (sizeof ($methodArgs) > 0) |
|
| 131 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 132 | - |
|
| 133 | - else self::$objects[$name]->$methodName (); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - catch (\Throwable $e) |
|
| 127 | + if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) { |
|
| 128 | + eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 129 | + } elseif (sizeof ($methodArgs) > 0) { |
|
| 130 | + self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 131 | + } else { |
|
| 132 | + self::$objects[$name]->$methodName (); |
|
| 133 | + } |
|
| 134 | + } catch (\Throwable $e) |
|
| 137 | 135 | { |
| 138 | - if (self::$throw_errors) |
|
| 139 | - 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); |
|
| 136 | + if (self::$throw_errors) { |
|
| 137 | + 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); |
|
| 138 | + } |
|
| 140 | 139 | } |
| 140 | + } elseif (self::$throw_errors) { |
|
| 141 | + throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 141 | 142 | } |
| 142 | - |
|
| 143 | - elseif (self::$throw_errors) |
|
| 144 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 145 | 143 | break; |
| 146 | 144 | |
| 147 | 145 | case STYLES_IMPORTING: |
@@ -149,8 +147,9 @@ discard block |
||
| 149 | 147 | { |
| 150 | 148 | $path = eval ('namespace VoidEngine; return '. self::formatLine ($style, self::$objects) .';'); |
| 151 | 149 | |
| 152 | - if (!file_exists ($path)) |
|
| 153 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 150 | + if (!file_exists ($path)) { |
|
| 151 | + throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 152 | + } |
|
| 154 | 153 | |
| 155 | 154 | \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
| 156 | 155 | } |
@@ -163,12 +162,13 @@ discard block |
||
| 163 | 162 | |
| 164 | 163 | $nodes = $node->getNodes (); |
| 165 | 164 | |
| 166 | - if (isset ($node->args['styles'])) |
|
| 167 | - foreach ($node->args['styles'] as $style) |
|
| 165 | + if (isset ($node->args['styles'])) { |
|
| 166 | + foreach ($node->args['styles'] as $style) |
|
| 168 | 167 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
| 169 | 168 | $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
| 170 | - |
|
| 171 | - else throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
| 169 | + } else { |
|
| 170 | + throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | self::$objects = self::run (new AST (array_map ( |
| 174 | 174 | fn ($node) => $node->export (), $nodes)), $node); |
@@ -208,8 +208,9 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | $nReplacement = []; |
| 210 | 210 | |
| 211 | - foreach ($replacement as $replaceTo => $nLn) |
|
| 212 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 211 | + foreach ($replacement as $replaceTo => $nLn) { |
|
| 212 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 213 | + } |
|
| 213 | 214 | |
| 214 | 215 | $replacement = $nReplacement; |
| 215 | 216 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -218,10 +219,11 @@ discard block |
||
| 218 | 219 | { |
| 219 | 220 | $replaced = false; |
| 220 | 221 | |
| 221 | - foreach ($replacement as $name => $replaceAt) |
|
| 222 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 222 | + foreach ($replacement as $name => $replaceAt) { |
|
| 223 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 223 | 224 | { |
| 224 | 225 | $newLine .= $replaceAt; |
| 226 | + } |
|
| 225 | 227 | |
| 226 | 228 | $i += $l - 1; |
| 227 | 229 | $replaced = true; |
@@ -229,8 +231,9 @@ discard block |
||
| 229 | 231 | break; |
| 230 | 232 | } |
| 231 | 233 | |
| 232 | - if (!$replaced) |
|
| 233 | - $newLine .= $line[$i]; |
|
| 234 | + if (!$replaced) { |
|
| 235 | + $newLine .= $line[$i]; |
|
| 236 | + } |
|
| 234 | 237 | } |
| 235 | 238 | |
| 236 | 239 | $line = $newLine; |
@@ -9,8 +9,9 @@ discard block |
||
| 9 | 9 | $code = "<?php\n\nnamespace VoidEngine;\n\n"; |
| 10 | 10 | $definedObjects = []; |
| 11 | 11 | |
| 12 | - foreach ($tree->getNodes () as $node) |
|
| 13 | - $code .= self::translateNode ($node, null, $definedObjects) ."\n"; |
|
| 12 | + foreach ($tree->getNodes () as $node) { |
|
| 13 | + $code .= self::translateNode ($node, null, $definedObjects) ."\n"; |
|
| 14 | + } |
|
| 14 | 15 | |
| 15 | 16 | return $code; |
| 16 | 17 | } |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | break; |
| 28 | 29 | |
| 29 | 30 | case OBJECT_DEFINITION: |
| 30 | - if (isset ($definedObjects[$node->args['name']])) |
|
| 31 | - break; |
|
| 31 | + if (isset ($definedObjects[$node->args['name']])) { |
|
| 32 | + break; |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $code .= '$'. $node->args['name'] .' = new '. $node->args['class'] .' ('. implode (', ', self::processArgs ($node->args['args'], $definedObjects)) .');' ."\n". '$'. $node->args['name'] .'->name = \''. $node->args['name'] .'\';' ."\n"; |
| 34 | 36 | |
@@ -45,13 +47,15 @@ discard block |
||
| 45 | 47 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
| 46 | 48 | $use = explode (' ', $use); |
| 47 | 49 | |
| 48 | - foreach ($use as $id => $useParam) |
|
| 49 | - if (isset ($definedObjects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 50 | + foreach ($use as $id => $useParam) { |
|
| 51 | + if (isset ($definedObjects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 50 | 52 | { |
| 51 | 53 | $fname = $use[$id + 1]; |
| 54 | + } |
|
| 52 | 55 | |
| 53 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
| 54 | - $fname = substr ($fname, 0, -1); |
|
| 56 | + if (substr ($fname, strlen ($fname) - 1) == ',') { |
|
| 57 | + $fname = substr ($fname, 0, -1); |
|
| 58 | + } |
|
| 55 | 59 | |
| 56 | 60 | $preset .= "$fname = $useParam; "; |
| 57 | 61 | |
@@ -73,8 +77,9 @@ discard block |
||
| 73 | 77 | break; |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | - foreach ($node->getNodes () as $subnode) |
|
| 77 | - $code .= self::translateNode ($subnode, $node, $definedObjects); |
|
| 80 | + foreach ($node->getNodes () as $subnode) { |
|
| 81 | + $code .= self::translateNode ($subnode, $node, $definedObjects); |
|
| 82 | + } |
|
| 78 | 83 | |
| 79 | 84 | return $code; |
| 80 | 85 | } |
@@ -83,8 +88,9 @@ discard block |
||
| 83 | 88 | { |
| 84 | 89 | $newArgs = []; |
| 85 | 90 | |
| 86 | - foreach ($args as $arg) |
|
| 87 | - $newArgs[] = self::formatLine ($arg, $definedObjects); |
|
| 91 | + foreach ($args as $arg) { |
|
| 92 | + $newArgs[] = self::formatLine ($arg, $definedObjects); |
|
| 93 | + } |
|
| 88 | 94 | |
| 89 | 95 | return $newArgs; |
| 90 | 96 | } |
@@ -110,8 +116,9 @@ discard block |
||
| 110 | 116 | |
| 111 | 117 | $nReplacement = []; |
| 112 | 118 | |
| 113 | - foreach ($replacement as $replaceTo => $nLn) |
|
| 114 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 119 | + foreach ($replacement as $replaceTo => $nLn) { |
|
| 120 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 121 | + } |
|
| 115 | 122 | |
| 116 | 123 | $replacement = $nReplacement; |
| 117 | 124 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -120,10 +127,11 @@ discard block |
||
| 120 | 127 | { |
| 121 | 128 | $replaced = false; |
| 122 | 129 | |
| 123 | - foreach ($replacement as $name => $replaceAt) |
|
| 124 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 130 | + foreach ($replacement as $name => $replaceAt) { |
|
| 131 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 125 | 132 | { |
| 126 | 133 | $newLine .= $replaceAt; |
| 134 | + } |
|
| 127 | 135 | |
| 128 | 136 | $i += $l - 1; |
| 129 | 137 | $replaced = true; |
@@ -131,8 +139,9 @@ discard block |
||
| 131 | 139 | break; |
| 132 | 140 | } |
| 133 | 141 | |
| 134 | - if (!$replaced) |
|
| 135 | - $newLine .= $line[$i]; |
|
| 142 | + if (!$replaced) { |
|
| 143 | + $newLine .= $line[$i]; |
|
| 144 | + } |
|
| 136 | 145 | } |
| 137 | 146 | |
| 138 | 147 | $line = $newLine; |
@@ -22,8 +22,9 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | public function __construct (array $node = null) |
| 24 | 24 | { |
| 25 | - if ($node !== null) |
|
| 26 | - $this->import ($node); |
|
| 25 | + if ($node !== null) { |
|
| 26 | + $this->import ($node); |
|
| 27 | + } |
|
| 27 | 28 | } |
| 28 | 29 | |
| 29 | 30 | /** |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function __construct (array $tree = null) |
| 19 | 19 | { |
| 20 | - if ($tree !== null) |
|
| 21 | - $this->import ($tree); |
|
| 20 | + if ($tree !== null) { |
|
| 21 | + $this->import ($tree); |
|
| 22 | + } |
|
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | /** |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | */ |
| 31 | 32 | public function import (array $tree): AST |
| 32 | 33 | { |
| 33 | - foreach ($tree as $node) |
|
| 34 | - $this->nodes[] = new Node ($node); |
|
| 34 | + foreach ($tree as $node) { |
|
| 35 | + $this->nodes[] = new Node ($node); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | return $this; |
| 37 | 39 | } |
@@ -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, |
@@ -129,11 +135,13 @@ discard block |
||
| 129 | 135 | */ |
| 130 | 136 | elseif (($pos = strpos ($line, ':')) !== false) |
| 131 | 137 | { |
| 132 | - if ($objects->size () == 0) |
|
| 133 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 138 | + if ($objects->size () == 0) { |
|
| 139 | + throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 140 | + } |
|
| 134 | 141 | |
| 135 | - if (!isset ($words[1])) |
|
| 136 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 142 | + if (!isset ($words[1])) { |
|
| 143 | + throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 144 | + } |
|
| 137 | 145 | |
| 138 | 146 | $propertyName = substr ($line, 0, $pos); |
| 139 | 147 | $propertyValue = substr ($line, $pos + 1); |
@@ -167,25 +175,27 @@ discard block |
||
| 167 | 175 | */ |
| 168 | 176 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
| 169 | 177 | { |
| 170 | - if ($objects->size () == 0) |
|
| 171 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 178 | + if ($objects->size () == 0) { |
|
| 179 | + throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | 182 | $methodArgs = []; |
| 174 | 183 | |
| 175 | 184 | if (($pos = strpos ($line, '(')) !== false) |
| 176 | 185 | { |
| 177 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 178 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 186 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
| 187 | + throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 188 | + } |
|
| 179 | 189 | |
| 180 | 190 | $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
| 181 | 191 | |
| 182 | 192 | $methodName = trim (substr ($line, 2, $pos - 2)); |
| 183 | 193 | $methodArgs = self::filter ($methodArgs) ? |
| 184 | 194 | self::parseArguments ($methodArgs) : []; |
| 195 | + } else { |
|
| 196 | + $methodName = trim (substr ($line, 2)); |
|
| 185 | 197 | } |
| 186 | 198 | |
| 187 | - else $methodName = trim (substr ($line, 2)); |
|
| 188 | - |
|
| 189 | 199 | $objects->current ()->push (new Node ([ |
| 190 | 200 | 'type' => \VLF\METHOD_CALL, |
| 191 | 201 | 'line' => $line, |
@@ -202,7 +212,9 @@ discard block |
||
| 202 | 212 | /** |
| 203 | 213 | * Неопознанная структура |
| 204 | 214 | */ |
| 205 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 215 | + else { |
|
| 216 | + throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 217 | + } |
|
| 206 | 218 | } |
| 207 | 219 | |
| 208 | 220 | return $tree; |
@@ -35,11 +35,12 @@ |
||
| 35 | 35 | $name = $node->args['name']; |
| 36 | 36 | $nodes = $node->getNodes (); |
| 37 | 37 | |
| 38 | - if ($node->args['parents'] !== null) |
|
| 39 | - foreach ($node->args['parents'] as $parent) |
|
| 38 | + if ($node->args['parents'] !== null) { |
|
| 39 | + foreach ($node->args['parents'] as $parent) |
|
| 40 | 40 | { |
| 41 | 41 | if (!isset (self::$styles[$parent]) && self::$throw_errors) |
| 42 | 42 | throw new \Exception ('Style "'. $parent .'" not founded'); |
| 43 | + } |
|
| 43 | 44 | |
| 44 | 45 | $nodes = array_merge ($nodes, self::$styles[$parent]); |
| 45 | 46 | } |
@@ -48,10 +48,12 @@ |
||
| 48 | 48 | require 'components/Component.php'; |
| 49 | 49 | require 'components/Control.php'; |
| 50 | 50 | |
| 51 | -foreach (glob ('components/*/*.php') as $name) |
|
| 51 | +foreach (glob ('components/*/*.php') as $name) { |
|
| 52 | 52 | require $name; |
| 53 | +} |
|
| 53 | 54 | |
| 54 | -if (file_exists ('extensions')) |
|
| 55 | +if (file_exists ('extensions')) { |
|
| 55 | 56 | foreach (scandir ('extensions') as $ext) |
| 56 | 57 | if (file_exists ($ext = 'extensions/'. $ext .'/main.php')) |
| 57 | 58 | require $ext; |
| 59 | +} |
|