thirdparty/php-peg/Compiler.php
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 ) ;
	}
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 ) ;
	}
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 ) ; }
Generate the PHP code for a function to match against a string for this rule
Generate the PHP code for a function to match against a string for this rule