2022-04-28 16:35:02 +00:00
|
|
|
package grammar
|
|
|
|
|
2022-05-13 13:38:19 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ json.Unmarshaler = (*Check)(nil)
|
|
|
|
_ yaml.Unmarshaler = (*Check)(nil)
|
|
|
|
)
|
|
|
|
|
2022-04-28 16:35:02 +00:00
|
|
|
type Call struct {
|
|
|
|
Module string `parser:"(@Module'.')?"`
|
|
|
|
Name string `parser:"@Ident"`
|
|
|
|
Params []Param `parser:"'(' @@? ( ',' @@ )*')'"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Filters struct {
|
|
|
|
Chain []Call `parser:"@@ ('->' @@)*"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Check struct {
|
|
|
|
Initiator *Call `parser:"@@"`
|
|
|
|
Validators *Filters `parser:"( '=>' @@)?"`
|
|
|
|
}
|
|
|
|
|
2022-05-13 13:38:19 +00:00
|
|
|
func (c *Check) UnmarshalYAML(value *yaml.Node) error {
|
|
|
|
parser, err := NewParser[Check]()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
chk, err := parser.Parse(value.Value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = *chk
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Check) UnmarshalJSON(bytes []byte) error {
|
|
|
|
parser, err := NewParser[Check]()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
chk, err := parser.ParseBytes(bytes)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = *chk
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-28 16:35:02 +00:00
|
|
|
type Script struct {
|
2022-05-08 09:00:22 +00:00
|
|
|
Checks []Check `parser:"(@@';'?)*"`
|
2022-04-28 16:35:02 +00:00
|
|
|
}
|