/
fmt.go
69 lines (52 loc) · 1.26 KB
/
fmt.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
65
66
67
68
69
package symbolic
import (
"errors"
pprint "github.com/inoxlang/inox/internal/prettyprint"
)
var (
ANY_FORMAT = &AnyFormat{}
_ = []Format{ANY_FORMAT}
ErrInvalidFormattingArgument = errors.New("invalid formatting argument")
)
type Format interface {
Pattern
Format(v Value) error
}
// An AnyFormat represents a symbolic Pattern we do not know the concrete type.
type AnyFormat struct {
NotCallablePatternMixin
SerializableMixin
}
func (p *AnyFormat) Test(v Value, state RecTestCallState) bool {
state.StartCall()
defer state.FinishCall()
_, ok := v.(Format)
return ok
}
func (p *AnyFormat) PrettyPrint(w pprint.PrettyPrintWriter, config *pprint.PrettyPrintConfig) {
w.WriteName("format")
}
func (p *AnyFormat) HasUnderlyingPattern() bool {
return false
}
func (p *AnyFormat) TestValue(Value, RecTestCallState) bool {
return true
}
func (p *AnyFormat) SymbolicValue() Value {
return ANY
}
func (p *AnyFormat) StringPattern() (StringPattern, bool) {
return nil, false
}
func (p *AnyFormat) IteratorElementKey() Value {
return ANY_INT
}
func (p *AnyFormat) IteratorElementValue() Value {
return ANY
}
func (p *AnyFormat) WidestOfType() Value {
return ANY_FORMAT
}
func (p *AnyFormat) Format(v Value) error {
return ErrInvalidFormattingArgument
}