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.
 
 

56 lines
1.3 KiB

<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE file for details */
declare(strict_types=1);
namespace MensBeam\Lit\Scope;
class Scope extends Node {
protected bool $_anchorToPrevious;
protected array $_atoms = [];
protected ?\WeakReference $_parent;
public function __construct(?Scope $parent = null, bool $anchorToPrevious = false, string ...$atoms) {
$this->_anchorToPrevious = $anchorToPrevious;
$this->_atoms = $atoms;
$this->_parent = ($parent !== null) ? \WeakReference::create($parent) : null;
}
public function matches(Scope $scope): bool {
foreach ($this->_atoms as $index => $atom) {
if ($atom === '*') {
continue;
}
if ($atom !== $scope->atoms[$index]) {
return false;
}
}
return true;
}
public function __get(string $name) {
if ($name === 'parent') {
return ($this->_parent !== null) ? $this->_parent->get() : null;
}
return parent::__get($name);
}
public function __toString(): string {
$result = '';
if ($this->_anchorToPrevious) {
$result .= '< ';
}
$result .= implode('.', $this->_atoms);
return $result;
}
}