-
Notifications
You must be signed in to change notification settings - Fork 0
Example Python
Benedict Albrecht edited this page Jun 2, 2026
·
6 revisions
This page demonstrates a Crodox grammar definition for Python (.py) files.
Tip: You can generate this definition automatically using the Template Generator:
python crodox_template_generator.py python
<~"FROM".py~>
<*comment_line*> # -->> \n <*>
<*comment_block*> <| """ -->> """ <||> ''' -->> ''' |> <*>
<*()*> ( <---> ) <*>
<*[]*> [ <---> ] <*>
<*{}*> { <---> } <*>
<: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}-> ?> ) -->> :
<:>
<:class:>
class <<name:up>> <| ( <? <<'name'>> <| , <||> |> ?> ) <||> |> :
<:>
<: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
<:>
<~>
| Object | Description |
|---|---|
comment_line |
Single-line comments (# ... \n) using Jump
|
comment_block |
Docstrings / block comments (""" ... """ or ''' ... ''') |
(), [], {}
|
Structural delimiters for grouping, lists, and dicts |
| Object | Description |
|---|---|
import |
import module with optional as alias - uses :up scope so the name is visible to all siblings |
from_import |
from module import name - uses path variable <<"FROM">> for cross-file dependency |
| Object | Description |
|---|---|
decorator |
@name(args) - uses reference variable <<'name'>> to link to the decorator definition without overwriting |
| Object | Description |
|---|---|
parameter |
Function parameter with optional type annotation and default value - used as a Reference inside function
|
function |
def name(params): with optional async and return type annotation. Uses :up scope and typed sub-body <-{parameter}-> for params |
class |
class Name(bases): with optional inheritance list. Uses <-function-> typed sub-body so methods depend on the class but not vice versa |
| Object | Description |
|---|---|
variable |
name = value with optional type annotation (: Type) |
| Object | Description |
|---|---|
if / elif / else
|
Conditional blocks |
for |
For loop - captures the loop variable <<name>>
|
while |
While loop |
try / except / finally
|
Exception handling - except captures the exception type and optional alias |
with |
Context manager - captures the alias <<name>>
|
return |
Return statement |
raise |
Raise statement - references the exception class |
assert |
Assert statement |
pass |
Pass placeholder |
-
No braces: Python uses
:+ indentation instead of{ }, so sub-bodies use: <--->to capture indented blocks -
:upscope: Used for imports, functions, and classes so they are visible to all siblings (matching Python's module-level scoping) -
References:
<-{parameter}->keeps parameters as variable contributors to the function, not as child nodes -
Or Statements: Used for
async/sync, optional type annotations, and string quote styles -
Jump: Used for comments and expression skipping (
-->> \n)
- 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