Starting Zig code generator with one test

This commit is contained in:
2025-05-21 23:00:35 -05:00
parent bdf7ea85d3
commit 0bf8c3ef6b
5 changed files with 217 additions and 1 deletions

50
internal/zig/ast.go Normal file
View File

@@ -0,0 +1,50 @@
package zig
// https://github.com/ziglang/zig-spec/blob/master/grammar/grammar.peg
type Root struct {
ContainerDocComment string // //! Doc Comment
ContainerMembers []*ContainerMember
}
type ContainerMember struct {
// FIXME
Decls []Decl
}
type Decl interface{}
type FnDecl struct {
Name string
Params []*ParamDecl
CallConv string
ReturnType TypeExpr
Body *Block // nil means semicolon
}
type ParamDecl struct {
DocComment string // ??? It's what it says
Name string // Can be empty
Type TypeExpr // anytype when empty
}
type Block struct {
Label string
Stmts []Stmt
}
type Stmt interface{}
type ReturnStmt struct{}
type Expr interface{}
// This will need to become a real type expr someday
type TypeExpr string
func (t TypeExpr) String() string {
if string(t) == "" {
return "anytype"
}
return string(t)
}