コード例 #1
0
ファイル: Token.php プロジェクト: guitarpoet/clips-tool
 protected function n_to_x($code, $id, $min, $max)
 {
     if (1 === $min && 1 === $max) {
         return $code;
     }
     return PHPBuilder::build()->l('$count = 0;')->b('while ($count < ' . $max . ')', $this->save($id), $code->replace(array('MATCH' => NULL, 'FAIL' => $this->restore($id, true)->l('break;'))), '$count++;')->b('if ($count >= ' . $min . ')', 'MATCH')->b('else', 'FAIL');
 }
コード例 #2
0
 /**
  * Generate the PHP code for a function to match against a string for this rule
  */
 function compile($indent)
 {
     $function_name = $this->function_name($this->name);
     // Build the typestack
     $typestack = array();
     $class = $this;
     do {
         $typestack[] = $this->function_name($class->name);
     } while ($class = $class->extends);
     $typestack = "array('" . implode("','", $typestack) . "')";
     // Build an array of additional arguments to add to result node (if any)
     if (empty($this->arguments)) {
         $arguments = 'null';
     } else {
         $arguments = "array(";
         foreach ($this->arguments as $k => $v) {
             $arguments .= "'{$k}' => '{$v}'";
         }
         $arguments .= ")";
     }
     $match = PHPBuilder::build();
     $match->l("protected \$match_{$function_name}_typestack = {$typestack};");
     $match->b("function match_{$function_name} (\$stack = array())", '$matchrule = "' . $function_name . '"; $result = $this->construct($matchrule, $matchrule, ' . $arguments . ');', $this->parsed->compile()->replace(array('MATCH' => 'return $this->finalise($result);', 'FAIL' => 'return FALSE;')));
     $functions = array();
     foreach ($this->functions as $name => $function) {
         $function_name = $this->function_name(preg_match('/^_/', $name) ? $this->name . $name : $this->name . '_' . $name);
         $functions[] = implode(PHP_EOL, array('function ' . $function_name . ' ' . $function));
     }
     // print_r( $match ) ; return '' ;
     return $match->render(NULL, $indent) . PHP_EOL . PHP_EOL . implode(PHP_EOL, $functions);
 }
コード例 #3
0
ファイル: PHPWriter.php プロジェクト: guitarpoet/clips-tool
 function match_fail_block($code)
 {
     $id = $this->varid();
     return PHPBuilder::build()->l('$' . $id . ' = NULL;')->b('do', $code->replace(array('MBREAK' => '$' . $id . ' = TRUE; break;', 'FBREAK' => '$' . $id . ' = FALSE; break;')))->l('while(0);')->b('if( $' . $id . ' === TRUE )', 'MATCH')->b('if( $' . $id . ' === FALSE)', 'FAIL');
 }