Ejemplo n.º 1
0
 function match_code($value)
 {
     // We inline single-character matches for speed
     if (!$this->contains_expression($value) && strlen(eval('return ' . $value . ';')) == 1) {
         return $this->match_fail_conditional('substr($this->string,$this->pos,1) == ' . $value, PHPBuilder::build()->l('$this->pos += 1;', $this->set_text($value)));
     }
     return parent::match_code($value);
 }
Ejemplo n.º 2
0
 function match_code($value)
 {
     $code = PHPBuilder::build();
     foreach ($value as $token) {
         $code->l($token->compile()->replace(array('MATCH' => NULL, 'FAIL' => 'FBREAK')));
     }
     $code->l('MBREAK');
     return $this->match_fail_block($code);
 }
Ejemplo n.º 3
0
 function match_code($value)
 {
     $id = $this->varid();
     $code = PHPBuilder::build()->l($this->save($id));
     foreach ($value as $opt) {
         $code->l($opt->compile()->replace(array('MATCH' => 'MBREAK', 'FAIL' => NULL)), $this->restore($id));
     }
     $code->l('FBREAK');
     return $this->match_fail_block($code);
 }
Ejemplo n.º 4
0
 function match_code($value)
 {
     $function = $this->match_function($value);
     $storetag = $this->function_name($this->tag ? $this->tag : $this->match_function($value));
     if (\hafriedlander\Peg\Compiler::$debug) {
         $debug_header = PHPBuilder::build()->l('$indent = str_repeat( " ", $this->depth );', '$this->depth += 2;', '$sub = ( strlen( $this->string ) - $this->pos > 20 ) ? ( substr( $this->string, $this->pos, 20 ) . "..." ) : substr( $this->string, $this->pos );', '$sub = preg_replace( \'/(\\r|\\n)+/\', " {NL} ", $sub );', 'print( $indent."Matching against $matcher (".$sub.")\\n" );');
         $debug_match = PHPBuilder::build()->l('print( $indent."MATCH\\n" );', '$this->depth -= 2;');
         $debug_fail = PHPBuilder::build()->l('print( $indent."FAIL\\n" );', '$this->depth -= 2;');
     } else {
         $debug_header = $debug_match = $debug_fail = NULL;
     }
     return PHPBuilder::build()->l('$matcher = \'match_\'.' . $function . '; $key = $matcher; $pos = $this->pos;', $debug_header, '$subres = ( $this->packhas( $key, $pos ) ? $this->packread( $key, $pos ) : $this->packwrite( $key, $pos, $this->$matcher(array_merge($stack, array($result))) ) );', $this->match_fail_conditional('$subres !== FALSE', PHPBuilder::build()->l($debug_match, $this->tag === FALSE ? '$this->store( $result, $subres );' : '$this->store( $result, $subres, "' . $storetag . '" );'), PHPBuilder::build()->l($debug_fail)));
 }