Dustin Wilson
3 years ago
14 changed files with 241 additions and 91 deletions
@ -0,0 +1,18 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2021 Dustin Wilson et al. |
|||
* See LICENSE file for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace dW\Lit\Grammar; |
|||
|
|||
class CaptureList extends ImmutableList { |
|||
public function __construct(array $array) { |
|||
foreach ($array as $k => $v) { |
|||
assert(is_int($k), new \Exception('Integer index expected for supplied array, found ' . gettype($k) . "\n")); |
|||
assert($v instanceof GrammarInclude || $v instanceof Pattern || $v instanceof PatternList, new \Exception(__NAMESPACE__ . '\GrammarInclude, ' . __NAMESPACE__ . '\Pattern, or ' . __NAMESPACE__ . '\PatternList value expected for supplied array, found ' . gettype($v) . "\n")); |
|||
} |
|||
|
|||
$this->storage = $array; |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2021 Dustin Wilson et al. |
|||
* See LICENSE file for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace dW\Lit\Grammar; |
|||
use dW\Lit\FauxReadOnly; |
|||
|
|||
class GrammarInclude { |
|||
use FauxReadOnly; |
|||
|
|||
const BASE_TYPE = 0; |
|||
const REPOSITORY_TYPE = 1; |
|||
const SCOPE_TYPE = 2; |
|||
const SELF_TYPE = 3; |
|||
|
|||
protected ?string $_name; |
|||
protected int $_type; |
|||
|
|||
|
|||
public function __construct(string $string) { |
|||
if ($string[0] === '#') { |
|||
$this->_type = self::REPOSITORY_TYPE; |
|||
$this->_name = substr($string, 1); |
|||
} elseif ($string === '$base') { |
|||
$this->_type = self::BASE_TYPE; |
|||
} elseif ($string === '$self') { |
|||
$this->_type = self::SELF_TYPE; |
|||
} else { |
|||
$this->_type = self::SCOPE_TYPE; |
|||
$this->_name = $string; |
|||
} |
|||
} |
|||
} |
@ -1,32 +0,0 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2021 Dustin Wilson et al. |
|||
* See LICENSE file for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace dW\Lit\Grammar; |
|||
use dW\Lit\FauxReadOnly; |
|||
|
|||
class Include { |
|||
use FauxReadOnly; |
|||
|
|||
const REPOSITORY_TYPE = 0; |
|||
const SCOPE_TYPE = 1; |
|||
const SELF_TYPE = 2; |
|||
|
|||
protected ?string $name; |
|||
protected int $type; |
|||
|
|||
|
|||
public function __construct(string $string) { |
|||
if ($string[0] === '#') { |
|||
$this->type = self::REPOSITORY_TYPE; |
|||
$this->name = substr($string, 1); |
|||
} elseif ($string === '$self') { |
|||
$this->type = self::SELF_TYPE; |
|||
} |
|||
|
|||
$this->type = self::SCOPE_TYPE; |
|||
$this->name = $string; |
|||
} |
|||
} |
Loading…
Reference in new issue