return new self($scopeName, $patterns, $name, $contentRegex, $firstLineMatch, $injections, $repository);
}
protected static function parseJSONPattern(array $pattern): GrammarInclude|Pattern|null {
if (array_keys($pattern) === [ 'include' ]) {
return new GrammarInclude($pattern['include']);
}
$p = [
'name' => null,
'contentName' => null,
'begin' => null,
'end' => null,
'match' => null,
'patterns' => null,
'captures' => null,
'beginCaptures' => null,
'endCaptures' => null,
'applyEndPatternLast' => false
];
$modified = false;
foreach ($pattern as $key => $value) {
switch ($key) {
case 'applyEndPatternLast':
assert(is_bool($value) || (is_int($value) && ($value === 0 || $value === 1)), new \Exception("The value for applyEndPatternLast must be either a boolean, 0, or 1\n"));
$value = (bool)$value;
case 'name':
case 'contentName':
$p[$key] = $value;
$modified = true;
break;
case 'begin':
case 'end':
case 'match':
$p[$key] = "/$value/";
$modified = true;
break;
case 'captures':
case 'beginCaptures':
case 'endCaptures':
assert(is_array($value), new \Exception("Array value expected for '$key', found " . gettype($value) . "\n"));
if (count($value) === 0) {
continue 2;
}
$kk = array_keys($value);
$v = array_values($value);
// Skipping that bad three k variable name here... :)
foreach ($kk as &$kkkk) {
if (is_int($kkkk)) {
continue;
}
assert(strspn($kkkk, '0123456789') === strlen($kkkk), new \Exception("\"$kkkk\" is not castable to an integer for use in a capture list\n"));