@@ -15,22 +15,22 @@ |
||
| 15 | 15 | # Объявление констант |
| 16 | 16 | const APP_DIR = __DIR__; |
| 17 | 17 | |
| 18 | -define ('VoidEngine\CORE_DIR', dirname (__DIR__) .'/qero-packages/winforms-php/VoidFramework/core'); |
|
| 18 | +define('VoidEngine\CORE_DIR', dirname(__DIR__).'/qero-packages/winforms-php/VoidFramework/core'); |
|
| 19 | 19 | |
| 20 | 20 | # Подгружаем PHP расширения |
| 21 | -foreach (glob (CORE_DIR .'/ext/php_*.dll') as $ext) |
|
| 22 | - if (!extension_loaded (substr (basename ($ext), 4, -4))) |
|
| 23 | - load_extension ($ext); |
|
| 21 | +foreach (glob(CORE_DIR.'/ext/php_*.dll') as $ext) |
|
| 22 | + if (!extension_loaded(substr(basename($ext), 4, -4))) |
|
| 23 | + load_extension($ext); |
|
| 24 | 24 | |
| 25 | 25 | # Подгружаем Qero-пакеты |
| 26 | -require __DIR__ .'/../qero-packages/autoload.php'; |
|
| 26 | +require __DIR__.'/../qero-packages/autoload.php'; |
|
| 27 | 27 | |
| 28 | -chdir (APP_DIR); // Меняем стандартную директорию на директорию приложения |
|
| 28 | +chdir(APP_DIR); // Меняем стандартную директорию на директорию приложения |
|
| 29 | 29 | |
| 30 | 30 | # Парсим стили main.vst |
| 31 | -VSTInterpreter::run (VSTParser::parse ('main.vst')); |
|
| 31 | +VSTInterpreter::run(VSTParser::parse('main.vst')); |
|
| 32 | 32 | |
| 33 | 33 | # Парсим разметку app.vlf и запускаем приложение |
| 34 | -$objects = VLFInterpreter::run (VLFParser::parse ('app.vlf')); |
|
| 34 | +$objects = VLFInterpreter::run(VLFParser::parse('app.vlf')); |
|
| 35 | 35 | |
| 36 | -$APPLICATION->run ($objects['MainForm']); |
|
| 36 | +$APPLICATION->run($objects['MainForm']); |
|
@@ -1,44 +1,44 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -echo ' Configuring VoidFramework...'. PHP_EOL; |
|
| 3 | +echo ' Configuring VoidFramework...'.PHP_EOL; |
|
| 4 | 4 | |
| 5 | -function dir_copy (string $from, string $to): bool |
|
| 5 | +function dir_copy(string $from, string $to): bool |
|
| 6 | 6 | { |
| 7 | - if (!is_dir ($from)) |
|
| 7 | + if (!is_dir($from)) |
|
| 8 | 8 | return false; |
| 9 | 9 | |
| 10 | - if (!is_dir ($to)) |
|
| 11 | - dir_create ($to); |
|
| 10 | + if (!is_dir($to)) |
|
| 11 | + dir_create($to); |
|
| 12 | 12 | |
| 13 | - foreach (array_slice (scandir ($from), 2) as $file) |
|
| 14 | - if (is_dir ($f = $from .'/'. $file)) |
|
| 15 | - dir_copy ($f, $to .'/'. $file); |
|
| 13 | + foreach (array_slice(scandir($from), 2) as $file) |
|
| 14 | + if (is_dir($f = $from.'/'.$file)) |
|
| 15 | + dir_copy($f, $to.'/'.$file); |
|
| 16 | 16 | |
| 17 | - else copy ($f, $to .'/'. $file); |
|
| 17 | + else copy($f, $to.'/'.$file); |
|
| 18 | 18 | |
| 19 | 19 | return true; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -$info = file_exists (QERO_DIR .'/qero-info.json') ? |
|
| 23 | - json_decode (file_get_contents (QERO_DIR .'/qero-info.json'), true) : array (); |
|
| 22 | +$info = file_exists(QERO_DIR.'/qero-info.json') ? |
|
| 23 | + json_decode (file_get_contents(QERO_DIR.'/qero-info.json'), true) : array(); |
|
| 24 | 24 | |
| 25 | 25 | $info['scripts']['start'] = '"qero-packages/winforms-php/VoidFramework/core/VoidCore.exe" "app/start.php"'; |
| 26 | 26 | |
| 27 | -file_put_contents (QERO_DIR .'/qero-info.json', json_encode ($info, defined ('JSON_PRETTY_PRINT') ? |
|
| 27 | +file_put_contents(QERO_DIR.'/qero-info.json', json_encode($info, defined('JSON_PRETTY_PRINT') ? |
|
| 28 | 28 | constant ('JSON_PRETTY_PRINT') : 0)); |
| 29 | -file_put_contents (QERO_DIR .'/start.bat', '@echo off |
|
| 29 | +file_put_contents(QERO_DIR.'/start.bat', '@echo off |
|
| 30 | 30 | '. $info['scripts']['start']); |
| 31 | 31 | |
| 32 | -if (!is_dir (QERO_DIR .'/app')) |
|
| 32 | +if (!is_dir(QERO_DIR.'/app')) |
|
| 33 | 33 | { |
| 34 | - echo ' Configuring application...'. PHP_EOL; |
|
| 34 | + echo ' Configuring application...'.PHP_EOL; |
|
| 35 | 35 | |
| 36 | - mkdir (QERO_DIR .'/app'); |
|
| 37 | - dir_copy (__DIR__ .'/app_bundle', QERO_DIR .'/app'); |
|
| 36 | + mkdir(QERO_DIR.'/app'); |
|
| 37 | + dir_copy(__DIR__.'/app_bundle', QERO_DIR.'/app'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | -Qero\dir_delete (__DIR__ .'/app_bundle'); |
|
| 41 | -unlink (__FILE__); |
|
| 40 | +Qero\dir_delete(__DIR__.'/app_bundle'); |
|
| 41 | +unlink(__FILE__); |
|
| 42 | 42 | |
| 43 | -echo ' Configuration completed'. PHP_EOL . |
|
| 44 | - ' Thank for installing winforms-php/VoidFramework!'. PHP_EOL . PHP_EOL; |
|
| 43 | +echo ' Configuration completed'.PHP_EOL. |
|
| 44 | + ' Thank for installing winforms-php/VoidFramework!'.PHP_EOL.PHP_EOL; |
|
@@ -6,17 +6,17 @@ |
||
| 6 | 6 | chdir (CORE_DIR); |
| 7 | 7 | |
| 8 | 8 | foreach (glob ('ext/php_*.dll') as $ext) |
| 9 | - if (!extension_loaded (substr (basename ($ext), 4, -4))) |
|
| 10 | - load_extension ($ext); |
|
| 9 | + if (!extension_loaded (substr (basename ($ext), 4, -4))) |
|
| 10 | + load_extension ($ext); |
|
| 11 | 11 | |
| 12 | 12 | if (file_exists ('../engine/VoidEngine.php')) |
| 13 | - require '../engine/VoidEngine.php'; |
|
| 13 | + require '../engine/VoidEngine.php'; |
|
| 14 | 14 | |
| 15 | 15 | else message ('VoidEngine not founded'); |
| 16 | 16 | |
| 17 | 17 | $app = '../../app/start.php'; |
| 18 | 18 | |
| 19 | 19 | if (file_exists ($app)) |
| 20 | - require $app; |
|
| 20 | + require $app; |
|
| 21 | 21 | |
| 22 | 22 | else \VoidCore::callMethod (\VoidCore::createObject ('WinForms_PHP.DebugForm'), 'ShowDialog'); |
@@ -3,20 +3,20 @@ |
||
| 3 | 3 | namespace VoidEngine; |
| 4 | 4 | |
| 5 | 5 | const CORE_DIR = __DIR__; |
| 6 | -chdir (CORE_DIR); |
|
| 6 | +chdir(CORE_DIR); |
|
| 7 | 7 | |
| 8 | -foreach (glob ('ext/php_*.dll') as $ext) |
|
| 9 | - if (!extension_loaded (substr (basename ($ext), 4, -4))) |
|
| 10 | - load_extension ($ext); |
|
| 8 | +foreach (glob('ext/php_*.dll') as $ext) |
|
| 9 | + if (!extension_loaded(substr(basename($ext), 4, -4))) |
|
| 10 | + load_extension($ext); |
|
| 11 | 11 | |
| 12 | -if (file_exists ('../engine/VoidEngine.php')) |
|
| 12 | +if (file_exists('../engine/VoidEngine.php')) |
|
| 13 | 13 | require '../engine/VoidEngine.php'; |
| 14 | 14 | |
| 15 | -else message ('VoidEngine not founded'); |
|
| 15 | +else message('VoidEngine not founded'); |
|
| 16 | 16 | |
| 17 | 17 | $app = '../../app/start.php'; |
| 18 | 18 | |
| 19 | -if (file_exists ($app)) |
|
| 19 | +if (file_exists($app)) |
|
| 20 | 20 | require $app; |
| 21 | 21 | |
| 22 | -else \VoidCore::callMethod (\VoidCore::createObject ('WinForms_PHP.DebugForm'), 'ShowDialog'); |
|
| 22 | +else \VoidCore::callMethod(\VoidCore::createObject('WinForms_PHP.DebugForm'), 'ShowDialog'); |
|
@@ -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 | +} |
|
@@ -17,33 +17,33 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return AST - возвращает AST дерево разметки |
| 19 | 19 | */ |
| 20 | - public static function parse (string $vlf): AST |
|
| 20 | + public static function parse(string $vlf): AST |
|
| 21 | 21 | { |
| 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 | - $lines = explode (self::$divider, $vlf); |
|
| 28 | + $lines = explode(self::$divider, $vlf); |
|
| 29 | 29 | $skip_at = -1; |
| 30 | 30 | |
| 31 | 31 | foreach ($lines as $line_num => $line) |
| 32 | 32 | { |
| 33 | 33 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
| 34 | 34 | |
| 35 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
| 35 | + if ($skip_at > $line_num || !self::filter($line)) |
|
| 36 | 36 | continue; |
| 37 | 37 | |
| 38 | - $height = self::getHeight ($line); |
|
| 39 | - $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
|
| 38 | + $height = self::getHeight($line); |
|
| 39 | + $words = array_filter(explode(' ', $line), 'VLF\Parser::filter'); |
|
| 40 | 40 | $poped = false; |
| 41 | 41 | |
| 42 | 42 | # Очищаем стек объектов |
| 43 | - while ($objects->size () > 0) |
|
| 44 | - if ($objects->current ()->height >= $height) |
|
| 43 | + while ($objects->size() > 0) |
|
| 44 | + if ($objects->current()->height >= $height) |
|
| 45 | 45 | { |
| 46 | - $objects->pop (); |
|
| 46 | + $objects->pop(); |
|
| 47 | 47 | |
| 48 | 48 | $poped = true; |
| 49 | 49 | } |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | else break; |
| 52 | 52 | |
| 53 | 53 | # Создаём новую ссылку на объект |
| 54 | - if ($poped && $objects->size () > 0) |
|
| 54 | + if ($poped && $objects->size() > 0) |
|
| 55 | 55 | { |
| 56 | - $object = $objects->pop (); |
|
| 56 | + $object = $objects->pop(); |
|
| 57 | 57 | |
| 58 | - $objects->push (new Node (array_merge ($object->export (), ['nodes' => []]))); |
|
| 59 | - $tree->push ($objects->current ()); |
|
| 58 | + $objects->push(new Node(array_merge($object->export(), ['nodes' => []]))); |
|
| 59 | + $tree->push($objects->current()); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -64,16 +64,16 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | if ($words[0] == 'import') |
| 66 | 66 | { |
| 67 | - $imports = substr ($line, strlen ($words[0])); |
|
| 68 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
| 67 | + $imports = substr($line, strlen($words[0])); |
|
| 68 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
| 69 | 69 | |
| 70 | 70 | $imports .= $parsed[0]; |
| 71 | 71 | $skip_at = $parsed[1]; |
| 72 | 72 | |
| 73 | - $imports = self::filter ($imports) ? |
|
| 74 | - array_map ('trim', self::parseArguments ($imports)) : []; |
|
| 73 | + $imports = self::filter($imports) ? |
|
| 74 | + array_map ('trim', self::parseArguments($imports)) : []; |
|
| 75 | 75 | |
| 76 | - $tree->push (new Node ([ |
|
| 76 | + $tree->push(new Node([ |
|
| 77 | 77 | 'type' => STYLES_IMPORTING, |
| 78 | 78 | 'line' => $line, |
| 79 | 79 | 'words' => $words, |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | if (isset ($words[0][1])) |
| 97 | 97 | { |
| 98 | 98 | if ($words[0][1] == '^') |
| 99 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 99 | + $skip_at = self::parseSubtext($lines, $line_num, $height)[1]; |
|
| 100 | 100 | |
| 101 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 101 | + else throw new \Exception('Unknown char founded after comment definition at line '.($line_num + 1)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | continue; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | elseif ($words[0][0] == '%') |
| 111 | 111 | { |
| 112 | - $code = substr ($line, strlen ($words[0])); |
|
| 112 | + $code = substr($line, strlen($words[0])); |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * Обработка многострочного кода |
@@ -118,16 +118,16 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | if ($words[0][1] == '^') |
| 120 | 120 | { |
| 121 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
| 121 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
| 122 | 122 | |
| 123 | 123 | $code .= $parsed[0]; |
| 124 | 124 | $skip_at = $parsed[1]; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - else throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
| 127 | + else throw new \Exception('Unknown char founded after runtime execution definition at line '.($line_num + 1)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $tree->push (new Node ([ |
|
| 130 | + $tree->push(new Node([ |
|
| 131 | 131 | 'type' => RUNTIME_EXECUTION, |
| 132 | 132 | 'line' => $line, |
| 133 | 133 | 'words' => $words, |
@@ -142,29 +142,29 @@ discard block |
||
| 142 | 142 | /** |
| 143 | 143 | * Установка свойства |
| 144 | 144 | */ |
| 145 | - elseif (($pos = strpos ($line, ':')) !== false) |
|
| 145 | + elseif (($pos = strpos($line, ':')) !== false) |
|
| 146 | 146 | { |
| 147 | - if ($objects->size () == 0) |
|
| 148 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 147 | + if ($objects->size() == 0) |
|
| 148 | + throw new \Exception('Trying to set property to unknown object at line '.($line_num + 1)); |
|
| 149 | 149 | |
| 150 | 150 | if (!isset ($words[1])) |
| 151 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 151 | + throw new \Exception('Trying to set void property value at line '.($line_num + 1)); |
|
| 152 | 152 | |
| 153 | - $propertyName = substr ($line, 0, $pos); |
|
| 154 | - $propertyValue = substr ($line, $pos + 1); |
|
| 153 | + $propertyName = substr($line, 0, $pos); |
|
| 154 | + $propertyValue = substr($line, $pos + 1); |
|
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | 157 | * Обработка многострочных свойств |
| 158 | 158 | */ |
| 159 | 159 | if ($line[$pos + 1] == '^') |
| 160 | 160 | { |
| 161 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
| 161 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
| 162 | 162 | |
| 163 | - $propertyValue = substr ($propertyValue, 1) . $parsed[0]; |
|
| 163 | + $propertyValue = substr($propertyValue, 1).$parsed[0]; |
|
| 164 | 164 | $skip_at = $parsed[1]; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $objects->current ()->push (new Node ([ |
|
| 167 | + $objects->current()->push(new Node([ |
|
| 168 | 168 | 'type' => PROPERTY_SET, |
| 169 | 169 | 'line' => $line, |
| 170 | 170 | 'words' => $words, |
@@ -182,26 +182,26 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
| 184 | 184 | { |
| 185 | - if ($objects->size () == 0) |
|
| 186 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 185 | + if ($objects->size() == 0) |
|
| 186 | + throw new \Exception('Trying to call method from unknown object at line '.($line_num + 1)); |
|
| 187 | 187 | |
| 188 | 188 | $methodArgs = []; |
| 189 | 189 | |
| 190 | - if (($pos = strpos ($line, '(')) !== false) |
|
| 190 | + if (($pos = strpos($line, '(')) !== false) |
|
| 191 | 191 | { |
| 192 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 193 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 192 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
| 193 | + throw new \Exception('Incorrect method arguments syntax at line '.($line_num + 1)); |
|
| 194 | 194 | |
| 195 | - $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
|
| 195 | + $methodArgs = substr($line, $pos + 1, $end - $pos - 1); |
|
| 196 | 196 | |
| 197 | - $methodName = trim (substr ($line, 2, $pos - 2)); |
|
| 198 | - $methodArgs = self::filter ($methodArgs) ? |
|
| 199 | - self::parseArguments ($methodArgs) : []; |
|
| 197 | + $methodName = trim(substr($line, 2, $pos - 2)); |
|
| 198 | + $methodArgs = self::filter($methodArgs) ? |
|
| 199 | + self::parseArguments($methodArgs) : []; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - else $methodName = trim (substr ($line, 2)); |
|
| 202 | + else $methodName = trim(substr($line, 2)); |
|
| 203 | 203 | |
| 204 | - $objects->current ()->push (new Node ([ |
|
| 204 | + $objects->current()->push(new Node([ |
|
| 205 | 205 | 'type' => METHOD_CALL, |
| 206 | 206 | 'line' => $line, |
| 207 | 207 | 'words' => $words, |
@@ -217,39 +217,39 @@ discard block |
||
| 217 | 217 | /** |
| 218 | 218 | * Объявление объекта |
| 219 | 219 | */ |
| 220 | - elseif (sizeof ($words) > 1) |
|
| 220 | + elseif (sizeof($words) > 1) |
|
| 221 | 221 | { |
| 222 | 222 | $class = $words[0]; |
| 223 | 223 | $name = $words[1]; |
| 224 | 224 | $args = []; |
| 225 | 225 | $styles = []; |
| 226 | 226 | |
| 227 | - if ($objects->size () > 0 && $objects->current ()->height < $height) |
|
| 228 | - $args[] = $objects->current ()->args['name']; |
|
| 227 | + if ($objects->size() > 0 && $objects->current()->height < $height) |
|
| 228 | + $args[] = $objects->current()->args['name']; |
|
| 229 | 229 | |
| 230 | - if (($pos = strpos ($line, '(')) !== false) |
|
| 230 | + if (($pos = strpos($line, '(')) !== false) |
|
| 231 | 231 | { |
| 232 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 233 | - throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
| 232 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
| 233 | + throw new \Exception('Incorrect class constructor arguments syntax at line '.($line_num + 1)); |
|
| 234 | 234 | |
| 235 | - $args = substr ($line, $pos + 1, $end - $pos - 1); |
|
| 235 | + $args = substr($line, $pos + 1, $end - $pos - 1); |
|
| 236 | 236 | |
| 237 | - $name = substr ($line, $len = strlen ($class), $pos - $len); |
|
| 238 | - $args = self::filter ($args) ? |
|
| 239 | - self::parseArguments ($args) : []; |
|
| 237 | + $name = substr($line, $len = strlen($class), $pos - $len); |
|
| 238 | + $args = self::filter($args) ? |
|
| 239 | + self::parseArguments($args) : []; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if (($end = strpos ($line, '>')) !== false) |
|
| 242 | + if (($end = strpos($line, '>')) !== false) |
|
| 243 | 243 | { |
| 244 | - $styles = trim (substr ($line, $end + 1)); |
|
| 244 | + $styles = trim(substr($line, $end + 1)); |
|
| 245 | 245 | |
| 246 | - if (strlen ($styles) == 0) |
|
| 247 | - throw new \Exception ('Trying to set empty style to object'); |
|
| 246 | + if (strlen($styles) == 0) |
|
| 247 | + throw new \Exception('Trying to set empty style to object'); |
|
| 248 | 248 | |
| 249 | - $styles = array_map ('trim', explode (',', $styles)); |
|
| 249 | + $styles = array_map('trim', explode(',', $styles)); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $objects->push (new Node ([ |
|
| 252 | + $objects->push(new Node([ |
|
| 253 | 253 | 'type' => OBJECT_DEFINITION, |
| 254 | 254 | 'line' => $line, |
| 255 | 255 | 'words' => $words, |
@@ -257,19 +257,19 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | 'args' => [ |
| 259 | 259 | 'class' => $class, |
| 260 | - 'name' => trim ($name), |
|
| 260 | + 'name' => trim($name), |
|
| 261 | 261 | 'args' => $args, |
| 262 | 262 | 'styles' => $styles |
| 263 | 263 | ] |
| 264 | 264 | ])); |
| 265 | 265 | |
| 266 | - $tree->push ($objects->current ()); |
|
| 266 | + $tree->push($objects->current()); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Неопознанная структура |
| 271 | 271 | */ |
| 272 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 272 | + else throw new \Exception('Unsupported structure founded at line '.($line_num + 1)); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | return $tree; |
@@ -282,12 +282,12 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return int - возвращает её высоту |
| 284 | 284 | */ |
| 285 | - protected static function getHeight (string &$line): int |
|
| 285 | + protected static function getHeight(string &$line): int |
|
| 286 | 286 | { |
| 287 | 287 | $i = 0; |
| 288 | 288 | $height = 0; |
| 289 | 289 | |
| 290 | - while (isset ($line[$i]) && ctype_space ($line[$i])) |
|
| 290 | + while (isset ($line[$i]) && ctype_space($line[$i])) |
|
| 291 | 291 | { |
| 292 | 292 | ++$height; |
| 293 | 293 | |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | ++$i; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - $line = substr ($line, $i); |
|
| 300 | + $line = substr($line, $i); |
|
| 301 | 301 | |
| 302 | 302 | return $height; |
| 303 | 303 | } |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @return bool - возвращает true если строка не пустая |
| 311 | 311 | */ |
| 312 | - protected static function filter (string $line): bool |
|
| 312 | + protected static function filter(string $line): bool |
|
| 313 | 313 | { |
| 314 | - return strlen (trim ($line)) > 0; |
|
| 314 | + return strlen(trim($line)) > 0; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * |
| 324 | 324 | * @return array - возвращает массив [текст, конечный индекс] |
| 325 | 325 | */ |
| 326 | - protected static function parseSubtext (array $lines, $begin_id, int $down_height): array |
|
| 326 | + protected static function parseSubtext(array $lines, $begin_id, int $down_height): array |
|
| 327 | 327 | { |
| 328 | 328 | $parsed = "\n"; |
| 329 | 329 | |
@@ -332,17 +332,17 @@ discard block |
||
| 332 | 332 | if ($line_id <= $begin_id) |
| 333 | 333 | continue; |
| 334 | 334 | |
| 335 | - if (!self::filter ($line)) |
|
| 335 | + if (!self::filter($line)) |
|
| 336 | 336 | { |
| 337 | 337 | $parsed .= "\n"; |
| 338 | 338 | |
| 339 | 339 | continue; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - $height = self::getHeight ($line); |
|
| 342 | + $height = self::getHeight($line); |
|
| 343 | 343 | |
| 344 | 344 | if ($height > $down_height) |
| 345 | - $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
| 345 | + $parsed .= str_repeat(' ', $height - $down_height)."$line\n"; |
|
| 346 | 346 | |
| 347 | 347 | else return [$parsed, $line_id]; |
| 348 | 348 | } |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | * |
| 358 | 358 | * @return array - возвращает массив аргументов |
| 359 | 359 | */ |
| 360 | - protected static function parseArguments (string $arguments): array |
|
| 360 | + protected static function parseArguments(string $arguments): array |
|
| 361 | 361 | { |
| 362 | 362 | $args = []; |
| 363 | 363 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | $t = ''; |
| 368 | 368 | |
| 369 | - for ($i = 0, $len = strlen ($arguments); $i < $len; ++$i) |
|
| 369 | + for ($i = 0, $len = strlen($arguments); $i < $len; ++$i) |
|
| 370 | 370 | { |
| 371 | 371 | $t .= $arguments[$i]; |
| 372 | 372 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | |
| 384 | 384 | elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
| 385 | 385 | { |
| 386 | - $args[] = substr ($t, 0, -1); |
|
| 386 | + $args[] = substr($t, 0, -1); |
|
| 387 | 387 | $t = ''; |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -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 = ''; |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return array - возвращает список созданных объектов |
| 22 | 22 | */ |
| 23 | - public static function run (AST $tree, Node $parent = null): array |
|
| 23 | + public static function run(AST $tree, Node $parent = null): array |
|
| 24 | 24 | { |
| 25 | - foreach ($tree->getNodes () as $id => $node) |
|
| 25 | + foreach ($tree->getNodes() as $id => $node) |
|
| 26 | 26 | { |
| 27 | 27 | switch ($node->type) |
| 28 | 28 | { |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | $args = $node->args['args']; |
| 40 | 40 | |
| 41 | 41 | foreach ($args as $arg_id => $arg) |
| 42 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 42 | + $args[$arg_id] = self::formatLine($arg, self::$objects); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | try |
| 46 | 46 | { |
| 47 | - self::$objects[$name] = eval ("namespace VoidEngine; return new $class (". implode (', ', $args) .");"); |
|
| 47 | + self::$objects[$name] = eval ("namespace VoidEngine; return new $class (".implode(', ', $args).");"); |
|
| 48 | 48 | |
| 49 | 49 | try |
| 50 | 50 | { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | catch (\Throwable $e) |
| 58 | 58 | { |
| 59 | 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); |
|
| 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 | 61 | } |
| 62 | 62 | break; |
| 63 | 63 | |
@@ -70,30 +70,30 @@ discard block |
||
| 70 | 70 | $propertyValue = $node->args['value']; |
| 71 | 71 | $preset = ''; |
| 72 | 72 | |
| 73 | - if (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
| 73 | + if (preg_match('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
| 74 | 74 | { |
| 75 | - $use = substr ($propertyValue, strpos ($propertyValue, 'use')); |
|
| 76 | - $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
|
| 77 | - $use = explode (' ', $use); |
|
| 75 | + $use = substr($propertyValue, strpos($propertyValue, 'use')); |
|
| 76 | + $use = $ouse = substr($use, ($pos = strpos($use, '(') + 1), strpos($use, ')') - $pos); |
|
| 77 | + $use = explode(' ', $use); |
|
| 78 | 78 | |
| 79 | 79 | foreach ($use as $id => $useParam) |
| 80 | 80 | if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
| 81 | 81 | { |
| 82 | 82 | $fname = $use[$id + 1]; |
| 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 | $preset .= "$fname = $useParam; "; |
| 88 | 88 | |
| 89 | 89 | unset ($use[$id]); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $preset = self::formatLine ($preset, self::$objects); |
|
| 93 | - $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
|
| 92 | + $preset = self::formatLine($preset, self::$objects); |
|
| 93 | + $propertyValue = self::formatLine(str_replace($ouse, implode(' ', $use), $propertyValue), self::$objects); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 96 | + else $propertyValue = self::formatLine($propertyValue, self::$objects); |
|
| 97 | 97 | |
| 98 | 98 | try |
| 99 | 99 | { |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | catch (\Throwable $e) |
| 104 | 104 | { |
| 105 | 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); |
|
| 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); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | elseif (self::$throw_errors) |
| 111 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 111 | + throw new \Exception('Setting property to an non-object at line "'.$node->line); |
|
| 112 | 112 | break; |
| 113 | 113 | |
| 114 | 114 | case METHOD_CALL: |
@@ -120,58 +120,58 @@ discard block |
||
| 120 | 120 | $methodArgs = $node->args['args']; |
| 121 | 121 | |
| 122 | 122 | foreach ($methodArgs as $arg_id => $arg) |
| 123 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 123 | + $methodArgs[$arg_id] = self::formatLine($arg, self::$objects); |
|
| 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) .');'); |
|
| 127 | + if (strpos($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
| 128 | + eval ('namespace VoidEngine; _c('.self::$objects[$name]->selector.')->'.$methodName.' ('.implode(', ', $methodArgs).');'); |
|
| 129 | 129 | |
| 130 | - elseif (sizeof ($methodArgs) > 0) |
|
| 131 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 130 | + elseif (sizeof($methodArgs) > 0) |
|
| 131 | + self::$objects[$name]->$methodName(...eval ('namespace VoidEngine; return ['.implode(', ', $methodArgs).'];')); |
|
| 132 | 132 | |
| 133 | - else self::$objects[$name]->$methodName (); |
|
| 133 | + else self::$objects[$name]->$methodName(); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | catch (\Throwable $e) |
| 137 | 137 | { |
| 138 | 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); |
|
| 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); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | elseif (self::$throw_errors) |
| 144 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 144 | + throw new \Exception('Calling method to an non-object at line "'.$node->line.'"'); |
|
| 145 | 145 | break; |
| 146 | 146 | |
| 147 | 147 | case STYLES_IMPORTING: |
| 148 | 148 | foreach ($node->args['imports'] as $style) |
| 149 | 149 | { |
| 150 | - $path = eval ('namespace VoidEngine; return '. self::formatLine ($style, self::$objects) .';'); |
|
| 150 | + $path = eval ('namespace VoidEngine; return '.self::formatLine($style, self::$objects).';'); |
|
| 151 | 151 | |
| 152 | - if (!file_exists ($path)) |
|
| 153 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 152 | + if (!file_exists($path)) |
|
| 153 | + throw new \Exception('Trying to import nonexistent style at line "'.$node->line.'"'); |
|
| 154 | 154 | |
| 155 | - \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
|
| 155 | + \VLF\VST\Interpreter::run(\VLF\VST\Parser::parse(file_get_contents($path))); |
|
| 156 | 156 | } |
| 157 | 157 | break; |
| 158 | 158 | |
| 159 | 159 | case RUNTIME_EXECUTION: |
| 160 | - eval (self::formatLine ($node->args['code'], self::$objects)); |
|
| 160 | + eval (self::formatLine($node->args['code'], self::$objects)); |
|
| 161 | 161 | break; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $nodes = $node->getNodes (); |
|
| 164 | + $nodes = $node->getNodes(); |
|
| 165 | 165 | |
| 166 | 166 | if (isset ($node->args['styles'])) |
| 167 | 167 | foreach ($node->args['styles'] as $style) |
| 168 | 168 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
| 169 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
| 169 | + $nodes = array_merge($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
| 170 | 170 | |
| 171 | - else throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
| 171 | + else throw new \Exception('Trying to set undefined style to object at line "'.$node->line.'"'); |
|
| 172 | 172 | |
| 173 | - self::$objects = self::run (new AST (array_map ( |
|
| 174 | - fn ($node) => $node->export (), $nodes)), $node); |
|
| 173 | + self::$objects = self::run(new AST(array_map( |
|
| 174 | + fn($node) => $node->export(), $nodes)), $node); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return self::$objects; |
@@ -185,26 +185,25 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return string - возвращает форматированную строку |
| 187 | 187 | */ |
| 188 | - public static function formatLine (string $line, array $objects = []): string |
|
| 188 | + public static function formatLine(string $line, array $objects = []): string |
|
| 189 | 189 | { |
| 190 | - if (sizeof ($objects) > 0) |
|
| 190 | + if (sizeof($objects) > 0) |
|
| 191 | 191 | { |
| 192 | - $len = strlen ($line); |
|
| 192 | + $len = strlen($line); |
|
| 193 | 193 | $newLine = ''; |
| 194 | 194 | |
| 195 | - $replacement = array_map (function ($object) |
|
| 195 | + $replacement = array_map(function($object) |
|
| 196 | 196 | { |
| 197 | - return \VoidEngine\Components::exists ($object->selector) !== false ? |
|
| 198 | - '\VoidEngine\_c('. $object->selector .')' : |
|
| 199 | - 'unserialize (\''. serialize ($object) .'\')'; |
|
| 197 | + return \VoidEngine\Components::exists($object->selector) !== false ? |
|
| 198 | + '\VoidEngine\_c('.$object->selector.')' : 'unserialize (\''.serialize($object).'\')'; |
|
| 200 | 199 | }, $objects); |
| 201 | 200 | |
| 202 | - $replacement = array_map (function ($name) |
|
| 201 | + $replacement = array_map(function($name) |
|
| 203 | 202 | { |
| 204 | - return strlen ($name = trim ($name)) + substr_count ($name, '_'); |
|
| 205 | - }, $omap = array_flip ($replacement)); |
|
| 203 | + return strlen($name = trim($name)) + substr_count($name, '_'); |
|
| 204 | + }, $omap = array_flip($replacement)); |
|
| 206 | 205 | |
| 207 | - arsort ($replacement); |
|
| 206 | + arsort($replacement); |
|
| 208 | 207 | |
| 209 | 208 | $nReplacement = []; |
| 210 | 209 | |
@@ -212,14 +211,14 @@ discard block |
||
| 212 | 211 | $nReplacement[$omap[$replaceTo]] = $replaceTo; |
| 213 | 212 | |
| 214 | 213 | $replacement = $nReplacement; |
| 215 | - $blacklist = array_flip (['\'', '"', '$']); |
|
| 214 | + $blacklist = array_flip(['\'', '"', '$']); |
|
| 216 | 215 | |
| 217 | 216 | for ($i = 0; $i < $len; ++$i) |
| 218 | 217 | { |
| 219 | 218 | $replaced = false; |
| 220 | 219 | |
| 221 | 220 | foreach ($replacement as $name => $replaceAt) |
| 222 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 221 | + if (substr($line, $i, ($l = strlen($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 223 | 222 | { |
| 224 | 223 | $newLine .= $replaceAt; |
| 225 | 224 | |
@@ -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; |
@@ -4,25 +4,25 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Translator |
| 6 | 6 | { |
| 7 | - public static function translate (AST $tree): string |
|
| 7 | + public static function translate(AST $tree): string |
|
| 8 | 8 | { |
| 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 | return $code; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - protected static function translateNode (Node $node, Node $owner = null, array &$definedObjects = []): string |
|
| 18 | + protected static function translateNode(Node $node, Node $owner = null, array &$definedObjects = []): string |
|
| 19 | 19 | { |
| 20 | 20 | $code = ''; |
| 21 | 21 | |
| 22 | 22 | switch ($node->type) |
| 23 | 23 | { |
| 24 | 24 | case RUNTIME_EXECUTION: |
| 25 | - $code .= self::formatLine ($node->args['code'], $definedObjects) ."\n\n"; |
|
| 25 | + $code .= self::formatLine($node->args['code'], $definedObjects)."\n\n"; |
|
| 26 | 26 | |
| 27 | 27 | break; |
| 28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | if (isset ($definedObjects[$node->args['name']])) |
| 31 | 31 | break; |
| 32 | 32 | |
| 33 | - $code .= '$'. $node->args['name'] .' = new '. $node->args['class'] .' ('. implode (', ', self::processArgs ($node->args['args'], $definedObjects)) .');' ."\n". '$'. $node->args['name'] .'->name = \''. $node->args['name'] .'\';' ."\n"; |
|
| 33 | + $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 | 34 | |
| 35 | 35 | $definedObjects[$node->args['name']] = $node->args['name']; |
| 36 | 36 | |
@@ -39,74 +39,74 @@ discard block |
||
| 39 | 39 | case PROPERTY_SET: |
| 40 | 40 | $preset = ''; |
| 41 | 41 | |
| 42 | - if (preg_match ('/function \((.*)\) use \((.*)\)/', $node->args['property_value'])) |
|
| 42 | + if (preg_match('/function \((.*)\) use \((.*)\)/', $node->args['property_value'])) |
|
| 43 | 43 | { |
| 44 | - $use = substr ($node->args['property_value'], strpos ($node->args['property_value'], 'use')); |
|
| 45 | - $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
|
| 46 | - $use = explode (' ', $use); |
|
| 44 | + $use = substr($node->args['property_value'], strpos($node->args['property_value'], 'use')); |
|
| 45 | + $use = $ouse = substr($use, ($pos = strpos($use, '(') + 1), strpos($use, ')') - $pos); |
|
| 46 | + $use = explode(' ', $use); |
|
| 47 | 47 | |
| 48 | 48 | foreach ($use as $id => $useParam) |
| 49 | 49 | if (isset ($definedObjects[$useParam]) && $use[$id + 1][0] == '$') |
| 50 | 50 | { |
| 51 | 51 | $fname = $use[$id + 1]; |
| 52 | 52 | |
| 53 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
| 54 | - $fname = substr ($fname, 0, -1); |
|
| 53 | + if (substr($fname, strlen($fname) - 1) == ',') |
|
| 54 | + $fname = substr($fname, 0, -1); |
|
| 55 | 55 | |
| 56 | 56 | $preset .= "$fname = $useParam; "; |
| 57 | 57 | |
| 58 | 58 | unset ($use[$id]); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $preset = self::formatLine ($preset, $definedObjects) ."\n"; |
|
| 61 | + $preset = self::formatLine($preset, $definedObjects)."\n"; |
|
| 62 | 62 | |
| 63 | - $node->args['property_value'] = self::formatLine (str_replace ($ouse, join (' ', $use), $node->args['property_value']), $definedObjects); |
|
| 63 | + $node->args['property_value'] = self::formatLine(str_replace($ouse, join(' ', $use), $node->args['property_value']), $definedObjects); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $code .= $preset .'$'. $owner->args['name'] .'->'. $node->args['property_name'] .' = '. self::formatLine ($node->args['property_value'], $definedObjects) .';' ."\n"; |
|
| 66 | + $code .= $preset.'$'.$owner->args['name'].'->'.$node->args['property_name'].' = '.self::formatLine($node->args['property_value'], $definedObjects).';'."\n"; |
|
| 67 | 67 | |
| 68 | 68 | break; |
| 69 | 69 | |
| 70 | 70 | case METHOD_CALL: |
| 71 | - $code .= '$'. $owner->args['name'] .'->'. $node->args['method_name'] .' ('. implode (', ', self::processArgs ($node->args['method_args'], $definedObjects)) .');' ."\n"; |
|
| 71 | + $code .= '$'.$owner->args['name'].'->'.$node->args['method_name'].' ('.implode(', ', self::processArgs($node->args['method_args'], $definedObjects)).');'."\n"; |
|
| 72 | 72 | |
| 73 | 73 | break; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - foreach ($node->getNodes () as $subnode) |
|
| 77 | - $code .= self::translateNode ($subnode, $node, $definedObjects); |
|
| 76 | + foreach ($node->getNodes() as $subnode) |
|
| 77 | + $code .= self::translateNode($subnode, $node, $definedObjects); |
|
| 78 | 78 | |
| 79 | 79 | return $code; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - protected static function processArgs (array $args, array $definedObjects = []): array |
|
| 82 | + protected static function processArgs(array $args, array $definedObjects = []): array |
|
| 83 | 83 | { |
| 84 | 84 | $newArgs = []; |
| 85 | 85 | |
| 86 | 86 | foreach ($args as $arg) |
| 87 | - $newArgs[] = self::formatLine ($arg, $definedObjects); |
|
| 87 | + $newArgs[] = self::formatLine($arg, $definedObjects); |
|
| 88 | 88 | |
| 89 | 89 | return $newArgs; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - protected static function formatLine (string $line, array $objects = []): string |
|
| 92 | + protected static function formatLine(string $line, array $objects = []): string |
|
| 93 | 93 | { |
| 94 | - if (sizeof ($objects) > 0) |
|
| 94 | + if (sizeof($objects) > 0) |
|
| 95 | 95 | { |
| 96 | - $len = strlen ($line); |
|
| 96 | + $len = strlen($line); |
|
| 97 | 97 | $newLine = ''; |
| 98 | 98 | |
| 99 | - $replacement = array_map (function ($object) |
|
| 99 | + $replacement = array_map(function($object) |
|
| 100 | 100 | { |
| 101 | - return '$'. $object; |
|
| 101 | + return '$'.$object; |
|
| 102 | 102 | }, $objects); |
| 103 | 103 | |
| 104 | - $replacement = array_map (function ($name) |
|
| 104 | + $replacement = array_map(function($name) |
|
| 105 | 105 | { |
| 106 | - return strlen ($name = trim ($name)) + substr_count ($name, '_'); |
|
| 107 | - }, $omap = array_flip ($replacement)); |
|
| 106 | + return strlen($name = trim($name)) + substr_count($name, '_'); |
|
| 107 | + }, $omap = array_flip($replacement)); |
|
| 108 | 108 | |
| 109 | - arsort ($replacement); |
|
| 109 | + arsort($replacement); |
|
| 110 | 110 | |
| 111 | 111 | $nReplacement = []; |
| 112 | 112 | |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | $nReplacement[$omap[$replaceTo]] = $replaceTo; |
| 115 | 115 | |
| 116 | 116 | $replacement = $nReplacement; |
| 117 | - $blacklist = array_flip (['\'', '"', '$']); |
|
| 117 | + $blacklist = array_flip(['\'', '"', '$']); |
|
| 118 | 118 | |
| 119 | 119 | for ($i = 0; $i < $len; ++$i) |
| 120 | 120 | { |
| 121 | 121 | $replaced = false; |
| 122 | 122 | |
| 123 | 123 | foreach ($replacement as $name => $replaceAt) |
| 124 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 124 | + if (substr($line, $i, ($l = strlen($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 125 | 125 | { |
| 126 | 126 | $newLine .= $replaceAt; |
| 127 | 127 | |
@@ -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; |
@@ -8,10 +8,10 @@ discard block |
||
| 8 | 8 | class Node |
| 9 | 9 | { |
| 10 | 10 | public ?string $line = null; // Строка |
| 11 | - public array $words = []; // Список слов |
|
| 12 | - public int $height = 0; // Высота строки |
|
| 13 | - public int $type = 0; // Тип ноды |
|
| 14 | - public array $args = []; // Аргументы ноды |
|
| 11 | + public array $words = []; // Список слов |
|
| 12 | + public int $height = 0; // Высота строки |
|
| 13 | + public int $type = 0; // Тип ноды |
|
| 14 | + public array $args = []; // Аргументы ноды |
|
| 15 | 15 | |
| 16 | 16 | protected array $nodes = []; // Ветви ноды |
| 17 | 17 | |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * [@param array $node = null] - массив для импорта ноды |
| 22 | 22 | */ |
| 23 | - public function __construct (array $node = null) |
|
| 23 | + public function __construct(array $node = null) |
|
| 24 | 24 | { |
| 25 | 25 | if ($node !== null) |
| 26 | - $this->import ($node); |
|
| 26 | + $this->import($node); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return Node - возвращает саму себя |
| 35 | 35 | */ |
| 36 | - public function import (array $node): Node |
|
| 36 | + public function import(array $node): Node |
|
| 37 | 37 | { |
| 38 | 38 | $this->line = $node['line'] ?? null; |
| 39 | 39 | $this->words = $node['words'] ?? []; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $this->type = $node['type'] ?? 0; |
| 42 | 42 | $this->args = $node['args'] ?? []; |
| 43 | 43 | |
| 44 | - $this->nodes = array_map (fn (array $t) => new Node ($t), $node['nodes'] ?? []); |
|
| 44 | + $this->nodes = array_map(fn(array $t) => new Node($t), $node['nodes'] ?? []); |
|
| 45 | 45 | |
| 46 | 46 | return $this; |
| 47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return array - возвращает массив экспортированной ноды |
| 53 | 53 | */ |
| 54 | - public function export (): array |
|
| 54 | + public function export(): array |
|
| 55 | 55 | { |
| 56 | 56 | return [ |
| 57 | 57 | 'line' => $this->line, |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | 'type' => $this->type, |
| 61 | 61 | 'args' => $this->args, |
| 62 | 62 | |
| 63 | - 'nodes' => array_map (fn (Node $node) => $node->export (), $this->nodes) |
|
| 63 | + 'nodes' => array_map(fn(Node $node) => $node->export(), $this->nodes) |
|
| 64 | 64 | ]; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return Node - возвращает саму себя |
| 73 | 73 | */ |
| 74 | - public function push (Node $node): Node |
|
| 74 | + public function push(Node $node): Node |
|
| 75 | 75 | { |
| 76 | 76 | $this->nodes[] = $node; |
| 77 | 77 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return array - возвращает список ветвей |
| 85 | 85 | */ |
| 86 | - public function getNodes (): array |
|
| 86 | + public function getNodes(): array |
|
| 87 | 87 | { |
| 88 | 88 | return $this->nodes; |
| 89 | 89 | } |
@@ -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 | /** |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * [@param array $tree = null] - массив для импорта дерева |
| 17 | 17 | */ |
| 18 | - public function __construct (array $tree = null) |
|
| 18 | + public function __construct(array $tree = null) |
|
| 19 | 19 | { |
| 20 | 20 | if ($tree !== null) |
| 21 | - $this->import ($tree); |
|
| 21 | + $this->import($tree); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return AST - возвращает сам себя |
| 30 | 30 | */ |
| 31 | - public function import (array $tree): AST |
|
| 31 | + public function import(array $tree): AST |
|
| 32 | 32 | { |
| 33 | 33 | foreach ($tree as $node) |
| 34 | - $this->nodes[] = new Node ($node); |
|
| 34 | + $this->nodes[] = new Node($node); |
|
| 35 | 35 | |
| 36 | 36 | return $this; |
| 37 | 37 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return array - возращает массив экспортированного дерева |
| 43 | 43 | */ |
| 44 | - public function export (): array |
|
| 44 | + public function export(): array |
|
| 45 | 45 | { |
| 46 | - return array_map (fn (Node $node) => $node->export (), $this->nodes); |
|
| 46 | + return array_map(fn(Node $node) => $node->export(), $this->nodes); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return AST - возвращает сам себя |
| 55 | 55 | */ |
| 56 | - public function push (Node $node): AST |
|
| 56 | + public function push(Node $node): AST |
|
| 57 | 57 | { |
| 58 | 58 | $this->nodes[] = $node; |
| 59 | 59 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return array - возвращает список корневых нод |
| 67 | 67 | */ |
| 68 | - public function getNodes (): array |
|
| 68 | + public function getNodes(): array |
|
| 69 | 69 | { |
| 70 | 70 | return $this->nodes; |
| 71 | 71 | } |
@@ -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 | } |
@@ -20,33 +20,33 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return AST - возвращает AST дерево разметки |
| 22 | 22 | */ |
| 23 | - public static function parse (string $vst): AST |
|
| 23 | + public static function parse(string $vst): AST |
|
| 24 | 24 | { |
| 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 | - $lines = explode (self::$divider, $vst); |
|
| 31 | + $lines = explode(self::$divider, $vst); |
|
| 32 | 32 | $skip_at = -1; |
| 33 | 33 | |
| 34 | 34 | foreach ($lines as $line_num => $line) |
| 35 | 35 | { |
| 36 | 36 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
| 37 | 37 | |
| 38 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
| 38 | + if ($skip_at > $line_num || !self::filter($line)) |
|
| 39 | 39 | continue; |
| 40 | 40 | |
| 41 | - $height = self::getHeight ($line); |
|
| 42 | - $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
|
| 41 | + $height = self::getHeight($line); |
|
| 42 | + $words = array_filter(explode(' ', $line), 'VLF\Parser::filter'); |
|
| 43 | 43 | $poped = false; |
| 44 | 44 | |
| 45 | 45 | # Очищаем стек объектов |
| 46 | - while ($objects->size () > 0) |
|
| 47 | - if ($objects->current ()->height >= $height) |
|
| 46 | + while ($objects->size() > 0) |
|
| 47 | + if ($objects->current()->height >= $height) |
|
| 48 | 48 | { |
| 49 | - $objects->pop (); |
|
| 49 | + $objects->pop(); |
|
| 50 | 50 | |
| 51 | 51 | $poped = true; |
| 52 | 52 | } |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | else break; |
| 55 | 55 | |
| 56 | 56 | # Создаём новую ссылку на объект |
| 57 | - if ($poped && $objects->size () > 0) |
|
| 57 | + if ($poped && $objects->size() > 0) |
|
| 58 | 58 | { |
| 59 | - $object = $objects->pop (); |
|
| 59 | + $object = $objects->pop(); |
|
| 60 | 60 | |
| 61 | - $objects->push (new Node (array_merge ($object->export (), ['nodes' => []]))); |
|
| 62 | - $tree->push ($objects->current ()); |
|
| 61 | + $objects->push(new Node(array_merge($object->export(), ['nodes' => []]))); |
|
| 62 | + $tree->push($objects->current()); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | if (isset ($words[0][1])) |
| 74 | 74 | { |
| 75 | 75 | if ($words[0][1] == '^') |
| 76 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
| 76 | + $skip_at = self::parseSubtext($lines, $line_num, $height)[1]; |
|
| 77 | 77 | |
| 78 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
| 78 | + else throw new \Exception('Unknown char founded after comment definition at line '.($line_num + 1)); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | continue; |
@@ -86,30 +86,30 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | elseif ($words[0][0] == '.') |
| 88 | 88 | { |
| 89 | - $pos = strpos ($line, ':'); |
|
| 89 | + $pos = strpos($line, ':'); |
|
| 90 | 90 | $parents = null; |
| 91 | 91 | |
| 92 | 92 | if ($pos !== false) |
| 93 | 93 | { |
| 94 | - $name = trim (substr ($line, 1, $pos - 1)); |
|
| 94 | + $name = trim(substr($line, 1, $pos - 1)); |
|
| 95 | 95 | |
| 96 | 96 | if (isset ($line[$pos])) |
| 97 | 97 | { |
| 98 | - $parents = trim (substr ($line, $pos + 1)); |
|
| 98 | + $parents = trim(substr($line, $pos + 1)); |
|
| 99 | 99 | |
| 100 | - if (strlen ($parents) == 0) |
|
| 100 | + if (strlen($parents) == 0) |
|
| 101 | 101 | $parents = null; |
| 102 | 102 | |
| 103 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
| 103 | + else $parents = array_map('trim', explode(',', $parents)); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - else $name = trim (substr ($line, 1)); |
|
| 107 | + else $name = trim(substr($line, 1)); |
|
| 108 | 108 | |
| 109 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
| 110 | - $parents = [$objects->current ()->args['name']]; |
|
| 109 | + if ($parents === null && $objects->size() > 0 && $objects->current()->height < $height) |
|
| 110 | + $parents = [$objects->current()->args['name']]; |
|
| 111 | 111 | |
| 112 | - $objects->push (new Node ([ |
|
| 112 | + $objects->push(new Node([ |
|
| 113 | 113 | 'type' => \VLF\STYLE_DEFINITION, |
| 114 | 114 | 'line' => $line, |
| 115 | 115 | 'words' => $words, |
@@ -121,35 +121,35 @@ discard block |
||
| 121 | 121 | ] |
| 122 | 122 | ])); |
| 123 | 123 | |
| 124 | - $tree->push ($objects->current ()); |
|
| 124 | + $tree->push($objects->current()); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * Установка свойства |
| 129 | 129 | */ |
| 130 | - elseif (($pos = strpos ($line, ':')) !== false) |
|
| 130 | + elseif (($pos = strpos($line, ':')) !== false) |
|
| 131 | 131 | { |
| 132 | - if ($objects->size () == 0) |
|
| 133 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
| 132 | + if ($objects->size() == 0) |
|
| 133 | + throw new \Exception('Trying to set property to unknown object at line '.($line_num + 1)); |
|
| 134 | 134 | |
| 135 | 135 | if (!isset ($words[1])) |
| 136 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
| 136 | + throw new \Exception('Trying to set void property value at line '.($line_num + 1)); |
|
| 137 | 137 | |
| 138 | - $propertyName = substr ($line, 0, $pos); |
|
| 139 | - $propertyValue = substr ($line, $pos + 1); |
|
| 138 | + $propertyName = substr($line, 0, $pos); |
|
| 139 | + $propertyValue = substr($line, $pos + 1); |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * Обработка многострочных свойств |
| 143 | 143 | */ |
| 144 | 144 | if ($line[$pos + 1] == '^') |
| 145 | 145 | { |
| 146 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
| 146 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
| 147 | 147 | |
| 148 | - $propertyValue = substr ($propertyValue, 1) . $parsed[0]; |
|
| 148 | + $propertyValue = substr($propertyValue, 1).$parsed[0]; |
|
| 149 | 149 | $skip_at = $parsed[1]; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $objects->current ()->push (new Node ([ |
|
| 152 | + $objects->current()->push(new Node([ |
|
| 153 | 153 | 'type' => \VLF\PROPERTY_SET, |
| 154 | 154 | 'line' => $line, |
| 155 | 155 | 'words' => $words, |
@@ -167,26 +167,26 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
| 169 | 169 | { |
| 170 | - if ($objects->size () == 0) |
|
| 171 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
| 170 | + if ($objects->size() == 0) |
|
| 171 | + throw new \Exception('Trying to call method from unknown object at line '.($line_num + 1)); |
|
| 172 | 172 | |
| 173 | 173 | $methodArgs = []; |
| 174 | 174 | |
| 175 | - if (($pos = strpos ($line, '(')) !== false) |
|
| 175 | + if (($pos = strpos($line, '(')) !== false) |
|
| 176 | 176 | { |
| 177 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
| 178 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
| 177 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
| 178 | + throw new \Exception('Incorrect method arguments syntax at line '.($line_num + 1)); |
|
| 179 | 179 | |
| 180 | - $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
|
| 180 | + $methodArgs = substr($line, $pos + 1, $end - $pos - 1); |
|
| 181 | 181 | |
| 182 | - $methodName = trim (substr ($line, 2, $pos - 2)); |
|
| 183 | - $methodArgs = self::filter ($methodArgs) ? |
|
| 184 | - self::parseArguments ($methodArgs) : []; |
|
| 182 | + $methodName = trim(substr($line, 2, $pos - 2)); |
|
| 183 | + $methodArgs = self::filter($methodArgs) ? |
|
| 184 | + self::parseArguments($methodArgs) : []; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - else $methodName = trim (substr ($line, 2)); |
|
| 187 | + else $methodName = trim(substr($line, 2)); |
|
| 188 | 188 | |
| 189 | - $objects->current ()->push (new Node ([ |
|
| 189 | + $objects->current()->push(new Node([ |
|
| 190 | 190 | 'type' => \VLF\METHOD_CALL, |
| 191 | 191 | 'line' => $line, |
| 192 | 192 | 'words' => $words, |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * Неопознанная структура |
| 204 | 204 | */ |
| 205 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
| 205 | + else throw new \Exception('Unsupported structure founded at line '.($line_num + 1)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | return $tree; |
@@ -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; |