Starting Zig code generator with one test
This commit is contained in:
50
internal/zig/ast.go
Normal file
50
internal/zig/ast.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user