scpt/ast.go

42 lines
671 B
Go
Raw Normal View History

2021-03-01 17:11:22 +00:00
package scpt
type AST struct {
Commands []*Command `@@*`
}
type Command struct {
Vars []*Var `( @@`
Calls []*FuncCall `| @@ )`
}
type FuncCall struct {
Name string `@Ident`
Args []*Arg `@@*`
}
type Arg struct {
Key string `"with" @Ident`
Value *Value `@@`
}
type Var struct {
Key string `"set" @Ident "to"`
Value *Value `@@`
}
type Value struct {
String *string ` @String`
Float *float64 `| @Float`
Integer *int64 `| @Int`
Bool *Bool `| @("true" | "false")`
SubCmd *FuncCall `| "(" @@ ")"`
VarVal *string `| "$" @Ident`
}
type Bool bool
func (b *Bool) Capture(values []string) error {
*b = values[0] == "true"
return nil
}