Literal

public class Literal<T>

Literals are used by DataTypes to be able to recognise static values, that can be expressed as a given type

  • For the conversion it uses the registered literals, to be able to process the input and return an existing type

    Declaration

    Swift

    let convert: (_ body: LiteralBody) -> T?

    Parameters

    body

    Struct ontaining the raw matched value and an interpreter

    Return Value

    The value of the DataType or nil if it cannot be processed

  • In case of more complicated expression, this initialiser accepts a convert block, which can be used to process any value. Return nil, if the input cannot be accepted and converted.

    Declaration

    Swift

    public init(convert: @escaping (_ body: LiteralBody) -> T?)

    Parameters

    convert

    The conversion block to process values

    body

    Struct ontaining the raw matched value and an interpreter

  • In case the literals are easily expressed, static keywords, then this initialiser is the best to use.

    Declaration

    Swift

    public init(_ check: String, convertsTo value: @autoclosure @escaping () -> T)

    Parameters

    check

    The string to check for in the input string (with exact match)

    convertsTo

    Statically typed associated value. As it is expressed as an autoclosure, the provided expression will be evaluated at recognition time, not initialisation time. For example, Date() is perfectly acceptable to use here.

  • For the conversion it uses the registered literals, to be able to process the input and return an existing type

    Declaration

    Swift

    func convert(input: String, interpreter: TypedInterpreter) -> T?

    Parameters

    input

    The input to convert as a DataType value

    interpreter

    An interpreter instance if the content needs any further evaluation

    Return Value

    The value of the DataType or nil if it cannot be processed