Compare commits

..

3 Commits

Author SHA1 Message Date
Pavel Shevaev 5d5af1ac09 Adding some typehints
Publish PHP Package / docker (push) Successful in 7s Details
2025-04-17 17:47:55 +03:00
Pavel Shevaev f5874a9db4 Adding extra check if def macros are not actually present in the source
Publish PHP Package / docker (push) Successful in 6s Details
2025-02-28 01:54:13 +03:00
Pavel Shevaev 20e06b8433 Fixing new lines preserving for one line comments
Publish PHP Package / docker (push) Failing after 3s Details
2025-02-26 09:50:52 +03:00
1 changed files with 19 additions and 10 deletions

View File

@ -31,12 +31,12 @@ class JSM
$this->args_parser = new JSM_ArgsParser();
}
function getRootFile()
function getRootFile() : string
{
return $this->file;
}
function getModule($file)
static function getModule($file) : JSM_Module
{
if(isset(self::$modules[$file]))
return self::$modules[$file];
@ -254,9 +254,8 @@ class JSM
{
if(strpos($txt, '/*') === false)
return $txt;
$regex = '~/\*.*?\*/~s';
$txt = preg_replace_callback(
$regex,
'~/\*.*?\*/~s',
//preserve the new lines for better error reporting
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
$txt);
@ -266,7 +265,11 @@ class JSM
private static function _removeLineComments(string $txt) : string
{
//TODO: it's not robust enough, note a hack for URL addresses
$txt = preg_replace("~\s*(?<!:)//.*~", "\n", $txt);
$txt = preg_replace_callback(
'~\s*(?<!:)//.*~',
//preserve the new lines for better error reporting
function($m) { return str_repeat("\n", substr_count($m[0], "\n")); },
$txt);
return $txt;
}
@ -520,7 +523,12 @@ class JSM
private function _extractScriptDefs(string $file, string $txt) : string
{
if(strpos($txt, 'def') === false)
$strpos = strpos($txt, 'def');
if($strpos === false)
return $txt;
//let's extra check if newline symbols preceed 'def'
if($strpos > 0 && !($txt[$strpos-1] === "\n" || $txt[$strpos-1] === "\r"))
return $txt;
//NOTE: make it more robust
@ -675,22 +683,23 @@ class JSM
class JSM_Module
{
var $file = '';
var string $file = '';
var $defs = array();
//NOTE: all includes (even those included from other modules)
var $includes = array();
var $node = null;
function __construct($file)
function __construct(string $file)
{
$this->file = $file;
}
function getIncludes()
function getIncludes() : array
{
return $this->includes;
}
function getFile()
function getFile() : string
{
return $this->file;
}