Fix grammars which include \z

This commit is contained in:
Anthony Sottile
2020-03-27 18:18:16 -07:00
parent 50ad1e06f9
commit 1d3d413b93
2 changed files with 24 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ def _replace_esc(s: str, chars: str) -> str:
class _Reg:
def __init__(self, s: str) -> None:
self._pattern = s
self._pattern = _replace_esc(s, 'z')
def __repr__(self) -> str:
return f'{type(self).__name__}({self._pattern!r})'

View File

@@ -582,3 +582,26 @@ def test_begin_end_substitute_special_chars(compiler_state):
Region(1, 7, ('test', 'italic')),
Region(7, 8, ('test', 'italic')),
)
def test_backslash_z(compiler_state):
# similar to text.git-commit grammar, \z matches nothing!
compiler, state = compiler_state({
'scopeName': 'test',
'patterns': [
{'begin': '#', 'end': r'\z', 'name': 'comment'},
{'name': 'other', 'match': '.'},
],
})
state, regions1 = highlight_line(compiler, state, '# comment', True)
state, regions2 = highlight_line(compiler, state, 'other?', False)
assert regions1 == (
Region(0, 1, ('test', 'comment')),
Region(1, 9, ('test', 'comment')),
)
assert regions2 == (
Region(0, 6, ('test', 'comment')),
)