/
githubmirror
/
carbon-lang
Обзор
Документация
Войти
/
githubmirror
/
carbon-lang
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
scripts/update_tm_language.py
62 строки
2 KB
Richard Smith
Make our TextMate bundle actually work in TextMate. (#7386)
19 июн 2026, 00:06
Не верифицирован
19 июн 2026, 00:06
9748507
Код
Авторство
О чём код?
#!/usr/bin/env -S uv run --script # /// script # requires-python = ">=3.12" # /// """Updates the TextMate plist grammar from the VS Code JSON grammar.""" __copyright__ = """ Part of the Carbon Language project, under the Apache License v2.0 with LLVM Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception """ import json import plistlib from pathlib import Path def main() -> None: # Find repository root. repo_root = Path(__file__).resolve().parents[1] json_path = repo_root / "utils" / "vscode" / "carbon.tmLanguage.json" plist_path = ( repo_root / "utils" / "textmate" / "Syntaxes" / "carbon.tmLanguage" ) # Read and parse the JSON grammar. with open(json_path, "r", encoding="utf-8") as f: grammar_data = json.load(f) # Generate plist bytes. plist_bytes = plistlib.dumps(grammar_data, fmt=plistlib.FMT_XML) # Replace the file header. file_header = b"""<?xml version="1.0" encoding="UTF-8"?> <!-- Part of the Carbon Language project, under the Apache License v2.0 with LLVM Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> <!-- THIS FILE IS AUTOGENERATED FROM carbon.tmLanguage.json. DO NOT EDIT. --> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> """ (_, body) = plist_bytes.split(b"<plist", 1) plist_bytes = file_header + b"<plist" + body # Write the plist grammar. with open(plist_path, "wb") as f: f.write(plist_bytes) print(f"Successfully generated {plist_path.relative_to(repo_root)}") if __name__ == "__main__": main()