|
@ -5,17 +5,19 @@ |
|
|
|
|
|
|
|
|
declare(strict_types=1); |
|
|
declare(strict_types=1); |
|
|
namespace dW\Lit; |
|
|
namespace dW\Lit; |
|
|
use dW\Lit\Grammar\BaseReference, |
|
|
use dW\Lit\Grammar\{ |
|
|
dW\Lit\Grammar\CaptureList, |
|
|
BaseReference, |
|
|
dW\Lit\Grammar\Exception, |
|
|
CaptureList, |
|
|
dW\Lit\Grammar\GrammarReference, |
|
|
Exception, |
|
|
dW\Lit\Grammar\InjectionList, |
|
|
GrammarReference, |
|
|
dW\Lit\Grammar\Pattern, |
|
|
InjectionList, |
|
|
dW\Lit\Grammar\PatternList, |
|
|
Pattern, |
|
|
dW\Lit\Grammar\Reference, |
|
|
PatternList, |
|
|
dW\Lit\Grammar\Repository, |
|
|
Reference, |
|
|
dW\Lit\Grammar\RepositoryReference, |
|
|
Repository, |
|
|
dW\Lit\Grammar\SelfReference; |
|
|
RepositoryReference, |
|
|
|
|
|
SelfReference |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -50,7 +52,7 @@ class Grammar { |
|
|
|
|
|
|
|
|
/** Clones the supplied grammar with this grammar set as its owner grammar */ |
|
|
/** Clones the supplied grammar with this grammar set as its owner grammar */ |
|
|
public function adoptGrammar(self $grammar): self { |
|
|
public function adoptGrammar(self $grammar): self { |
|
|
return new self($grammar->name, $grammar->scopeName, $grammar->contentScopeName, $grammar->patterns, $grammar->contentRegex, $grammar->firstLineMatch, $grammar->injections, $grammar->repository, $this); |
|
|
return new self($grammar->scopeName, $grammar->contentScopeName, $grammar->patterns, $grammar->name, $grammar->contentRegex, $grammar->firstLineMatch, $grammar->injections, $grammar->repository, $this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -76,8 +78,20 @@ class Grammar { |
|
|
$this->_name = $json['name'] ?? null; |
|
|
$this->_name = $json['name'] ?? null; |
|
|
$this->_scopeName = $json['scopeName']; |
|
|
$this->_scopeName = $json['scopeName']; |
|
|
$this->_contentScopeName = $json['contentScopeName'] ?? null; |
|
|
$this->_contentScopeName = $json['contentScopeName'] ?? null; |
|
|
$this->_contentRegex = (isset($json['contentRegex'])) ? "/{$json['contentRegex']}/" : null; |
|
|
|
|
|
$this->_firstLineMatch = (isset($json['firstLineMatch'])) ? "/{$json['firstLineMatch']}/" : null; |
|
|
if (isset($json['contentRegex'])) { |
|
|
|
|
|
$value = str_replace('/', '\/', $json['contentRegex']); |
|
|
|
|
|
$this->_contentRegex = $value; |
|
|
|
|
|
} else { |
|
|
|
|
|
$this->_contentRegex = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($json['firstLineMatch'])) { |
|
|
|
|
|
$value = str_replace('/', '\/', $json['firstLineMatch']); |
|
|
|
|
|
$this->_firstLineMatch = $value; |
|
|
|
|
|
} else { |
|
|
|
|
|
$this->_firstLineMatch = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$repository = null; |
|
|
$repository = null; |
|
|
if (isset($json['repository'])) { |
|
|
if (isset($json['repository'])) { |
|
@ -120,7 +134,7 @@ class Grammar { |
|
|
} elseif ($pattern['include'] === '$base') { |
|
|
} elseif ($pattern['include'] === '$base') { |
|
|
return new BaseReference($this); |
|
|
return new BaseReference($this); |
|
|
} elseif ($pattern['include'] === '$self') { |
|
|
} elseif ($pattern['include'] === '$self') { |
|
|
return \WeakReference::create($this); |
|
|
return SelfReference::create($this); |
|
|
} else { |
|
|
} else { |
|
|
return new GrammarReference($pattern['include'], $this); |
|
|
return new GrammarReference($pattern['include'], $this); |
|
|
} |
|
|
} |
|
@ -156,6 +170,7 @@ class Grammar { |
|
|
case 'begin': |
|
|
case 'begin': |
|
|
case 'end': |
|
|
case 'end': |
|
|
case 'match': |
|
|
case 'match': |
|
|
|
|
|
$value = str_replace('/', '\/', $value); |
|
|
$p[$key] = "/$value/"; |
|
|
$p[$key] = "/$value/"; |
|
|
$modified = true; |
|
|
$modified = true; |
|
|
break; |
|
|
break; |
|
|