-
Notifications
You must be signed in to change notification settings - Fork 15
/
pattern_expr_pair.go
45 lines (37 loc) · 993 Bytes
/
pattern_expr_pair.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
package rel
import (
"context"
"fmt"
)
// PatternExprPair a Pattern/Expr pair
type PatternExprPair struct {
pattern Pattern
expr Expr
}
// NewPatternExprPair returns a new PatternExprPair.
func NewPatternExprPair(pattern Pattern, expr Expr) PatternExprPair {
return PatternExprPair{pattern, expr}
}
// Pattern returns the PatternExprPair's Pattern.
func (p PatternExprPair) Pattern() Pattern {
return p.pattern
}
// Expr returns the PatternExprPair's Expr.
func (p PatternExprPair) Expr() Expr {
return p.expr
}
// String returns a string representation of a PatternPair.
func (p PatternExprPair) String() string {
return fmt.Sprintf("%s: %s", p.pattern, p.expr)
}
// Bind implements Pattern.Bind.
func (p PatternExprPair) Bind(
ctx context.Context,
local Scope,
value Value,
) (context.Context, Scope, error) {
return p.pattern.Bind(ctx, local, value)
}
func (p PatternExprPair) eval(ctx context.Context, local Scope) (Value, error) {
return p.expr.Eval(ctx, local)
}