ucl/cmdlang/ast.go

34 lines
652 B
Go
Raw Normal View History

2024-04-10 10:45:58 +00:00
package cmdlang
import (
"github.com/alecthomas/participle/v2"
"io"
)
type astLiteral struct {
Str *string `parser:"@String"`
Ident *string `parser:" | @Ident"`
}
type astCmdArg struct {
2024-04-10 12:19:11 +00:00
Literal *astLiteral `parser:"@@"`
Var *string `parser:"| '$' @Ident"`
Sub *astPipeline `parser:"| '(' @@ ')'"`
2024-04-10 10:45:58 +00:00
}
type astCmd struct {
Name string `parser:"@Ident"`
Args []astCmdArg `parser:"@@*"`
}
type astPipeline struct {
First *astCmd `parser:"@@"`
Rest []*astCmd `parser:"( '|' @@ )*"`
}
var parser = participle.MustBuild[astPipeline]()
2024-04-10 10:45:58 +00:00
func parse(r io.Reader) (*astPipeline, error) {
2024-04-10 10:45:58 +00:00
return parser.Parse("test", r)
}