ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\Refinery\Parser\ABNF\Brick Class Reference

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

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

Public Member Functions

 __construct ()
 
 apply (Closure $parse, string $input)
 
 toTransformation (Closure $parse)
 
 range (int $start, int $end)
 
 alpha ()
 
 digit ()
 
 either (array $parsers)
 
 sequence (array $parsers)
 
 repeat (int $min, ?int $max, $parse)
 
 transformation (Transformation $transformation, Closure $parse)
 

Private Member Functions

 namesFromKeys (array $array)
 
 consume (Closure $parse, Intermediate $intermediate)
 It just checks if the given input is fully consumed after parsing and rejects the input otherwise. More...
 

Private Attributes

Transform $transform
 
Primitives $primitives
 

Detailed Description

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

Definition at line 34 of file Brick.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\Parser\ABNF\Brick::__construct ( )

Definition at line 39 of file Brick.php.

References ILIAS\Refinery\transform().

40  {
41  $this->transform = new Transform();
42  $this->primitives = new Primitives();
43  }
+ Here is the call graph for this function:

Member Function Documentation

◆ alpha()

ILIAS\Refinery\Parser\ABNF\Brick::alpha ( )
Returns
Parser

Definition at line 78 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\range().

Referenced by ILIAS\Data\LanguageTag\definition().

78  : Closure
79  {
80  return $this->primitives->simpleEither([
81  $this->range(0x41, 0x5A),
82  $this->range(0x61, 0x7A),
83  ]);
84  }
range(int $start, int $end)
Definition: Brick.php:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ apply()

ILIAS\Refinery\Parser\ABNF\Brick::apply ( Closure  $parse,
string  $input 
)

Definition at line 45 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\consume(), and ILIAS\Refinery\Parser\ABNF\Intermediate\transform().

Referenced by ILIAS\Refinery\Parser\ABNF\Brick\toTransformation().

45  : Result
46  {
47  return $this->consume($parse, new Intermediate($input))->then(static fn(Intermediate $x): Result => (
48  $x->transform(static fn($value): Result => (
49  new Ok(is_array($value) && !is_string(key($value)) ? current($value) : $value)
50  ))
51  ));
52  }
consume(Closure $parse, Intermediate $intermediate)
It just checks if the given input is fully consumed after parsing and rejects the input otherwise...
Definition: Brick.php:157
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ consume()

ILIAS\Refinery\Parser\ABNF\Brick::consume ( Closure  $parse,
Intermediate  $intermediate 
)
private

It just checks if the given input is fully consumed after parsing and rejects the input otherwise.

Parameters
Parser$parse
Intermediate$intermediate
Returns
Result<Intermediate>

Definition at line 157 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Intermediate\done(), and ILIAS\Data\Result\then().

Referenced by ILIAS\Refinery\Parser\ABNF\Brick\apply().

157  : Result
158  {
159  return $parse($intermediate, static fn(Result $x): Result => $x->then(
160  static fn(Intermediate $x): Result => $x->done() ? new Ok($x) : new Error('EOF not reached.')
161  ));
162  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digit()

ILIAS\Refinery\Parser\ABNF\Brick::digit ( )
Returns
Parser

Definition at line 89 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\range().

Referenced by ILIAS\Data\LanguageTag\definition().

89  : Closure
90  {
91  return $this->range(0x30, 0x39);
92  }
range(int $start, int $end)
Definition: Brick.php:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ either()

ILIAS\Refinery\Parser\ABNF\Brick::either ( array  $parsers)

Definition at line 94 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\namesFromKeys().

Referenced by ILIAS\Data\LanguageTag\definition().

94  : Closure
95  {
96  return $this->primitives->simpleEither($this->namesFromKeys($parsers));
97  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ namesFromKeys()

ILIAS\Refinery\Parser\ABNF\Brick::namesFromKeys ( array  $array)
private
Parameters
array<(string|int),(string|Parser)>$array
Returns
Parser[]

Definition at line 139 of file Brick.php.

References ILIAS\Refinery\transform().

Referenced by ILIAS\Refinery\Parser\ABNF\Brick\either(), and ILIAS\Refinery\Parser\ABNF\Brick\sequence().

139  : array
140  {
141  return array_map(
142  function ($key) use ($array): Closure {
143  $current = $this->primitives->parserFrom($array[$key]);
144  return is_string($key) ? $this->transform->as($key, $current) : $current;
145  },
146  array_keys($array)
147  );
148  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ range()

ILIAS\Refinery\Parser\ABNF\Brick::range ( int  $start,
int  $end 
)
Parameters
int$start
int$end
Returns
Parser

Definition at line 68 of file Brick.php.

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\Brick\alpha(), ILIAS\Data\LanguageTag\definition(), and ILIAS\Refinery\Parser\ABNF\Brick\digit().

68  : Closure
69  {
70  return static fn(Intermediate $x, Closure $cc): Result => $cc(
71  $x->value() >= $start && $x->value() <= $end ? $x->accept() : $x->reject()
72  );
73  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ repeat()

ILIAS\Refinery\Parser\ABNF\Brick::repeat ( int  $min,
?int  $max,
  $parse 
)
Parameters
int$min
null | int$max
Parser | string$parse
Returns
Parser

Definition at line 114 of file Brick.php.

References null.

Referenced by ILIAS\Data\LanguageTag\definition().

114  : Closure
115  {
116  $min = max(0, $min);
117  $max = null === $max ? null : max($min, $max) - $min;
118 
119  return $this->primitives->simpleSequence([
120  ...array_fill(0, $min, $parse),
121  $this->primitives->until($max, $parse)
122  ]);
123  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ sequence()

ILIAS\Refinery\Parser\ABNF\Brick::sequence ( array  $parsers)
Parameters
(Parser|string)[]$parse
Returns
Parser

Definition at line 103 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\namesFromKeys().

Referenced by ILIAS\Data\LanguageTag\definition().

103  : Closure
104  {
105  return $this->primitives->simpleSequence($this->namesFromKeys($parsers));
106  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toTransformation()

ILIAS\Refinery\Parser\ABNF\Brick::toTransformation ( Closure  $parse)
Parameters
Parser$parse
Returns
Transformation

Definition at line 58 of file Brick.php.

References ILIAS\Refinery\Parser\ABNF\Brick\apply().

58  : Transformation
59  {
60  return new Custom(fn($input) => $this->apply($parse, $input)->value());
61  }
apply(Closure $parse, string $input)
Definition: Brick.php:45
+ Here is the call graph for this function:

◆ transformation()

ILIAS\Refinery\Parser\ABNF\Brick::transformation ( Transformation  $transformation,
Closure  $parse 
)
Parameters
Transformation$transformation
Parser$parser
Returns
Parser

Definition at line 130 of file Brick.php.

References ILIAS\Refinery\transform().

Referenced by ILIAS\Data\LanguageTag\definition().

130  : Closure
131  {
132  return $this->transform->to($transformation, $parse);
133  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $primitives

Primitives ILIAS\Refinery\Parser\ABNF\Brick::$primitives
private

Definition at line 37 of file Brick.php.

◆ $transform

Transform ILIAS\Refinery\Parser\ABNF\Brick::$transform
private

Definition at line 36 of file Brick.php.


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