/** * Construct a realistic domain. * * @return void */ protected function construct() { if (null === self::$_compiler) { self::$_compiler = Compiler\Llk::load(new File\Read('hoa://Library/Regex/Grammar.pp')); } if (!isset($this['regex'])) { $this['regex'] = new Conststring(''); } $this->_ast = self::$_compiler->parse(mb_substr($regex = $this['regex']->getConstantValue(), 1, mb_strrpos($regex, mb_substr($regex, 0, 1), 1) - 1)); return; }
/** * Predicate whether the sampled value belongs to the realistic domains. * * @param mixed $q Sampled value. * @return boolean */ protected function _predicate($q) { // How to handle size (because the unit of size is token, not // character)? try { $this->_compiler->parse($q, null, false); } catch (\Exception $e) { return false; } return true; }
/** * Get AST of the token representation. * * @return \Hoa\Compiler\Llk\TreeNode */ public function getAST() { if (null === static::$_regexCompiler) { $stream = new File\Read('hoa://Library/Regex/Grammar.pp'); $stream->rewind(); static::$_regexCompiler = Compiler\Llk::load($stream); } if (null === $this->_ast) { $this->_ast = static::$_regexCompiler->parse($this->getRepresentation()); } return $this->_ast; }