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
bodyStruct ontaining the raw matched value and an interpreter
Return Value
The value of the
DataTypeornilif it cannot be processed -
In case of more complicated expression, this initialiser accepts a
convertblock, 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
convertThe conversion block to process values
bodyStruct 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
checkThe string to check for in the input string (with exact match)
convertsToStatically 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
inputThe input to convert as a
DataTypevalueinterpreterAn interpreter instance if the content needs any further evaluation
Return Value
The value of the
DataTypeornilif it cannot be processed
View on GitHub
Install in Dash
Literal Class Reference