/
attribute.go
71 lines (51 loc) · 1.48 KB
/
attribute.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
70
71
package annotation
// NameValue like `#[ident(name=value]`
type NameValue struct {
// name
Name string `parser:"@Ident '='"`
// one of follow
// String, Integer, Float, Bool,
// StringList, IntegerList, FloatList, BoolList,
Value ValueType `parser:"@@"`
}
type ValueType interface {
Type() string
}
type String struct {
Value string `parser:"@String"`
}
func (String) Type() string { return "string" }
type Integer struct {
Value int64 `parser:"@Int"`
}
func (Integer) Type() string { return "integer" }
type Float struct {
Value float64 `parser:"@Float"`
}
func (Float) Type() string { return "float" }
type Bool struct {
Value Boolean `parser:"@('true' | 'false')"`
}
func (Bool) Type() string { return "bool" }
type Boolean bool
func (b *Boolean) Capture(values []string) error {
*b = values[0] == "true"
return nil
}
type StringList struct {
Value []string `parser:"'[' (@String (',' @String)*)? ']'"`
}
func (StringList) Type() string { return "slice<string>" }
type IntegerList struct {
Value []int64 `parser:"'[' (@Int (',' @Int)*)? ']'"`
}
func (IntegerList) Type() string { return "slice<integer>" }
// NOTE: FloatList float list. must be first is float.
type FloatList struct {
Value []float64 `parser:"'[' (@Float (',' (@Float | @Int))*)? ']'"`
}
func (FloatList) Type() string { return "slice<float>" }
type BoolList struct {
Value []Boolean `parser:"'[' (@('true' | 'false') (',' @('true' | 'false'))*)? ']'"`
}
func (BoolList) Type() string { return "slice<bool>" }