Example #1
0
 private static function createParser()
 {
     $parser = new ParseMaster();
     // There is a bug in ParseMaster that causes a backslash at the end of a line to be changed
     // to \s if we use a backslash as the escape character. We work around this by using an
     // obscure escape character that we hope will never appear at the end of a line.
     $parser->escapeChar = chr(1);
     // Protect strings. The original code had [^\'\\v] here, but that didn't armor multiline
     // strings correctly. This also armors multiline strings that don't have backslashes at the
     // end of the line (these are invalid), but that's fine because we're just armoring here.
     $parser->add('/\'([^\'\\\\]*(\\\\.[^\'\\\\]*)*)\'/', '$1');
     $parser->add('/"([^"\\\\]*(\\\\.[^"\\\\]*)*)"/', '$1');
     // Protect regular expressions
     $parser->add('/[ \\t]+(\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?)/', '$2');
     $parser->add('/[^\\w\\$\\/\'"*)\\?:]\\/[^\\/\\r\\n\\*][^\\/\\r\\n]*\\/g?i?/', '$1');
     // Remove comments
     $parser->add('/\\/\\*(.|[\\r\\n])*?\\*\\//');
     // Preserve the newline after a C++-style comment -- bug 27046
     $parser->add('/\\/\\/[^\\r\\n]*([\\r\\n])/', '$2');
     return $parser;
 }
 private function _encodeKeywords($script)
 {
     // escape high-ascii values already in the script (i.e. in strings)
     if ($this->_encoding > 62) {
         $script = $this->_escape95($script);
     }
     // create the parser
     $parser = new ParseMaster();
     $encode = $this->_getEncoder($this->_encoding);
     // for high-ascii, don't encode single character low-ascii
     $regexp = $this->_encoding > 62 ? '/\\w\\w+/' : '/\\w+/';
     // build the word list
     $keywords = $this->_analyze($script, $regexp, $encode);
     $encoded = $keywords['encoded'];
     // encode
     $parser->add($regexp, array('fn' => '_replace_encoded', 'data' => $encoded));
     if (empty($script)) {
         return $script;
     } else {
         //$res = $parser->exec($script);
         //$res = $this->_bootStrap($res, $keywords);
         //return $res;
         return $this->_bootStrap($parser->exec($script), $keywords);
     }
 }
Example #3
0
 private function _basicCompression($script)
 {
     $parser = new ParseMaster();
     // make safe
     $parser->escapeChar = '\\';
     // protect strings
     $parser->add('/\'[^\'\\n\\r]*\'/', self::IGNORE);
     $parser->add('/"[^"\\n\\r]*"/', self::IGNORE);
     // remove comments
     $parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' ');
     $parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' ');
     // protect regular expressions
     $parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2');
     // IGNORE
     $parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE);
     // remove redundant semi-colons
     $parser->add('/\\(;;\\)/', self::IGNORE);
     // protect for (;;) loops
     $parser->add('/;+\\s*([};])/', '$2');
     // apply the above
     $script = $parser->exec($script);
     // remove white-space
     $parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3');
     $parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3');
     $parser->add('/\\s+/', '');
     // done
     return $parser->exec($script);
 }
	private function encodeKeywords($script)
	{
		// escape high-ascii values already in the script (i.e. in strings)
		if ($this->encoding == PACKER_ENCODING_HIGHASCII) {
			$script = $this->escape95($script);
		}
		// create the parser
		$parser = new ParseMaster();
		$encode = $this->getEncoder($this->encoding);

		// for high-ascii, don't encode single character low-ascii
		$regex = '~'.(($this->encoding == PACKER_ENCODING_HIGHASCII) ? "\\w\\w+" : "\\w+").'~';

		// build the word list
		$this->encodingLookup = $this->analyze($script, $regex, $encode);

		// encode
		$parser->Add(($this->encoding == PACKER_ENCODING.HIGHASCII) ? "\\w\\w+" : "\\w+", array(&$this, 'encodeWithLookup'));

		// if encoded, wrap the script in a decoding function
		return ($script == '') ? "" : $this->bootStrap($parser->Exec($script), $this->encodingLookup);
	}