Browse Source

Move Grammar\Registry to GrammarRegistry

main
Dustin Wilson 3 years ago
parent
commit
457cf39a56
  1. 1
      lib/Grammar.php
  2. 2
      lib/Grammar/Exception.php
  3. 5
      lib/Grammar/GrammarReference.php
  4. 7
      lib/GrammarRegistry.php
  5. 3
      lib/Highlight.php

1
lib/Grammar.php

@ -13,7 +13,6 @@ use dW\Lit\Grammar\BaseReference,
dW\Lit\Grammar\Pattern, dW\Lit\Grammar\Pattern,
dW\Lit\Grammar\PatternList, dW\Lit\Grammar\PatternList,
dW\Lit\Grammar\Reference, dW\Lit\Grammar\Reference,
dW\Lit\Grammar\Registry,
dW\Lit\Grammar\Repository, dW\Lit\Grammar\Repository,
dW\Lit\Grammar\RepositoryReference, dW\Lit\Grammar\RepositoryReference,
dW\Lit\Grammar\SelfReference; dW\Lit\Grammar\SelfReference;

2
lib/Grammar/Exception.php

@ -54,7 +54,7 @@ class Exception extends \Exception {
301 => 'Invalid %1$s index at offset %2$s', 301 => 'Invalid %1$s index at offset %2$s',
302 => '%1$s expected for %2$s, found %3$s', 302 => '%1$s expected for %2$s, found %3$s',
400 => 'A grammar for scope %s does not exist; one may be added using Grammar\\Registry::set' 400 => 'A grammar for scope %s does not exist; one may be added using GrammarRegistry::set'
]; ];
public function __construct(int $code, ...$args) { public function __construct(int $code, ...$args) {

5
lib/Grammar/GrammarReference.php

@ -5,7 +5,8 @@
declare(strict_types=1); declare(strict_types=1);
namespace dW\Lit\Grammar; namespace dW\Lit\Grammar;
use dW\Lit\Grammar; use dW\Lit\Grammar,
dW\Lit\GrammarRegistry;
/** /**
@ -30,7 +31,7 @@ class GrammarReference extends Reference {
return null; return null;
} }
$grammar = Registry::get($this->_scopeName); $grammar = GrammarRegistry::get($this->_scopeName);
if ($grammar === null) { if ($grammar === null) {
$this->object = false; $this->object = false;
return null; return null;

7
lib/Grammar/Registry.php → lib/GrammarRegistry.php

@ -4,11 +4,10 @@
* See LICENSE file for details */ * See LICENSE file for details */
declare(strict_types=1); declare(strict_types=1);
namespace dW\Lit\Grammar; namespace dW\Lit;
use dW\Lit\Grammar;
/** Static storage for grammars; a map of a scope string and a Grammar object */ /** Static storage for grammars; a map of a scope string and a Grammar object */
class Registry implements \IteratorAggregate { class GrammarRegistry implements \IteratorAggregate {
protected static array $storage = []; protected static array $storage = [];
public static function clear(): bool { public static function clear(): bool {
@ -30,7 +29,7 @@ class Registry implements \IteratorAggregate {
if (array_key_exists($scopeName, self::$storage)) { if (array_key_exists($scopeName, self::$storage)) {
return self::$storage[$scopeName]; return self::$storage[$scopeName];
} else { } else {
$filename = __DIR__ . "/../../data/$scopeName.json"; $filename = __DIR__ . "/../data/$scopeName.json";
if (file_exists($filename)) { if (file_exists($filename)) {
$grammar = new Grammar(); $grammar = new Grammar();
$grammar->loadJSON($filename); $grammar->loadJSON($filename);

3
lib/Highlight.php

@ -5,8 +5,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace dW\Lit; namespace dW\Lit;
use dW\Lit\Grammar\Exception, use dW\Lit\Grammar\Exception;
dW\Lit\Grammar\Registry as GrammarRegistry;
class Highlight { class Highlight {
public static function withFile(string $filepath, string $scopeName) { public static function withFile(string $filepath, string $scopeName) {

Loading…
Cancel
Save