19declare(strict_types=1);
49 new Ok(is_array($value) && !is_string(key($value)) ? current($value) : $value)
60 return new Custom(fn($input) => $this->
apply($parse, $input)->value());
68 public function range(
int $start,
int $end): Closure
78 public function alpha(): Closure
80 return $this->primitives->simpleEither([
81 $this->
range(0x41, 0x5A),
82 $this->
range(0x61, 0x7A),
89 public function digit(): Closure
91 return $this->
range(0x30, 0x39);
94 public function either(array $parsers): Closure
96 return $this->primitives->simpleEither($this->
namesFromKeys($parsers));
105 return $this->primitives->simpleSequence($this->
namesFromKeys($parsers));
114 public function repeat(
int $min, ?
int $max, $parse): Closure
117 $max =
null === $max ? null : max($min, $max) - $min;
119 return $this->primitives->simpleSequence([
120 ...array_fill(0, $min, $parse),
121 $this->primitives->until($max, $parse)
132 return $this->
transform->to($transformation, $parse);
142 function ($key) use ($array): Closure {
143 $current = $this->primitives->parserFrom($array[$key]);
144 return is_string($key) ? $this->
transform->as($key, $current) : $current;
A result encapsulates a value or an error and simplifies the handling of those.
@phpstan-type Continuation Closure(Result<Intermediate>): Result<Intermediate> @phpstan-type Parser C...
toTransformation(Closure $parse)
consume(Closure $parse, Intermediate $intermediate)
It just checks if the given input is fully consumed after parsing and rejects the input otherwise.
namesFromKeys(array $array)
repeat(int $min, ?int $max, $parse)
range(int $start, int $end)
transformation(Transformation $transformation, Closure $parse)
apply(Closure $parse, string $input)
@phpstan-type Continuation Closure(Result<Intermediate>): Result<Intermediate> @phpstan-type Parser C...
A result encapsulates a value or an error and simplifies the handling of those.
then(callable $f)
Get a new result from the callable or do nothing if this is an error.