-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharg.go
42 lines (36 loc) · 844 Bytes
/
arg.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
package gokdl
import (
"fmt"
)
type Arg struct {
// Value of the argument.
// It is `nil` for the KDL `null` value.
Value any
// Type annotation on the argument.
// It has the zero value if no type annotation
// exists for this argument.
TypeAnnotation TypeAnnotation
}
func (a Arg) String() string {
return fmt.Sprint(a.Value)
}
func newArg(value any, ta TypeAnnotation) Arg {
return Arg{
Value: value,
TypeAnnotation: ta,
}
}
func newIntArg(value, typeAnnot string) (Arg, error) {
val, err := parseIntValue(value, typeAnnot)
return Arg{
Value: val,
TypeAnnotation: TypeAnnotation(typeAnnot),
}, err
}
func newFloatArg(value, typeAnnot string) (Arg, error) {
val, err := parseFloatValue(value, typeAnnot)
return Arg{
Value: val,
TypeAnnotation: TypeAnnotation(typeAnnot),
}, err
}