public function __set($name, $parser) { $parser = Parser::sanitize($parser); $this->parsers[$name] = $parser; if (!$parser->hasName()) { $parser->setName($name); } return $parser; }
public function __construct($parsers = null) { if (!is_array($parsers)) { $parsers = func_get_args(); } foreach ($parsers as $id => $parser) { $parser = Parser::sanitize($parser); $parsers[$id] = $parser; if (!$parser instanceof Parser) { throw new GrammarException('There is an object that is not a parser in this combinator.'); } } $this->parsers = $parsers; }
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'); }
public function __construct($parser, callable $function) { $this->function = $function; $this->parser = Parser::sanitize($parser); }
public function __construct($parser) { $this->parser = Parser::sanitize($parser); }