TextMate-style syntax highlighting in PHP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
678 B

<?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\Grammar;
/**
* Acts as a sort of lazy weak reference for a base grammar in a grammar.
*/
class BaseReference extends Reference {
protected ?\WeakReference $object;
public function get(): Grammar {
if ($this->object !== null) {
return $this->object->get();
}
$grammar = $this->_ownerGrammar->get();
do {
$result = $grammar;
} while ($grammar = $grammar->ownerGrammar);
$this->object = $result;
return $result->get();
}
}