dymokomi/luced-3d
Source of release 0.11.9
0.11.9 / tools / code_grammar.py
#!/usr/bin/env python3
"""Embed luced's Luce TextMate grammar as src/code_grammar.luc, so the Code
node highlights its snippets as luced highlights .lucb files.
Run from the repo root after luced's grammar changes:
python3 tools/code_grammar.py
"""
import json
import pathlib
root = pathlib.Path(__file__).resolve().parent.parent
grammar = (root.parent / "luced" / "grammars" / "luce.tmLanguage.json").read_text()
json.loads(grammar) # it must be a grammar
text = json.dumps(grammar)
(root / "src" / "code_grammar.luc").write_text(
"## Generated by tools/code_grammar.py from luced's grammars/luce.tmLanguage.json:\n"
"## the Luce TextMate grammar the Code node highlights its snippets with.\n\n"
"## The Luce grammar's JSON.\n"
f"pub func luce_grammar() -> str:\n return {text}\n")