5 // primitiveType is the hidden implementation of the various primitive types
6 // that are exposed as variables in this package.
7 type primitiveType struct {
12 type primitiveTypeKind byte
15 primitiveTypeBool primitiveTypeKind = 'B'
16 primitiveTypeNumber primitiveTypeKind = 'N'
17 primitiveTypeString primitiveTypeKind = 'S'
20 func (t primitiveType) Equals(other Type) bool {
21 if otherP, ok := other.typeImpl.(primitiveType); ok {
22 return otherP.Kind == t.Kind
27 func (t primitiveType) FriendlyName(mode friendlyTypeNameMode) string {
29 case primitiveTypeBool:
31 case primitiveTypeNumber:
33 case primitiveTypeString:
36 // should never happen
37 panic("invalid primitive type")
41 func (t primitiveType) GoString() string {
43 case primitiveTypeBool:
45 case primitiveTypeNumber:
47 case primitiveTypeString:
50 // should never happen
51 panic("invalid primitive type")
55 // Number is the numeric type. Number values are arbitrary-precision
56 // decimal numbers, which can then be converted into Go's various numeric
57 // types only if they are in the appropriate range.
60 // String is the string type. String values are sequences of unicode codepoints
61 // encoded internally as UTF-8.
64 // Bool is the boolean type. The two values of this type are True and False.
67 // True is the truthy value of type Bool
70 // False is the falsey value of type Bool
73 // Zero is a number value representing exactly zero.
76 // PositiveInfinity is a Number value representing positive infinity
77 var PositiveInfinity Value
79 // NegativeInfinity is a Number value representing negative infinity
80 var NegativeInfinity Value
84 primitiveType{Kind: primitiveTypeNumber},
87 primitiveType{Kind: primitiveTypeString},
90 primitiveType{Kind: primitiveTypeBool},
104 PositiveInfinity = Value{
106 v: (&big.Float{}).SetInf(false),
108 NegativeInfinity = Value{
110 v: (&big.Float{}).SetInf(true),
114 // IsPrimitiveType returns true if and only if the reciever is a primitive
115 // type, which means it's either number, string, or bool. Any two primitive
116 // types can be safely compared for equality using the standard == operator
117 // without panic, which is not a guarantee that holds for all types. Primitive
118 // types can therefore also be used in switch statements.
119 func (t Type) IsPrimitiveType() bool {
120 _, ok := t.typeImpl.(primitiveType)