|
@ -11,8 +11,14 @@ use dW\Lit\Grammar\CaptureList, |
|
|
dW\Lit\Grammar\InjectionList, |
|
|
dW\Lit\Grammar\InjectionList, |
|
|
dW\Lit\Grammar\Pattern, |
|
|
dW\Lit\Grammar\Pattern, |
|
|
dW\Lit\Grammar\PatternList, |
|
|
dW\Lit\Grammar\PatternList, |
|
|
|
|
|
dW\Lit\Grammar\Registry, |
|
|
dW\Lit\Grammar\Repository; |
|
|
dW\Lit\Grammar\Repository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* When the input data is read line-by-line a grammar object is used as a set of |
|
|
|
|
|
* instructions as to what to match and highlight |
|
|
|
|
|
*/ |
|
|
class Grammar { |
|
|
class Grammar { |
|
|
use FauxReadOnly; |
|
|
use FauxReadOnly; |
|
|
|
|
|
|
|
@ -25,7 +31,7 @@ class Grammar { |
|
|
protected string $_scopeName; |
|
|
protected string $_scopeName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(string $scopeName, PatternList $patterns, ?string $name = null, ?string $contentRegex = null, ?string $firstLineMatch = null, ?InjectionList $injections = null, ?Repository $repository = null) { |
|
|
public function __construct(string $scopeName, PatternList $patterns, ?string $name = null, ?string $contentRegex = null, ?string $firstLineMatch = null, ?InjectionList $injections = null, ?Repository $repository = null, bool $register = false) { |
|
|
$this->_name = $name; |
|
|
$this->_name = $name; |
|
|
$this->_scopeName = $scopeName; |
|
|
$this->_scopeName = $scopeName; |
|
|
$this->_patterns = $patterns; |
|
|
$this->_patterns = $patterns; |
|
@ -33,10 +39,14 @@ class Grammar { |
|
|
$this->_firstLineMatch = $firstLineMatch; |
|
|
$this->_firstLineMatch = $firstLineMatch; |
|
|
$this->_injections = $injections; |
|
|
$this->_injections = $injections; |
|
|
$this->_repository = $repository; |
|
|
$this->_repository = $repository; |
|
|
|
|
|
|
|
|
|
|
|
if ($register) { |
|
|
|
|
|
Registry::set($scopeName, $this); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** Parses an Atom JSON grammar and converts to a Grammar object */ |
|
|
/** Parses an Atom JSON grammar and converts to a Grammar object */ |
|
|
public static function fromJSON(string $jsonPath): self { |
|
|
public static function fromJSON(string $jsonPath, bool $register = false): self { |
|
|
if (!is_file($jsonPath)) { |
|
|
if (!is_file($jsonPath)) { |
|
|
throw new Exception(Exception::JSON_INVALID_FILE, $jsonPath); |
|
|
throw new Exception(Exception::JSON_INVALID_FILE, $jsonPath); |
|
|
} |
|
|
} |
|
@ -89,7 +99,7 @@ class Grammar { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return new self($scopeName, $patterns, $name, $contentRegex, $firstLineMatch, $injections, $repository); |
|
|
return new self($scopeName, $patterns, $name, $contentRegex, $firstLineMatch, $injections, $repository, $register); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|