-
Notifications
You must be signed in to change notification settings - Fork 0
/
expr.go
64 lines (49 loc) · 1.04 KB
/
expr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package clade
import (
"fmt"
"strings"
"github.com/lesomnus/boolal"
"github.com/lesomnus/pl"
"gopkg.in/yaml.v3"
)
type Pipeline pl.Pl
func (p *Pipeline) AsPl() *pl.Pl {
return (*pl.Pl)(p)
}
func (p *Pipeline) UnmarshalYAML(node *yaml.Node) error {
expr := ""
if err := node.Decode(&expr); err != nil {
return err
}
var (
pipeline *pl.Pl
err error
)
if strings.HasPrefix(expr, "(") && strings.HasSuffix(expr, ")") {
pipeline, err = pl.ParseString(expr)
} else {
fn, _ := pl.NewFn("pass", expr)
pipeline = pl.NewPl(fn)
}
if err != nil {
return fmt.Errorf("parse pipeline: %w", err)
}
*p = Pipeline(*pipeline)
return nil
}
type BoolAlgebra boolal.Expr
func (a *BoolAlgebra) Expr() *boolal.Expr {
return (*boolal.Expr)(a)
}
func (a *BoolAlgebra) UnmarshalYAML(node *yaml.Node) error {
expr := ""
if err := node.Decode(&expr); err != nil {
return err
}
algebra, err := boolal.ParseString(expr)
if err != nil {
return fmt.Errorf("parse boolean algebra: %w", err)
}
*a = *(*BoolAlgebra)(algebra)
return nil
}