DataType

public class DataType<T> : DataTypeProtocol

The implementation of a DataType uses the DataTypeProtocol to convert input to a strongly typed data and print it if needed

  • The existing type to map to an internal one

    Declaration

    Swift

    let type: T.Type
  • Array of literals that tell the framework how to transform certain types to an internal DataType representation

    Declaration

    Swift

    let literals: [Literal<T>]
  • To be able to bridge the outside world effectively, it needs to provide an already existing Swift or user-defined type. This can be class, struct, enum, or anything else, for example, block or function (which is not recommended). The literals tell the framework which strings can be represented in the given data type The last print block is used to convert the value of any DataType to a string value. It does not need to be unique or always the same for the same input values.

    Declaration

    Swift

    public init (type: T.Type,
                 literals: [Literal<T>],
                 print: @escaping (_ body: DataTypeBody<T>) -> String)

    Parameters

    type

    The existing type to map to an internal one

    literals

    Array of literals that tell the framework how to transform certain types to an internal DataType representation

    print

    A method to convert an internal representation to strings - for debugging and output representation purposes

    body

    Struct containing the value and a printer instance

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

    Declaration

    Swift

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

    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

  • This is a convenience method, for debugging and value printing purposes, which can return a string from the current data type. It does not need to be unique or always the same for the same input values.

    Declaration

    Swift

    public func print(value input: Any, printer: Printer) -> String?

    Parameters

    value

    Any value that is a valid DataType

    printer

    An interpreter instance if the content recursively contains further data types to print

    Return Value

    The string representation of the value or nil if it cannot be processed