ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Refinery\Parser\ABNF\Primitives Class Reference

@phpstan-type Continuation Closure(Result<Intermediate>): Result<Intermediate> @phpstan-type Parser Closure(Intermediate, Continuation): Result<Intermediate> More...

+ Collaboration diagram for ILIAS\Refinery\Parser\ABNF\Primitives:

Public Member Functions

 simpleEither (array $parse)
 
 simpleSequence (array $parse)
 
 until (?int $max, $parse)
 
 parserFrom ($x)
 

Private Member Functions

 or2 (Closure $f, Closure $g)
 
 seq (Closure $f, Closure $g)
 
 eq (int $atom)
 
 variadic (callable $call, array $parse)
 Makes a variadic function from a binary one (left associative and requires at leat 1 argument): f(f(a, b), c) === variadic(f, [a, b, c]);. More...
 
 mustEqual (string $expected)
 
 nop ()
 
 lazy (callable $call,... $arguments)
 

Detailed Description

@phpstan-type Continuation Closure(Result<Intermediate>): Result<Intermediate> @phpstan-type Parser Closure(Intermediate, Continuation): Result<Intermediate>

Definition at line 32 of file Primitives.php.

Member Function Documentation

◆ eq()

ILIAS\Refinery\Parser\ABNF\Primitives::eq ( int  $atom)
private
Parameters
int$atom
Returns
Parser

Definition at line 102 of file Primitives.php.

102 : Closure
103 {
104 return static fn(Intermediate $x, Closure $cc): Result => $cc(
105 $atom === $x->value() ? $x->accept() : $x->reject()
106 );
107 }

References ILIAS\Refinery\Parser\ABNF\Intermediate\accept(), ILIAS\Refinery\Parser\ABNF\Intermediate\reject(), and ILIAS\Refinery\Parser\ABNF\Intermediate\value().

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\mustEqual().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lazy()

ILIAS\Refinery\Parser\ABNF\Primitives::lazy ( callable  $call,
  $arguments 
)
private

Definition at line 149 of file Primitives.php.

149 : Closure
150 {
151 return static fn(Intermediate $x, Closure $cc): Result => (
152 ($call(...$arguments))($x, $cc)
153 );
154 }

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\until().

+ Here is the caller graph for this function:

◆ mustEqual()

ILIAS\Refinery\Parser\ABNF\Primitives::mustEqual ( string  $expected)
private
Parameters
string$expected
Returns
Parser

Definition at line 128 of file Primitives.php.

128 : Closure
129 {
130 if (strlen($expected) === 1) {
131 return $this->eq(ord($expected));
132 } elseif ('' === $expected) {
133 return $this->nop();
134 }
135
136 return $this->simpleSequence(str_split($expected));
137 }

References ILIAS\Refinery\Parser\ABNF\Primitives\eq(), ILIAS\Refinery\Parser\ABNF\Primitives\nop(), and ILIAS\Refinery\Parser\ABNF\Primitives\simpleSequence().

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\parserFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nop()

ILIAS\Refinery\Parser\ABNF\Primitives::nop ( )
private
Returns
Parser

Definition at line 142 of file Primitives.php.

142 : Closure
143 {
144 return static fn(Intermediate $x, Closure $cc): Result => (
145 $cc(new Ok($x))
146 );
147 }

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\mustEqual(), and ILIAS\Refinery\Parser\ABNF\Primitives\until().

+ Here is the caller graph for this function:

◆ or2()

ILIAS\Refinery\Parser\ABNF\Primitives::or2 ( Closure  $f,
Closure  $g 
)
private

Definition at line 75 of file Primitives.php.

75 : Closure
76 {
77 return static fn(Intermediate $x, Closure $cc): Result => (
78 $f($x, $cc)->except(static fn(): Result => $g($x, $cc))
79 );
80 }

References Vendor\Package\$f.

◆ parserFrom()

ILIAS\Refinery\Parser\ABNF\Primitives::parserFrom (   $x)
Parameters
Parser | string$x
Returns
Parser

Definition at line 70 of file Primitives.php.

70 : Closure
71 {
72 return $x instanceof Closure ? $x : $this->mustEqual($x);
73 }

References ILIAS\Refinery\Parser\ABNF\Primitives\mustEqual().

+ Here is the call graph for this function:

◆ seq()

ILIAS\Refinery\Parser\ABNF\Primitives::seq ( Closure  $f,
Closure  $g 
)
private
Parameters
Parser$f
Parser$g
Returns
Parser

Definition at line 87 of file Primitives.php.

87 : Closure
88 {
89 return static fn(Intermediate $x, Closure $cc): Result => $f(
90 $x,
91 static fn(Result $x): Result => (
92 $x->then(static fn(Intermediate $x): Result => $g($x, $cc))
93 ->except(static fn($error): Result => $cc(new Error($error)))
94 )
95 );
96 }
ilErrorHandling $error
Definition: class.ilias.php:69

References ILIAS\$error, and Vendor\Package\$f.

◆ simpleEither()

ILIAS\Refinery\Parser\ABNF\Primitives::simpleEither ( array  $parse)

Definition at line 34 of file Primitives.php.

34 : Closure
35 {
36 return $this->variadic([$this, 'or2'], $parse);
37 }
variadic(callable $call, array $parse)
Makes a variadic function from a binary one (left associative and requires at leat 1 argument): f(f(a...
Definition: Primitives.php:117

References ILIAS\Refinery\Parser\ABNF\Primitives\variadic().

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\until().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleSequence()

ILIAS\Refinery\Parser\ABNF\Primitives::simpleSequence ( array  $parse)

Definition at line 39 of file Primitives.php.

39 : Closure
40 {
41 return $this->variadic([$this, 'seq'], $parse);
42 }

References ILIAS\Refinery\Parser\ABNF\Primitives\variadic().

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\mustEqual(), and ILIAS\Refinery\Parser\ABNF\Primitives\until().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ until()

ILIAS\Refinery\Parser\ABNF\Primitives::until ( ?int  $max,
  $parse 
)
Parameters
null | int$max
Parser | string$parse
Returns
Parser

Definition at line 49 of file Primitives.php.

49 : Closure
50 {
51 if (0 === $max) {
52 return $this->nop();
53 }
54
55 $max = null === $max ? null : $max - 1;
56
57 return $this->simpleEither([
58 $this->nop(),
59 $this->simpleSequence([
60 $parse,
61 $this->lazy([$this, 'until'], $max, $parse)
62 ])
63 ]);
64 }
lazy(callable $call,... $arguments)
Definition: Primitives.php:149

References ILIAS\Refinery\Parser\ABNF\Primitives\lazy(), ILIAS\Refinery\Parser\ABNF\Primitives\nop(), ILIAS\Refinery\Parser\ABNF\Primitives\simpleEither(), and ILIAS\Refinery\Parser\ABNF\Primitives\simpleSequence().

+ Here is the call graph for this function:

◆ variadic()

ILIAS\Refinery\Parser\ABNF\Primitives::variadic ( callable  $call,
array  $parse 
)
private

Makes a variadic function from a binary one (left associative and requires at leat 1 argument): f(f(a, b), c) === variadic(f, [a, b, c]);.

Parameters
callable(Parser,Parser)Parser $call
(Parser|string)[]$parse
Returns
Parser

Definition at line 117 of file Primitives.php.

117 : Closure
118 {
119 $parse = array_map([$this, 'parserFrom'], $parse);
120
121 return array_reduce(array_slice($parse, 1), $call, $parse[0]);
122 }

Referenced by ILIAS\Refinery\Parser\ABNF\Primitives\simpleEither(), and ILIAS\Refinery\Parser\ABNF\Primitives\simpleSequence().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: