Documentation ¶
Index ¶
- Variables
- func Compare(x1 XValue, x2 XValue) int
- func Describe(x XValue) string
- func Equals(x1 XValue, x2 XValue) bool
- func Format(env envs.Environment, x XValue) string
- func IsXError(x XValue) bool
- func Render(x XValue) string
- func String(x XValue) string
- func ToXArray(env envs.Environment, x XValue) (*XArray, XError)
- func ToXBoolean(x XValue) (XBoolean, XError)
- func ToXDate(env envs.Environment, x XValue) (XDate, XError)
- func ToXDateTime(env envs.Environment, x XValue) (XDateTime, XError)
- func ToXDateTimeWithTimeFill(env envs.Environment, x XValue) (XDateTime, XError)
- func ToXJSON(x XValue) (XText, XError)
- func ToXNumber(env envs.Environment, x XValue) (XNumber, XError)
- func ToXObject(env envs.Environment, x XValue) (*XObject, XError)
- func ToXText(env envs.Environment, x XValue) (XText, XError)
- func ToXTime(env envs.Environment, x XValue) (XTime, XError)
- func Truthy(x XValue) bool
- type XArray
- func (x *XArray) Count() int
- func (x *XArray) Describe() string
- func (x *XArray) Equals(o XValue) bool
- func (x *XArray) Format(env envs.Environment) string
- func (x *XArray) Get(index int) XValue
- func (x *XArray) MarshalJSON() ([]byte, error)
- func (x *XArray) Render() string
- func (x *XArray) String() string
- func (x *XArray) Truthy() bool
- type XBoolean
- func (x XBoolean) Compare(o XValue) int
- func (x XBoolean) Describe() string
- func (x XBoolean) Equals(o XValue) bool
- func (x XBoolean) Format(env envs.Environment) string
- func (x XBoolean) MarshalJSON() ([]byte, error)
- func (x XBoolean) Native() bool
- func (x XBoolean) Render() string
- func (x XBoolean) String() string
- func (x XBoolean) Truthy() bool
- func (x *XBoolean) UnmarshalJSON(data []byte) error
- type XComparable
- type XCountable
- type XDate
- func (x XDate) Compare(o XValue) int
- func (x XDate) Describe() string
- func (x XDate) Equals(o XValue) bool
- func (x XDate) Format(env envs.Environment) string
- func (x XDate) FormatCustom(env envs.Environment, layout string) (string, error)
- func (x XDate) MarshalJSON() ([]byte, error)
- func (x XDate) Native() dates.Date
- func (x XDate) Render() string
- func (x XDate) String() string
- func (x XDate) Truthy() bool
- type XDateTime
- func (x XDateTime) Compare(o XValue) int
- func (x XDateTime) Date() XDate
- func (x XDateTime) Describe() string
- func (x XDateTime) Equals(o XValue) bool
- func (x XDateTime) Format(env envs.Environment) string
- func (x XDateTime) FormatCustom(env envs.Environment, layout string, tz *time.Location) (string, error)
- func (x XDateTime) In(tz *time.Location) XDateTime
- func (x XDateTime) MarshalJSON() ([]byte, error)
- func (x XDateTime) Native() time.Time
- func (x XDateTime) Render() string
- func (x XDateTime) ReplaceTime(tm XTime) XDateTime
- func (x XDateTime) String() string
- func (x XDateTime) Time() XTime
- func (x XDateTime) Truthy() bool
- func (x *XDateTime) UnmarshalJSON(data []byte) error
- type XError
- type XFunc
- type XFunction
- func (x *XFunction) Call(env envs.Environment, params []XValue) XValue
- func (x *XFunction) Describe() string
- func (x *XFunction) Equals(o XValue) bool
- func (x *XFunction) Format(env envs.Environment) string
- func (x *XFunction) MarshalJSON() ([]byte, error)
- func (x *XFunction) Name() string
- func (x *XFunction) Render() string
- func (x *XFunction) String() string
- func (x *XFunction) Truthy() bool
- type XNumber
- func (x XNumber) Compare(o XValue) int
- func (x XNumber) Describe() string
- func (x XNumber) Equals(o XValue) bool
- func (x XNumber) Format(env envs.Environment) string
- func (x XNumber) FormatCustom(format *envs.NumberFormat, places int, groupDigits bool) string
- func (x XNumber) MarshalJSON() ([]byte, error)
- func (x XNumber) Native() decimal.Decimal
- func (x XNumber) Render() string
- func (x XNumber) String() string
- func (x XNumber) Truthy() bool
- func (x *XNumber) UnmarshalJSON(data []byte) error
- type XObject
- func (x *XObject) Count() int
- func (x *XObject) Default() XValue
- func (x *XObject) Describe() string
- func (x *XObject) Equals(o XValue) bool
- func (x *XObject) Format(env envs.Environment) string
- func (x *XObject) Get(key string) (XValue, bool)
- func (x *XObject) MarshalJSON() ([]byte, error)
- func (x *XObject) Properties() []string
- func (x *XObject) Render() string
- func (x *XObject) SetMarshalDefault(marshal bool)
- func (x *XObject) String() string
- func (x *XObject) Truthy() bool
- type XText
- func (x XText) Compare(o XValue) int
- func (x XText) Describe() string
- func (x XText) Empty() bool
- func (x XText) Equals(o XValue) bool
- func (x XText) Format(env envs.Environment) string
- func (x XText) Length() int
- func (x XText) MarshalJSON() ([]byte, error)
- func (x XText) Native() string
- func (x XText) Render() string
- func (x XText) String() string
- func (x XText) Truthy() bool
- func (x *XText) UnmarshalJSON(data []byte) error
- type XTime
- func (x XTime) Compare(o XValue) int
- func (x XTime) Describe() string
- func (x XTime) Equals(o XValue) bool
- func (x XTime) Format(env envs.Environment) string
- func (x XTime) FormatCustom(env envs.Environment, layout string) (string, error)
- func (x XTime) MarshalJSON() ([]byte, error)
- func (x XTime) Native() dates.TimeOfDay
- func (x XTime) Render() string
- func (x XTime) String() string
- func (x XTime) Truthy() bool
- type XValue
Constants ¶
This section is empty.
Variables ¶
var NilXError = NewXError(nil)
NilXError is the nil error value
var XArrayEmpty = NewXArray()
XArrayEmpty is the empty array
var XBooleanFalse = NewXBoolean(false)
XBooleanFalse is the false boolean value
var XBooleanTrue = NewXBoolean(true)
XBooleanTrue is the true boolean value
var XDateTimeZero = NewXDateTime(envs.ZeroDateTime)
XDateTimeZero is the zero time value
var XDateZero = NewXDate(dates.ZeroDate)
XDateZero is the zero time value
var XNumberZero = NewXNumber(decimal.Zero)
XNumberZero is the zero number value
var XObjectEmpty = NewXObject(map[string]XValue{})
XObjectEmpty is the empty empty
var XTextEmpty = NewXText("")
XTextEmpty is the empty text value
var XTimeZero = NewXTime(dates.ZeroTimeOfDay)
XTimeZero is the zero time value
Functions ¶
func Describe ¶ added in v0.10.1
Describe returns a representation of the given value for use in error messages
func Equals ¶ added in v0.9.4
Equals checks for equality between the two given values. This is only used for testing as x = y specifically means text(x) == text(y)
func Format ¶ added in v0.115.3
func Format(env envs.Environment, x XValue) string
Format returns the pretty text representation
func String ¶ added in v0.115.3
String returns a representation of the given value for use in debugging
func ToXArray ¶ added in v0.115.3
func ToXArray(env envs.Environment, x XValue) (*XArray, XError)
ToXArray converts the given value to an array
func ToXBoolean ¶ added in v0.9.4
ToXBoolean converts the given value to a boolean
func ToXDate ¶
func ToXDate(env envs.Environment, x XValue) (XDate, XError)
ToXDate converts the given value to a time or returns an error if that isn't possible
func ToXDateTime ¶ added in v0.9.4
func ToXDateTime(env envs.Environment, x XValue) (XDateTime, XError)
ToXDateTime converts the given value to a time or returns an error if that isn't possible
func ToXDateTimeWithTimeFill ¶ added in v0.15.1
func ToXDateTimeWithTimeFill(env envs.Environment, x XValue) (XDateTime, XError)
ToXDateTimeWithTimeFill converts the given value to a time or returns an error if that isn't possible
func ToXNumber ¶
func ToXNumber(env envs.Environment, x XValue) (XNumber, XError)
ToXNumber converts the given value to a number or returns an error if that isn't possible
func ToXObject ¶ added in v0.115.3
func ToXObject(env envs.Environment, x XValue) (*XObject, XError)
ToXObject converts the given value to an object
func ToXText ¶ added in v0.9.0
func ToXText(env envs.Environment, x XValue) (XText, XError)
ToXText converts the given value to a string
Types ¶
type XArray ¶
type XArray struct { XValue // contains filtered or unexported fields }
XArray is an array of items.
@(array(1, "x", true)) -> [1, x, true] @(array(1, "x", true)[1]) -> x @(count(array(1, "x", true))) -> 3 @(json(array(1, "x", true))) -> [1,"x",true]
@type array
func NewXLazyArray ¶ added in v0.115.3
NewXLazyArray returns a new lazy array with the given source function
func (*XArray) Count ¶ added in v0.115.3
Count is called when the length of this object is requested in an expression
func (*XArray) Describe ¶ added in v0.115.3
Describe returns a representation of this type for error messages
func (*XArray) Format ¶ added in v0.115.3
func (x *XArray) Format(env envs.Environment) string
Format returns the pretty text representation
func (*XArray) MarshalJSON ¶ added in v0.115.3
MarshalJSON converts this type to internal JSON
type XBoolean ¶ added in v0.9.0
type XBoolean struct {
// contains filtered or unexported fields
}
XBoolean is a boolean `true` or `false`.
@(true) -> true @(1 = 1) -> true @(1 = 2) -> false @(json(true)) -> true
@type boolean
func NewXBoolean ¶ added in v0.9.0
NewXBoolean creates a new boolean value
func (XBoolean) Describe ¶ added in v0.10.1
Describe returns a representation of this type for error messages
func (XBoolean) Format ¶ added in v0.115.3
func (x XBoolean) Format(env envs.Environment) string
Format returns the pretty text representation
func (XBoolean) MarshalJSON ¶ added in v0.9.0
MarshalJSON is called when a struct containing this type is marshaled
func (XBoolean) String ¶ added in v0.9.0
String returns the native string representation of this type for debugging
func (*XBoolean) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON is called when a struct containing this type is unmarshaled
type XComparable ¶ added in v0.115.3
type XComparable interface { // Compare returns -1 if this value is less, 0 if equal, +1 if greater Compare(XValue) int }
XComparable is the interface for types which can be compared
type XCountable ¶ added in v0.115.3
type XCountable interface {
Count() int
}
XCountable is the interface for types which can be counted
type XDate ¶
type XDate struct {
// contains filtered or unexported fields
}
XDate is a Gregorian calendar date value.
@(date_from_parts(2019, 4, 11)) -> 2019-04-11 @(format_date(date_from_parts(2019, 4, 11))) -> 11-04-2019 @(json(date_from_parts(2019, 4, 11))) -> "2019-04-11"
@type date
func (XDate) Describe ¶ added in v0.115.3
Describe returns a representation of this type for error messages
func (XDate) Format ¶ added in v0.115.3
func (x XDate) Format(env envs.Environment) string
Format returns the pretty text representation
func (XDate) FormatCustom ¶ added in v0.115.3
FormatCustom provides customised formatting
func (XDate) MarshalJSON ¶
MarshalJSON is called when a struct containing this type is marshaled
type XDateTime ¶ added in v0.9.0
type XDateTime struct {
// contains filtered or unexported fields
}
XDateTime is a datetime value.
@(datetime("1979-07-18T10:30:45.123456Z")) -> 1979-07-18T10:30:45.123456Z @(format_datetime(datetime("1979-07-18T10:30:45.123456Z"))) -> 18-07-1979 05:30 @(json(datetime("1979-07-18T10:30:45.123456Z"))) -> "1979-07-18T10:30:45.123456Z"
@type datetime
func NewXDateTime ¶ added in v0.9.0
NewXDateTime creates a new date
func (XDateTime) Describe ¶ added in v0.10.1
Describe returns a representation of this type for error messages
func (XDateTime) Format ¶ added in v0.115.3
func (x XDateTime) Format(env envs.Environment) string
Format returns the pretty text representation
func (XDateTime) FormatCustom ¶ added in v0.115.3
func (x XDateTime) FormatCustom(env envs.Environment, layout string, tz *time.Location) (string, error)
FormatCustom provides customised formatting
func (XDateTime) MarshalJSON ¶ added in v0.9.0
MarshalJSON is called when a struct containing this type is marshaled
func (XDateTime) ReplaceTime ¶ added in v0.115.3
ReplaceTime returns the a new date time with the time part replaced by the given time
func (XDateTime) String ¶ added in v0.9.0
String returns the native string representation of this type
func (*XDateTime) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON is called when a struct containing this type is unmarshaled
type XFunction ¶ added in v0.115.3
type XFunction struct {
// contains filtered or unexported fields
}
XFunction is a callable function.
@(upper) -> upper @(array(upper)[0]("abc")) -> ABC @(json(upper)) -> null
@type function
func NewXFunction ¶ added in v0.115.3
NewXFunction creates a new XFunction
func (*XFunction) Call ¶ added in v0.115.3
func (x *XFunction) Call(env envs.Environment, params []XValue) XValue
func (*XFunction) Describe ¶ added in v0.115.3
Describe returns a representation of this type for error messages
func (*XFunction) Format ¶ added in v0.115.3
func (x *XFunction) Format(env envs.Environment) string
Format returns the pretty text representation
func (*XFunction) MarshalJSON ¶ added in v0.115.3
MarshalJSON converts this type to JSON
type XNumber ¶
type XNumber struct {
// contains filtered or unexported fields
}
XNumber is a whole or fractional number.
@(1234) -> 1234 @(1234.5678) -> 1234.5678 @(format_number(1234.5670)) -> 1,234.567 @(json(1234.5678)) -> 1234.5678
@type number
func NewXNumberFromInt ¶
NewXNumberFromInt creates a new XNumber from the given int
func NewXNumberFromInt64 ¶
NewXNumberFromInt64 creates a new XNumber from the given int
func RequireXNumberFromString ¶
RequireXNumberFromString creates a new XNumber from the given string or panics (used for tests)
func (XNumber) Describe ¶ added in v0.10.1
Describe returns a representation of this type for error messages
func (XNumber) Format ¶ added in v0.115.3
func (x XNumber) Format(env envs.Environment) string
Format returns the pretty text representation
func (XNumber) FormatCustom ¶ added in v0.115.3
FormatCustom provides customised formatting
func (XNumber) MarshalJSON ¶
MarshalJSON is called when a struct containing this type is marshaled
func (*XNumber) UnmarshalJSON ¶
UnmarshalJSON is called when a struct containing this type is unmarshaled
type XObject ¶ added in v0.115.3
type XObject struct { XValue XCountable // contains filtered or unexported fields }
XObject is an object with named properties.
@(object("foo", 1, "bar", "x")) -> {bar: x, foo: 1} @(object("foo", 1, "bar", "x").bar) -> x @(object("foo", 1, "bar", "x")["bar"]) -> x @(count(object("foo", 1, "bar", "x"))) -> 2 @(json(object("foo", 1, "bar", "x"))) -> {"bar":"x","foo":1}
@type object
func NewXLazyObject ¶ added in v0.115.3
NewXLazyObject returns a new lazy object with the source function and default
func NewXObject ¶ added in v0.115.3
NewXObject returns a new object with the given properties
func ReadXObject ¶ added in v0.115.3
ReadXObject reads an instance of this type from JSON
func (*XObject) Count ¶ added in v0.115.3
Count is called when the length of this object is requested in an expression
func (*XObject) Describe ¶ added in v0.115.3
Describe returns a representation of this type for error messages
func (*XObject) Format ¶ added in v0.115.3
func (x *XObject) Format(env envs.Environment) string
Format returns the pretty text representation
func (*XObject) MarshalJSON ¶ added in v0.115.3
MarshalJSON converts this type to internal JSON
func (*XObject) Properties ¶ added in v0.115.3
Properties returns the sorted property names of this object
func (*XObject) SetMarshalDefault ¶ added in v0.115.3
type XText ¶ added in v0.9.0
type XText struct {
// contains filtered or unexported fields
}
XText is a string of characters.
@("abc") -> abc @(text_length("abc")) -> 3 @(upper("abc")) -> ABC @(json("abc")) -> "abc"
@type text
func (XText) Describe ¶ added in v0.10.1
Describe returns a representation of this type for error messages
func (XText) Format ¶ added in v0.115.3
func (x XText) Format(env envs.Environment) string
Format returns the pretty text representation
func (XText) MarshalJSON ¶ added in v0.9.0
MarshalJSON is called when a struct containing this type is marshaled
func (XText) String ¶ added in v0.9.0
String returns the native string representation of this type for debugging
func (*XText) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON is called when a struct containing this type is unmarshaled
type XTime ¶ added in v0.115.3
type XTime struct {
// contains filtered or unexported fields
}
XTime is a time of day.
@(time_from_parts(16, 30, 45)) -> 16:30:45.000000 @(format_time(time_from_parts(16, 30, 45))) -> 16:30 @(json(time_from_parts(16, 30, 45))) -> "16:30:45.000000"
@type time
func (XTime) Describe ¶ added in v0.115.3
Describe returns a representation of this type for error messages
func (XTime) Format ¶ added in v0.115.3
func (x XTime) Format(env envs.Environment) string
Format returns the pretty text representation
func (XTime) FormatCustom ¶ added in v0.115.3
FormatCustom provides customised formatting
func (XTime) MarshalJSON ¶ added in v0.115.3
MarshalJSON is called when a struct containing this type is marshaled
type XValue ¶
type XValue interface { // How type is rendered in console for debugging fmt.Stringer // How the type JSONifies json.Marshaler // Describe returns a representation for use in error messages Describe() string // Truthy determines truthiness for this type Truthy() bool // Render returns the canonical text representation Render() string // Format returns the pretty text representation Format(env envs.Environment) string // Equals returns true if this value is equal to the given value Equals(XValue) bool }
XValue is the base interface of all excellent types
func JSONToXValue ¶
JSONToXValue returns an X type from the given JSON