regs[$this->regsCounter] = $match[1]; $id = "<regsCounter}>>"; $this->regsCounter++; return $id; } protected function _extractStrings($match) { $this->strings[$this->stringsCounter] = $this->importRegExps($match[0]); $id = "<stringsCounter}>>"; $this->stringsCounter++; return $id; } protected function importRegExps($input) { $regs = $this->regs; return preg_replace_callback("#<>#", fn($match) => $regs[$match[1]], $input); } protected function importStrings($input) { $strings = $this->strings; return preg_replace_callback("#<>#", fn($match) => $strings[$match[1]], $input); } public function __construct($file, $keywords = '_') { $this->content = file_get_contents($file); $this->keywords = (array)$keywords; } public function parse() { $output = $this->content; //htmlspecialchars($this->content, ENT_NOQUOTES); // extract reg exps $output = preg_replace_callback( '# ( / (?: (?>[^/\\\\]++) | \\\\\\\\ | (?_extractRegs(...), $output ); // extract strings $output = preg_replace_callback( ['# " ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?[^'\\\\]++) | \\\\\\\\ | (?_extractStrings(...), $output ); // delete line comments $output = preg_replace("#(//.*?)$#m", '', $output); // delete multiline comments $output = preg_replace('#/\*(.*?)\*/#is', '', $output); $strings = $this->strings; $output = preg_replace_callback("#<>#", fn($match) => $strings[$match[1]], $output); $keywords = implode('|', $this->keywords); $strings = []; // extract func calls preg_match_all( '# (?:'.$keywords.') \(\\ *" ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?[^'\\\\]++) | \\\\\\\\ | (?