ClosureRule

public final class ClosureRule : Rule

An implementation of a Rule that allows the specification of a Test closure to provide the required check.

  • Annotations for the rule

    Declaration

    Swift

    public let annotations: RuleAnnotations
  • Behaviour for the rule

    Declaration

    Swift

    public let behaviour: Behaviour
  • The Test closure used by the rule

    Declaration

    Swift

    public let matcher: Test
  • Create a an instance supplied annotations and token that will use the supplied Test closure to perform its match

    Declaration

    Swift

    public init(with behaviour:Behaviour, and annotations:RuleAnnotations = [:], using matcher:@escaping Test)

    Parameters

    token

    The new TokenType or nil if the token should remain the same

    annotations

    The new Annotations or nil if the annotations are unchanged

    matcher

    The Test closure

  • This function should create a new instance of this rule, replacing the behaviour and any annotations with those specified in the parameters if not nil, or maintaining the current ones if nil.

    Declaration

    Swift

    public func rule(with behaviour: Behaviour? = nil, annotations: RuleAnnotations? = nil) -> Rule

    Parameters

    behaviour

    The behaviour for the new instance, if nil the new copy should use the same behaviour as this instance.

    annotations

    The annotations for the new instance, if nil the new copy should use the same behaviour as this instance.

    Return Value

    A new instance with the specified behaviour and annotations.

  • This function implements the actual test. It is responsible soley for performing the test. The scanner head will be managed correctly based on success (it will be left in the position at the end of the test), or returned to its pre-test position on failure.

    Declaration

    Swift

    public func test(with lexer: LexicalAnalyzer, for ir: IntermediateRepresentation) throws

    Parameters

    lexer

    The lexer controlling the scanner

    ir

    The intermediate representation

  • A textual description of the rule

    Declaration

    Swift

    public var description: String { get }
  • An abreviated description of the rule

    Declaration

    Swift

    public var shortDescription: String { get }