diff --git a/babi/reg.py b/babi/reg.py index 14c73a0..ad1118c 100644 --- a/babi/reg.py +++ b/babi/reg.py @@ -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})' diff --git a/tests/highlight_test.py b/tests/highlight_test.py index e79f0e5..71300a4 100644 --- a/tests/highlight_test.py +++ b/tests/highlight_test.py @@ -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')), + )