-
Notifications
You must be signed in to change notification settings - Fork 0
Template Generator
Benedict Albrecht edited this page May 20, 2026
·
7 revisions
The Crodox Template Generator is a Python script that produces starter Crodox grammar definitions for supported programming languages.
python crodox_template_generator.py <language>
python crodox_template_generator.py <language> --output <file># Print Python definition to stdout
python crodox_template_generator.py python
# Write to a file
python crodox_template_generator.py python --output python.crodox| Language | Command |
|---|---|
| Python | python crodox_template_generator.py python |
To add a new language, edit crodox_template_generator.py:
-
Create a new generator function:
def generate_mylang() -> str: lines = [ '<~"FROM".ext~>', ' # ... your objects here ...', '<~>', ] return '\n'.join(lines) + '\n'
-
Register it in the
LANGUAGESdictionary:LANGUAGES: dict[str, Callable[[], str]] = { "python": generate_python, "mylang": generate_mylang, }
-
Run it:
python crodox_template_generator.py mylang
Save the following as crodox_template_generator.py:
Click to expand the full script
"""
Crodox Template Generator
Generates starter Crodox grammar definition files for supported programming languages.
Usage:
python crodox_template_generator.py <language> [--output <file>]
Example:
python crodox_template_generator.py python
python crodox_template_generator.py python --output python.crodox
"""
import argparse
from typing import Callable
def generate_python() -> str:
tq = '"""'
sq = "'''"
lines = [
'<~"FROM".py~>',
'',
' <*comment_line*> # -->> \\n <*>',
f' <*comment_block*> <| {tq} -->> {tq} <||> {sq} -->> {sq} |> <*>',
'',
' <*()*> ( <---> ) <*>',
' <*[]*> [ <---> ] <*>',
' <*{}*> { <---> } <*>',
'',
' <:import:>',
' import <<name:up>> <| as <<name:up>> <||> |> \\n',
' <:>',
'',
' <:from_import:>',
' from <<"FROM">> import <| <<name:up>> <||> ( <? <<name:up>> <| , <||> |> ?> ) |> \\n',
' <:>',
'',
' <:decorator:>',
" @ <<'name'>> <| ( <? <| <<'name'>> <||> ' <<'name'>> ' <||> \" <<'name'>> \" <||> <<name>> |> <| , <||> |> ?> ) <||> |> \\n",
' <:>',
'',
' <:variable:>',
" <<name>> <| : <<'name'>> <||> |> = -->> \\n",
' <:>',
'',
' <:parameter:>',
" <<name>> <| : <<'name'>> <||> |> <| = -->> <| , <||> ) |> <||> <| , <||> ) |> |>",
' <:>',
'',
' <:function:>',
" <| async <||> |> def <<name:up>> ( <? <-{parameter}-> ?> ) <| -> <<'name'>> <||> |> : <--->",
' <:>',
'',
' <:class:>',
" class <<name:up>> <| ( <? <<'name'>> <| , <||> |> ?> ) <||> |> : <-function->",
' <:>',
'',
' <:return:>',
' return -->> \\n',
' <:>',
'',
' <:raise:>',
" raise <<'name'>> ( -->> ) \\n",
' <:>',
'',
' <:if:> if -->> : <--->',
' <:>',
'',
' <:elif:> elif -->> : <--->',
' <:>',
'',
' <:else:> else : <--->',
' <:>',
'',
' <:for:> for <<name>> in -->> : <--->',
' <:>',
'',
' <:while:> while -->> : <--->',
' <:>',
'',
' <:try:> try : <--->',
' <:>',
'',
' <:except:>',
" except <| <<'name'>> <| as <<name>> <||> |> <||> |> : <--->",
' <:>',
'',
' <:finally:> finally : <--->',
' <:>',
'',
' <:with:> with -->> as <<name>> : <--->',
' <:>',
'',
' <:assert:> assert -->> \\n',
' <:>',
'',
' <:pass:> pass \\n',
' <:>',
'',
'<~>',
]
return '\\n'.join(lines) + '\\n'
LANGUAGES: dict[str, Callable[[], str]] = {
"python": generate_python,
}
def main() -> None:
parser = argparse.ArgumentParser(
description="Generate a starter Crodox grammar definition for a programming language.",
)
parser.add_argument(
"language",
choices=sorted(LANGUAGES.keys()),
help="Target language for the Crodox definition",
)
parser.add_argument(
"--output", "-o",
help="Output file path (default: stdout)",
)
args = parser.parse_args()
template = LANGUAGES[args.language]()
if args.output:
with open(args.output, "w", encoding="utf-8") as f:
f.write(template)
print(f"Wrote Crodox definition to {args.output}")
else:
print(template)
if __name__ == "__main__":
main()Alternatively, clone the wiki repo to get the script directly:
git clone https://crodox-software-gmbh.ghe.com/crodox/Wiki.wiki.git- Getting Started
- Sign-Up
- Home Screen
- Creating Your First Template
- Template Editor
- Application Navigation
- Syntax Overview
- Workflow: End-to-End
- Workflow: Test with simpleDemo
- Workflow: Build Template from angularTemp
- Demo Repositories
- Template
- Workbench
- GitHub Integration
- GitHub App Installation
- GitHub Repository Setup
- GitHub Re-linking
- Settings
- Overview
- Declarations
- Types
- Scoping