|
|
@ -10,39 +10,44 @@ class Filter extends Node { |
|
|
|
protected Group|Path $_child; |
|
|
|
protected int $_prefix; |
|
|
|
|
|
|
|
const SIDE_LEFT = 0; |
|
|
|
const SIDE_RIGHT = 1; |
|
|
|
const SIDE_BOTH = 2; |
|
|
|
const PREFIX_LEFT = 0; |
|
|
|
const PREFIX_RIGHT = 1; |
|
|
|
const PREFIX_BOTH = 2; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(Group|Path $child, string $prefix) { |
|
|
|
$this->_child = $child; |
|
|
|
|
|
|
|
switch ($prefix) { |
|
|
|
case 'L': $this->_prefix = self::SIDE_LEFT; |
|
|
|
case 'L': $this->_prefix = self::PREFIX_LEFT; |
|
|
|
break; |
|
|
|
case 'R': $this->_prefix = self::SIDE_RIGHT; |
|
|
|
case 'R': $this->_prefix = self::PREFIX_RIGHT; |
|
|
|
break; |
|
|
|
case 'B': $this->_prefix = self::SIDE_BOTH; |
|
|
|
case 'B': $this->_prefix = self::PREFIX_BOTH; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getPrefix(array $scopes): ?int { |
|
|
|
return ($this->matches($scopes)) ? $this->_prefix : null; |
|
|
|
} |
|
|
|
|
|
|
|
public function matches(array $scopes): bool { |
|
|
|
// No idea if prefixes are supposed to affect matches. Appears to in the |
|
|
|
// TextMate original but not in Atom's implementation... |
|
|
|
// TODO: Handle prefixes when matching; AFAIK prefixes only apply when |
|
|
|
// determining when to inject grammars. It appears there's more to it in |
|
|
|
// TextMate's original C++, but it may just be for determining "rank"? |
|
|
|
return $this->_child->matches($scopes); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function __toString(): string { |
|
|
|
switch ($this->_prefix) { |
|
|
|
case self::SIDE_LEFT: $prefix = 'L'; |
|
|
|
case self::PREFIX_LEFT: $prefix = 'L'; |
|
|
|
break; |
|
|
|
case self::SIDE_RIGHT: $prefix = 'R'; |
|
|
|
case self::PREFIX_RIGHT: $prefix = 'R'; |
|
|
|
break; |
|
|
|
case self::SIDE_BOTH: $prefix = 'B'; |
|
|
|
case self::PREFIX_BOTH: $prefix = 'B'; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|