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.

70 lines
1.9 KiB

<?php
/** @license MIT
* Copyright 2021 Dustin Wilson et al.
* See LICENSE file for details */
declare(strict_types=1);
namespace dW\Lit\Scope;
class Filter extends Node {
protected Group|Path $_child;
protected bool $frozen = false;
protected int $_prefix;
const SIDE_LEFT = 0;
const SIDE_RIGHT = 1;
const SIDE_BOTH = 2;
public function __construct(Expression $parent, string $prefix) {
$this->_parent = \WeakReference::create($parent);
switch ($prefix) {
case 'L': $this->_prefix = self::SIDE_LEFT;
break;
case 'R': $this->_prefix = self::SIDE_RIGHT;
break;
case 'B': $this->_prefix = self::SIDE_BOTH;
break;
}
}
public function matches(Path $path): bool {
// No idea if prefixes are supposed to affect matches. Appears to in the
// TextMate original but not in Atom's implementation...
return $this->_child->matches($path);
}
public function __set(string $name, $value) {
if ($name !== 'child') {
$trace = debug_backtrace();
trigger_error("Cannot set undefined property $name in {$trace[0]['file']} on line {$trace[0]['line']}", E_USER_NOTICE);
}
if ($this->frozen) {
$trace = debug_backtrace();
trigger_error("Cannot set readonly $name property in {$trace[0]['file']} on line {$trace[0]['line']}", E_USER_NOTICE);
return;
}
$this->frozen = true;
$this->_child = $value;
}
public function __toString(): string {
switch ($this->_prefix) {
case self::SIDE_LEFT: $prefix = 'L';
break;
case self::SIDE_RIGHT: $prefix = 'R';
break;
case self::SIDE_BOTH: $prefix = 'B';
break;
}
return "$prefix:{$this->_child}";
}
}