Behaviour

public struct Behaviour

Behaviour represents a complete description of the required behaviour of any given rule. This includes behaviours such as lookahead, negation, and cardinality. As well the scanning/parsing behaviour indicating whether or not the rule should create tokens (structural), is scanning (should be included in the match range, but creates no token) or skipping (must be matched, but is not included in the bounds of the match range).

  • Captures scanning/parsing behaviour indicating identifying if the rule should create tokens (structural), is scanning (should be included in the match range, but creates no token) or skipping (must be matched, but is not included in the bounds of the match range).

    See more

    Declaration

    Swift

    public enum Kind : Equatable
  • The rule should be matched, but if lookahead is true the scanner head position should be returned to its position at the start of evaluation

    Declaration

    Swift

    public let lookahead: Bool
  • The result of matching should be negated.

    Declaration

    Swift

    public let negate: Bool
  • The kind of rule, skipping, scanning, or structural (see above)

    Declaration

    Swift

    public let kind: Kind
  • The cardinatlity of the matches

    Declaration

    Swift

    public let cardinality: Cardinality
  • The token produced if structural or nil otherwise

    Declaration

    Swift

    public var token: TokenType? { get }
  • Constructs a new instance of the struct with the specified parameters. All except kind can be excluded resulting in requirements for a single match, un-negated without lookahead

    Declaration

    Swift

    public init(_ kind:Kind, cardinality: ClosedRange<Int> = 1...1, negated:Bool = false, lookahead:Bool = false)

    Parameters

    kind

    The of behaviour (skipping, scanning, or structural)

    cardinality

    How many matches are required. Defaults to 1, but can be specified as any closed range.

    negated

    Specifies if the result of the Matcher should be negated

    lookahead

    Specifies if the scanning head should be returned to the pre-matching position even if met.

  • Constructs a new instance of the struct with the specified parameters. All except kind can be excluded resulting in requirements for a single match, un-negated without lookahead

    Declaration

    Swift

    public init(_ kind:Kind, cardinality: PartialRangeFrom<Int>, negated:Bool = false, lookahead:Bool = false)

    Parameters

    kind

    The of behaviour (skipping, scanning, or structural)

    cardinality

    The minimum number of matches required

    negated

    Specifies if the result of the Matcher should be negated

    lookahead

    Specifies if the scanning head should be returned to the pre-matching position even if met.

  • Constructs a new instance of the struct with the specified parameters. All except kind can be excluded resulting in requirements for a single match, un-negated without lookahead

    Declaration

    Swift

    public init(_ kind:Kind, cardinality: Cardinality, negated:Bool = false, lookahead:Bool = false)

    Parameters

    kind

    The of behaviour (skipping, scanning, or structural)

    cardinality

    The cardinality of the matches

    negated

    Specifies if the result of the Matcher should be negated

    lookahead

    Specifies if the scanning head should be returned to the pre-matching position even if met.

  • Creates a new instance with the specified parameters changed. All have defaults and any that are excluded will maintain their current values.

    Declaration

    Swift

    public func instanceWith(_ kind:Kind?=nil, cardinality: ClosedRange<Int>? = nil, negated:Bool? = nil, lookahead:Bool? = nil)->Behaviour

    Parameters

    kind

    The of behaviour (skipping, scanning, or structural)

    cardinality

    How many matches are required.

    negated

    Specifies if the result of the Matcher should be negated

    lookahead

    Specifies if the scanning head should be returned to the pre-matching position even if met.

  • Creates a new instance with the specified parameters changed. All have defaults and any that are excluded will maintain their current values.

    Declaration

    Swift

    public func instanceWith(_ kind:Kind?=nil, cardinality: PartialRangeFrom<Int>? = nil, negated:Bool? = nil, lookahead:Bool? = nil)->Behaviour

    Parameters

    kind

    The of behaviour (skipping, scanning, or structural)

    cardinality

    How many matches are required.

    negated

    Specifies if the result of the Matcher should be negated

    lookahead

    Specifies if the scanning head should be returned to the pre-matching position even if met.

  • Takes a description of a match and wraps it in the behavioural annotations of the rule

    Declaration

    Swift

    public func describe(match:String, requiresScanningPrefix requiresScanning:Bool = true, requiresStructuralPrefix requiresStructural:Bool = true, annotatedWith annotations: RuleAnnotations)->String

    Parameters

    match

    A description of the match

    Return Value

    A wrapped description of the match which includes the behaviour