Function

public class Function<T> : FunctionProtocol

Functions can process values in given DataTypes, allowing the expressions to be feature-rich

  • Although Functions typically contain only one pattern, multiple ones can be added, for semantic grouping purposes

    Declaration

    Swift

    public let patterns: [Pattern<T, TypedInterpreter>]
  • If multiple patterns are provided use this initialiser. Otherwise, for only one, there is init(_,matcher:)

    Declaration

    Swift

    public init(patterns: [Pattern<T, TypedInterpreter>])

    Parameters

    patterns

    The array of patterns to be able to recognise

  • In case there is only one pattern, this initialiser is the preferred one to use

    Declaration

    Swift

    public init(_ elements: [PatternElement], options: PatternOptions = [], matcher: @escaping MatcherBlock<T, TypedInterpreter>)

    Parameters

    elements

    Contains the pattern that needs to be recognised

    options

    Options that modify the pattern matching algorithm

    matcher

    Ending closure that transforms and processes the recognised value

  • The matching of the input expression of a given Function happens in this method. It only accepts matches from the matcher, that are exact matches.

    Declaration

    Swift

    public func convert(input: String, interpreter: TypedInterpreter, context: Context, connectedRanges: [ClosedRange<String.Index>] = []) -> Any?

    Parameters

    input

    The input to convert as a DataType value

    interpreter

    An interpreter instance if the content needs any further evaluation

    context

    The context - if vaiables need any contextual information

    connectedRanges

    Ranges of string indices that are connected with opening-closing tag pairs, respectively

    Return Value

    A valid value of any DataType or nil if it cannot be processed