Ejemplo n.º 1
0
 public function __construct($parser, $separator = ',', $allow_trailing = true)
 {
     $parser = Parser::sanitize($parser);
     $separator = Parser::sanitize($separator);
     $sequence = new Sequence($parser, new Many(new Sequence($separator, $parser)));
     if ($allow_trailing) {
         $sequence->append(new OptionalChoice($separator));
     }
     $this->root = new Closure(new OptionalChoice($sequence), function ($data) {
         $result = [];
         if (is_array($data)) {
             $result[] = $data[0];
             foreach ($data[1] as $datum) {
                 $result[] = $datum[1];
             }
         }
         return $result;
     });
     $this->root->setName('repsep');
 }
Ejemplo n.º 2
0
 public function testAllNonCapturingChildren()
 {
     $parser = new Sequence(new Ignore('asdf'), new Ignore('hjkl'));
     $this->assertFalse($parser->parse(new Input('asdfhjkl'))->hasData);
 }