diff --git a/lib/Grammar.php b/lib/Grammar.php index ab83bc2..0f1968b 100644 --- a/lib/Grammar.php +++ b/lib/Grammar.php @@ -34,9 +34,10 @@ class Grammar { protected ?PatternList $_patterns; protected ?Repository $_repository; protected ?string $_scopeName; + protected ?string $_contentScopeName; - public function __construct(?string $scopeName = null, ?PatternList $patterns = null, ?string $name = null, ?string $contentRegex = null, ?string $firstLineMatch = null, ?InjectionList $injections = null, ?Repository $repository = null, ?Grammar $ownerGrammar = null) { + public function __construct(?string $scopeName = null, ?string $contentScopeName = null, ?PatternList $patterns = null, ?string $name = null, ?string $contentRegex = null, ?string $firstLineMatch = null, ?InjectionList $injections = null, ?Repository $repository = null, ?Grammar $ownerGrammar = null) { $this->_name = $name; $this->_scopeName = $scopeName; $this->_patterns = $patterns; @@ -50,7 +51,7 @@ class Grammar { /** Clones the supplied grammar with this grammar set as its owner grammar */ public function adoptGrammar(self $grammar): self { - return new self($grammar->name, $grammar->scopeName, $grammar->patterns, $grammar->contentRegex, $grammar->firstLineMatch, $grammar->injections, $this, $grammar->repository); + return new self($grammar->name, $grammar->scopeName, $grammar->contentScopeName, $grammar->patterns, $grammar->contentRegex, $grammar->firstLineMatch, $grammar->injections, $grammar->repository, $this); } @@ -75,6 +76,7 @@ class Grammar { $this->_name = $json['name'] ?? null; $this->_scopeName = $json['scopeName']; + $this->_contentScopeName = $json['contentScopeName'] ?? null; $this->_contentRegex = (isset($json['contentRegex'])) ? "/{$json['contentRegex']}/" : null; $this->_firstLineMatch = (isset($json['firstLineMatch'])) ? "/{$json['firstLineMatch']}/" : null; diff --git a/lib/Grammar/GrammarInclude.php b/lib/Grammar/GrammarInclude.php deleted file mode 100644 index bf702f4..0000000 --- a/lib/Grammar/GrammarInclude.php +++ /dev/null @@ -1,39 +0,0 @@ -_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; - } - } -} \ No newline at end of file diff --git a/lib/Grammar/GrammarReference.php b/lib/Grammar/GrammarReference.php index 8ff96ab..ec3b77b 100644 --- a/lib/Grammar/GrammarReference.php +++ b/lib/Grammar/GrammarReference.php @@ -5,15 +5,13 @@ declare(strict_types=1); namespace dW\Lit\Grammar; -use dW\Lit\FauxReadOnly, - dW\Lit\Grammar; +use dW\Lit\Grammar; + /** * Acts as a sort of lazy reference for entire grammars in grammars. */ class GrammarReference extends Reference { - use FauxReadOnly; - protected ?Grammar $object; protected \WeakReference $ownerGrammar; protected string $_scopeName; diff --git a/lib/Grammar/ImmutableList.php b/lib/Grammar/ImmutableList.php index b30cb0d..659edfe 100644 --- a/lib/Grammar/ImmutableList.php +++ b/lib/Grammar/ImmutableList.php @@ -44,7 +44,7 @@ abstract class ImmutableList implements \ArrayAccess, \Countable, \Iterator { if (!isset($this->storage[$offset])) { throw new Exception(Exception::LIST_INVALID_INDEX, __CLASS__, $offset); } - + return $this->storage[$offset]; } diff --git a/lib/Grammar/Pattern.php b/lib/Grammar/Pattern.php index 1fb64a7..7b27d02 100644 --- a/lib/Grammar/Pattern.php +++ b/lib/Grammar/Pattern.php @@ -5,13 +5,11 @@ declare(strict_types=1); namespace dW\Lit\Grammar; -use dW\Lit\FauxReadOnly; use dW\Lit\Grammar; -/** Contains patterns responsible for matching a portion of the document */ -class Pattern { - use FauxReadOnly; +/** Contains patterns responsible for matching a portion of the document */ +class Pattern extends Rule { protected bool $_applyEndPatternLast = false; protected ?string $_begin; protected ?CaptureList $_beginCaptures; diff --git a/lib/Grammar/Reference.php b/lib/Grammar/Reference.php index 1adfc98..be48461 100644 --- a/lib/Grammar/Reference.php +++ b/lib/Grammar/Reference.php @@ -9,4 +9,4 @@ namespace dW\Lit\Grammar; /** * Acts as a sort of lazy reference for including self in a grammar. */ -abstract class Reference {} \ No newline at end of file +abstract class Reference extends Rule {} \ No newline at end of file diff --git a/lib/Grammar/RepositoryReference.php b/lib/Grammar/RepositoryReference.php index ef4cf93..2c5ef11 100644 --- a/lib/Grammar/RepositoryReference.php +++ b/lib/Grammar/RepositoryReference.php @@ -5,15 +5,13 @@ declare(strict_types=1); namespace dW\Lit\Grammar; -use dW\Lit\FauxReadOnly, - dW\Lit\Grammar; +use dW\Lit\Grammar; + /** * Acts as a sort of lazy reference for repository items in grammars. */ class RepositoryReference extends Reference { - use FauxReadOnly; - protected \WeakReference $grammar; protected string $_name; protected PatternList|Pattern|null|false $object; diff --git a/lib/Grammar/Rule.php b/lib/Grammar/Rule.php new file mode 100644 index 0000000..85324bd --- /dev/null +++ b/lib/Grammar/Rule.php @@ -0,0 +1,16 @@ +data = $data; $this->grammar = $grammar; + $this->ruleStack = [ $this->grammar ]; } public function tokenize(): \Generator { - $ruleStack = [ $this->grammar ]; - foreach ($this->data as $lineNumber => $line) { yield $lineNumber => $line; }