Go API Overview¶
The Go implementation of Grammar School uses reflection to automatically discover method handlers.
Quick Example¶
package main
import (
"context"
"fmt"
"grammar-school/go/gs"
)
type MyDSL struct{}
func (d *MyDSL) Greet(args gs.Args) error {
name := args["name"].Str
fmt.Printf("Hello, %s!\n", name)
return nil
}
func main() {
dsl := &MyDSL{}
parser := &MyParser{} // Implement gs.Parser interface
engine, _ := gs.NewEngine("", dsl, parser)
engine.Execute(context.Background(), `greet(name="World")`)
// Output: Hello, World!
}
Key Components¶
Engine¶
The Engine orchestrates parsing, interpretation, and execution:
Method Handlers¶
Method handlers must match this signature:
The Engine uses reflection to automatically discover and register methods with this signature. Methods execute directly when called - no Action return needed.
Core Types¶
Value/ValueKind- AST value nodeArg- Named argumentCall- Function callCallChain- Chain of callsArgs- Map of string to ValueParser- Pluggable parser interface
See Also¶
- API Reference - Complete API documentation
- Core Types - Detailed type information
- Engine - Engine usage guide