mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 08:47:47 +02:00
Fix generation of url regex for Go
This commit is contained in:
@@ -369,19 +369,25 @@ def codepoint_to_mark_map(p: Callable[..., None], mark_map: List[int]) -> Dict[i
|
||||
return rmap
|
||||
|
||||
|
||||
def classes_to_regex(classes: Iterable[str], exclude: str = '') -> Iterable[str]:
|
||||
def classes_to_regex(classes: Iterable[str], exclude: str = '', for_go: bool = True) -> Iterable[str]:
|
||||
chars: Set[int] = set()
|
||||
for c in classes:
|
||||
chars |= class_maps[c]
|
||||
for x in map(ord, exclude):
|
||||
chars.discard(x)
|
||||
|
||||
def as_string(codepoint: int) -> str:
|
||||
if codepoint < 256:
|
||||
return fr'\x{codepoint:02x}'
|
||||
if codepoint <= 0xffff:
|
||||
return fr'\u{codepoint:04x}'
|
||||
return fr'\U{codepoint:08x}'
|
||||
if for_go:
|
||||
def as_string(codepoint: int) -> str:
|
||||
if codepoint < 256:
|
||||
return fr'\x{codepoint:02x}'
|
||||
return fr'\x{{{codepoint:x}}}'
|
||||
else:
|
||||
def as_string(codepoint: int) -> str:
|
||||
if codepoint < 256:
|
||||
return fr'\x{codepoint:02x}'
|
||||
if codepoint <= 0xffff:
|
||||
return fr'\u{codepoint:04x}'
|
||||
return fr'\U{codepoint:08x}'
|
||||
|
||||
for spec in get_ranges(list(chars)):
|
||||
if isinstance(spec, tuple):
|
||||
@@ -439,13 +445,10 @@ def gen_ucd() -> None:
|
||||
f.write(raw)
|
||||
|
||||
chars = ''.join(classes_to_regex(cz, exclude='\n\r'))
|
||||
with open('kittens/hints/url_regex.py', 'w') as f:
|
||||
f.write('# generated by gen-wcwidth.py, do not edit\n\n')
|
||||
f.write(f"url_delimiters = '{chars}' # noqa")
|
||||
with open('tools/cmd/hints/url_regex.go', 'w') as f:
|
||||
f.write('// generated by gen-wcwidth.py, do not edit\n\n')
|
||||
f.write('package hints\n\n')
|
||||
f.write(f"const URL_DELIMITERS = `{chars}`")
|
||||
f.write(f'const URL_DELIMITERS = `{chars}`')
|
||||
|
||||
|
||||
def gen_names() -> None:
|
||||
|
||||
Reference in New Issue
Block a user