Python API Overview¶
The Python implementation of Grammar School provides a clean, decorator-based API for building DSLs.
Quick Example¶
from grammar_school import Grammar, method
class MyDSL(Grammar):
@method
def greet(self, name):
print(f"Hello, {name}!")
dsl = MyDSL()
dsl.execute('greet(name="World")')
Key Components¶
Grammar¶
The Grammar class orchestrates parsing and interpretation:
class MyDSL(Grammar):
@method
def greet(self, name):
print(f"Hello, {name}!")
dsl = MyDSL()
dsl.execute('greet(name="World")')
Decorators¶
@method- Marks a method as a DSL handler (contains implementation)@rule- Defines custom grammar rules (advanced)
Core Types¶
Value- AST value nodeArg- Named argumentCall- Function callCallChain- Chain of calls
See Also¶
- API Reference - Complete API documentation
- Core Types - Detailed type information
- Grammar - Grammar definition guide