types

package
v0.0.0-...-a2de6b1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilXError = NewXError(nil)

NilXError is the nil error value

View Source
var XArrayEmpty = NewXArray()

XArrayEmpty is the empty array

View Source
var XBooleanFalse = NewXBoolean(false)

XBooleanFalse is the false boolean value

View Source
var XBooleanTrue = NewXBoolean(true)

XBooleanTrue is the true boolean value

View Source
var XDateTimeZero = NewXDateTime(envs.ZeroDateTime)

XDateTimeZero is the zero time value

View Source
var XDateZero = NewXDate(dates.ZeroDate)

XDateZero is the zero time value

View Source
var XNumberZero = NewXNumber(decimal.Zero)

XNumberZero is the zero number value

View Source
var XObjectEmpty = NewXObject(map[string]XValue{})

XObjectEmpty is the empty empty

View Source
var XTextEmpty = NewXText("")

XTextEmpty is the empty text value

XTimeZero is the zero time value

Functions

func Compare

func Compare(x1 XValue, x2 XValue) int

Compare compares two given values

func Describe

func Describe(x XValue) string

Describe returns a representation of the given value for use in error messages

func Equals

func Equals(x1 XValue, x2 XValue) bool

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

func Format(env envs.Environment, x XValue) string

Format returns the pretty text representation

func IsXError

func IsXError(x XValue) bool

IsXError returns whether the given value is an error value

func Render

func Render(x XValue) string

Render returns the canonical text representation

func String

func String(x XValue) string

String returns a representation of the given value for use in debugging

func ToXArray

func ToXArray(env envs.Environment, x XValue) (*XArray, XError)

ToXArray converts the given value to an array

func ToXBoolean

func ToXBoolean(x XValue) (XBoolean, XError)

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

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

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 ToXJSON

func ToXJSON(x XValue) (XText, XError)

ToXJSON converts the given value to a JSON string

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

func ToXObject(env envs.Environment, x XValue) (*XObject, XError)

ToXObject converts the given value to an object

func ToXText

func ToXText(env envs.Environment, x XValue) (XText, XError)

ToXText converts the given value to a string

func ToXTime

func ToXTime(env envs.Environment, x XValue) (XTime, XError)

ToXTime converts the given value to a time or returns an error if that isn't possible

func Truthy

func Truthy(x XValue) bool

Truthy determines truthiness for the given value

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 NewXArray

func NewXArray(data ...XValue) *XArray

NewXArray returns a new array with the given items

func NewXLazyArray

func NewXLazyArray(source func() []XValue) *XArray

NewXLazyArray returns a new lazy array with the given source function

func (*XArray) Count

func (x *XArray) Count() int

Count is called when the length of this object is requested in an expression

func (*XArray) Describe

func (x *XArray) Describe() string

Describe returns a representation of this type for error messages

func (*XArray) Equals

func (x *XArray) Equals(o XValue) bool

Equals determines equality for this type

func (*XArray) Format

func (x *XArray) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XArray) Get

func (x *XArray) Get(index int) XValue

Get is called when this object is indexed

func (*XArray) MarshalJSON

func (x *XArray) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to internal JSON

func (*XArray) Render

func (x *XArray) Render() string

Render returns the canonical text representation

func (*XArray) String

func (x *XArray) String() string

String returns the native string representation of this type

func (*XArray) Truthy

func (x *XArray) Truthy() bool

Truthy determines truthiness for this type

type XBoolean

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

func NewXBoolean(value bool) XBoolean

NewXBoolean creates a new boolean value

func (XBoolean) Compare

func (x XBoolean) Compare(o XValue) int

Compare compares this bool to another

func (XBoolean) Describe

func (x XBoolean) Describe() string

Describe returns a representation of this type for error messages

func (XBoolean) Equals

func (x XBoolean) Equals(o XValue) bool

Equals determines equality for this type

func (XBoolean) Format

func (x XBoolean) Format(env envs.Environment) string

Format returns the pretty text representation

func (XBoolean) MarshalJSON

func (x XBoolean) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XBoolean) Native

func (x XBoolean) Native() bool

Native returns the native value of this type

func (XBoolean) Render

func (x XBoolean) Render() string

Render returns the canonical text representation

func (XBoolean) String

func (x XBoolean) String() string

String returns the native string representation of this type for debugging

func (XBoolean) Truthy

func (x XBoolean) Truthy() bool

Truthy determines truthiness for this type

func (*XBoolean) UnmarshalJSON

func (x *XBoolean) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XComparable

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

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 NewXDate

func NewXDate(value dates.Date) XDate

NewXDate creates a new date

func (XDate) Compare

func (x XDate) Compare(o XValue) int

Compare compares this date to another

func (XDate) Describe

func (x XDate) Describe() string

Describe returns a representation of this type for error messages

func (XDate) Equals

func (x XDate) Equals(o XValue) bool

Equals determines equality for this type

func (XDate) Format

func (x XDate) Format(env envs.Environment) string

Format returns the pretty text representation

func (XDate) FormatCustom

func (x XDate) FormatCustom(env envs.Environment, layout string) (string, error)

FormatCustom provides customised formatting

func (XDate) MarshalJSON

func (x XDate) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XDate) Native

func (x XDate) Native() dates.Date

Native returns the native value of this type

func (XDate) Render

func (x XDate) Render() string

Render returns the canonical text representation

func (XDate) String

func (x XDate) String() string

String returns the native string representation of this type

func (XDate) Truthy

func (x XDate) Truthy() bool

Truthy determines truthiness for this type

type XDateTime

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

func NewXDateTime(value time.Time) XDateTime

NewXDateTime creates a new date

func (XDateTime) Compare

func (x XDateTime) Compare(o XValue) int

Compare compares this date to another

func (XDateTime) Date

func (x XDateTime) Date() XDate

Date returns the date part of this datetime

func (XDateTime) Describe

func (x XDateTime) Describe() string

Describe returns a representation of this type for error messages

func (XDateTime) Equals

func (x XDateTime) Equals(o XValue) bool

Equals determines equality for this type

func (XDateTime) Format

func (x XDateTime) Format(env envs.Environment) string

Format returns the pretty text representation

func (XDateTime) FormatCustom

func (x XDateTime) FormatCustom(env envs.Environment, layout string, tz *time.Location) (string, error)

FormatCustom provides customised formatting

func (XDateTime) In

func (x XDateTime) In(tz *time.Location) XDateTime

In returns a copy of this datetime in a different timezone

func (XDateTime) MarshalJSON

func (x XDateTime) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XDateTime) Native

func (x XDateTime) Native() time.Time

Native returns the native value of this type

func (XDateTime) Render

func (x XDateTime) Render() string

Render returns the canonical text representation

func (XDateTime) ReplaceTime

func (x XDateTime) ReplaceTime(tm XTime) XDateTime

ReplaceTime returns the a new date time with the time part replaced by the given time

func (XDateTime) String

func (x XDateTime) String() string

String returns the native string representation of this type

func (XDateTime) Time

func (x XDateTime) Time() XTime

Time returns the time part of this datetime

func (XDateTime) Truthy

func (x XDateTime) Truthy() bool

Truthy determines truthiness for this type

func (*XDateTime) UnmarshalJSON

func (x *XDateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XError

type XError interface {
	error
	XValue
	Equals(XValue) bool
}

XError is an error

func NewXError

func NewXError(err error) XError

NewXError creates a new XError

func NewXErrorf

func NewXErrorf(format string, a ...interface{}) XError

NewXErrorf creates a new XError

func ToInteger

func ToInteger(env envs.Environment, x XValue) (int, XError)

ToInteger tries to convert the passed in value to an integer or returns an error if that isn't possible

type XFunc

type XFunc func(env envs.Environment, args ...XValue) XValue

type XFunction

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

func NewXFunction(name string, fn XFunc) *XFunction

NewXFunction creates a new XFunction

func (*XFunction) Call

func (x *XFunction) Call(env envs.Environment, params []XValue) XValue

func (*XFunction) Describe

func (x *XFunction) Describe() string

Describe returns a representation of this type for error messages

func (*XFunction) Equals

func (x *XFunction) Equals(o XValue) bool

Equals determines equality for this type

func (*XFunction) Format

func (x *XFunction) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XFunction) MarshalJSON

func (x *XFunction) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to JSON

func (*XFunction) Name

func (x *XFunction) Name() string

Name returns the name or <anon> for anonymous functions

func (*XFunction) Render

func (x *XFunction) Render() string

Render returns the canonical text representation

func (*XFunction) String

func (x *XFunction) String() string

String returns the native string representation of this type

func (*XFunction) Truthy

func (x *XFunction) Truthy() bool

Truthy determines truthiness for this type

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 NewXNumber

func NewXNumber(value decimal.Decimal) XNumber

NewXNumber creates a new XNumber

func NewXNumberFromInt

func NewXNumberFromInt(value int) XNumber

NewXNumberFromInt creates a new XNumber from the given int

func NewXNumberFromInt64

func NewXNumberFromInt64(value int64) XNumber

NewXNumberFromInt64 creates a new XNumber from the given int

func RequireXNumberFromString

func RequireXNumberFromString(value string) XNumber

RequireXNumberFromString creates a new XNumber from the given string or panics (used for tests)

func (XNumber) Compare

func (x XNumber) Compare(o XValue) int

Compare compares this number to another

func (XNumber) Describe

func (x XNumber) Describe() string

Describe returns a representation of this type for error messages

func (XNumber) Equals

func (x XNumber) Equals(o XValue) bool

Equals determines equality for this type

func (XNumber) Format

func (x XNumber) Format(env envs.Environment) string

Format returns the pretty text representation

func (XNumber) FormatCustom

func (x XNumber) FormatCustom(format *envs.NumberFormat, places int, groupDigits bool) string

FormatCustom provides customised formatting

func (XNumber) MarshalJSON

func (x XNumber) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XNumber) Native

func (x XNumber) Native() decimal.Decimal

Native returns the native value of this type

func (XNumber) Render

func (x XNumber) Render() string

Render returns the canonical text representation

func (XNumber) String

func (x XNumber) String() string

String returns the native string representation of this type

func (XNumber) Truthy

func (x XNumber) Truthy() bool

Truthy determines truthiness for this type

func (*XNumber) UnmarshalJSON

func (x *XNumber) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XObject

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

func NewXLazyObject(source func() map[string]XValue) *XObject

NewXLazyObject returns a new lazy object with the source function and default

func NewXObject

func NewXObject(properties map[string]XValue) *XObject

NewXObject returns a new object with the given properties

func ReadXObject

func ReadXObject(data []byte) (*XObject, error)

ReadXObject reads an instance of this type from JSON

func (*XObject) Count

func (x *XObject) Count() int

Count is called when the length of this object is requested in an expression

func (*XObject) Default

func (x *XObject) Default() XValue

Default returns the default value for this

func (*XObject) Describe

func (x *XObject) Describe() string

Describe returns a representation of this type for error messages

func (*XObject) Equals

func (x *XObject) Equals(o XValue) bool

Equals determines equality for this type

func (*XObject) Format

func (x *XObject) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XObject) Get

func (x *XObject) Get(key string) (XValue, bool)

Get retrieves the named property

func (*XObject) MarshalJSON

func (x *XObject) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to internal JSON

func (*XObject) Properties

func (x *XObject) Properties() []string

Properties returns the sorted property names of this object

func (*XObject) Render

func (x *XObject) Render() string

Render returns the canonical text representation

func (*XObject) SetMarshalDefault

func (x *XObject) SetMarshalDefault(marshal bool)

func (*XObject) String

func (x *XObject) String() string

String returns the native string representation of this type for debugging

func (*XObject) Truthy

func (x *XObject) Truthy() bool

Truthy determines truthiness for this type

type XText

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 NewXText

func NewXText(value string) XText

NewXText creates a new text value

func (XText) Compare

func (x XText) Compare(o XValue) int

Compare compares this string to another

func (XText) Describe

func (x XText) Describe() string

Describe returns a representation of this type for error messages

func (XText) Empty

func (x XText) Empty() bool

Empty returns whether this is an empty string

func (XText) Equals

func (x XText) Equals(o XValue) bool

Equals determines equality for this type

func (XText) Format

func (x XText) Format(env envs.Environment) string

Format returns the pretty text representation

func (XText) Length

func (x XText) Length() int

Length returns the length of this string

func (XText) MarshalJSON

func (x XText) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XText) Native

func (x XText) Native() string

Native returns the native value of this type

func (XText) Render

func (x XText) Render() string

Render returns the canonical text representation

func (XText) String

func (x XText) String() string

String returns the native string representation of this type for debugging

func (XText) Truthy

func (x XText) Truthy() bool

Truthy determines truthiness for this type

func (*XText) UnmarshalJSON

func (x *XText) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XTime

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 NewXTime

func NewXTime(value dates.TimeOfDay) XTime

NewXTime creates a new time

func (XTime) Compare

func (x XTime) Compare(o XValue) int

Compare compares this date to another

func (XTime) Describe

func (x XTime) Describe() string

Describe returns a representation of this type for error messages

func (XTime) Equals

func (x XTime) Equals(o XValue) bool

Equals determines equality for this type

func (XTime) Format

func (x XTime) Format(env envs.Environment) string

Format returns the pretty text representation

func (XTime) FormatCustom

func (x XTime) FormatCustom(env envs.Environment, layout string) (string, error)

FormatCustom provides customised formatting

func (XTime) MarshalJSON

func (x XTime) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XTime) Native

func (x XTime) Native() dates.TimeOfDay

Native returns the native value of this type

func (XTime) Render

func (x XTime) Render() string

Render returns the canonical text representation

func (XTime) String

func (x XTime) String() string

String returns the native string representation of this type

func (XTime) Truthy

func (x XTime) Truthy() bool

Truthy determines truthiness for this type

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

func JSONToXValue(data []byte) XValue

JSONToXValue returns an X type from the given JSON

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL