Skip to content
kareman edited this page Aug 13, 2020 · 3 revisions

Parser

Takes a pattern, optimises it and tries to match it over an input.

public struct Parser<Input: BidirectionalCollection> where Input.Element: Hashable

Initializers

init(_:)

A parser which matches pattern at a given position.

@inlinable public init<P: Pattern>(_ pattern: P) throws where P.Input == Input

init(search:)

A parser which searches for pattern from a given position.

@inlinable public init<P: Pattern>(search pattern: P) throws where P.Input == Input

Is the same as Parser(Skip() • pattern).

Properties

matcher

let matcher: VMEngine<Input>

Methods

match(in:at:)

Tries to match the pattern in input at index.

@inlinable public func match(in input: Input, at index: Input.Index? = nil) -> Match?

Parameters

  • index: - index: The position to match at, if not provided the beginning of input will be used.

matches(in:from:)

A lazily generated sequence of consecutive matches of the pattern in input.

@inlinable public func matches(in input: Input, from startindex: Input.Index? = nil) -> UnfoldSequence<Match, Input.Index>

Each match attempt starts at the .range.upperBound of the previous match, so the matches can be overlapping.

You can dictate where the next match should start by where you place the last capture.

Parameters

  • startindex: - startindex: The position to match from, if not provided the beginning of input will be used.
Clone this wiki locally