#!/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""" """ (_, body) = plist_bytes.split(b"