makeParser

Mixin to produce matcher templates for processing Input input range and creating a Match output range.

The parser requires a function with two overloads called supply. Both are expected to output a user data type for storing the parsing result (eg. a list of tokens). The first one should take a slice of the input range as a std.range.Take!Input and will be called for any successful match. The second should take two instances of the data type and combine them into once.

A basic implementation of a supply string (with string as the input range) would be this:

string[] supply(Take!string input) {
    return [input.to!string];
}

string[] supply(string[] a, string[] b) {
    return a ~ b;
}

Notes:

* Performance of the parser heavily depends on std.range.popFrontN, so it's the fastest if the range supports slicing and has length. Alternatively, the range may define a popFrontN method itself. * The mixin can work both in module scope and at struct/class scope. No context is required for the matcher functions to work.

Internally the template only defines aliases to closures rather than functions. This allows them to work without an instance in structs and classes, but they may still use context for template parameters.

  1. mixintemplate makeParser(Input, alias supply)
  2. mixintemplate makeParser(Input, alias supply, alias basicMatcher)

Members

Aliases

Capture
alias Capture = ReturnMatch.Capture
Undocumented in source.
Capture
alias Capture = Nullable!(TupleWrap!(ret.Capture))
Undocumented in source.
Match
alias Match = rcdata.parser.MatchImpl!(Input, supply)
Undocumented in source.
MatchCapture
alias MatchCapture(Ts...) = rcdata.parser.MatchImpl!(Input, supply, Ts)
Undocumented in source.
ParserException
alias ParserException = rcdata.parser.ParserExceptionImpl!(Input, supply)
Undocumented in source.
PatternCaptureTypes
alias PatternCaptureTypes(pattern...) = MatchCaptureTypes!(staticMap!(MatchType, pattern))

Get an alias seq of capture types, similarly to PatternCaptureTypes, but based on a pattern for match.

Result
alias Result = MatchCapture!T
Undocumented in source.
Return
alias Return = MatchCapture!Capture
Undocumented in source.
ReturnMatch
alias ReturnMatch = MatchOr!pattern
Undocumented in source.
funCC
alias funCC = unaryFun!fun
Undocumented in source.

Static functions

run
auto run(LastResult lastResult, Input input, Result match)

Run the rule at given index. Does not store the result.

tupleWrap
TupleWrap!Ts tupleWrap(Ts args)
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

capture
Capture capture;
Undocumented in source.
capture
auto capture;
Undocumented in source.
lastResult
LastResult lastResult;
Undocumented in source.
result
auto result;
Undocumented in source.
result
auto result;
Undocumented in source.
result
auto result;
Undocumented in source.
ret
auto ret;
Undocumented in source.
source
Input source;
Undocumented in source.

Structs

CaptureTupleIterator
struct CaptureTupleIterator(patterns...)

Iterate on the given pattern tuple.

Templates

MatchCaptureTypes
template MatchCaptureTypes(Ts...)

Get an AliasSeq of capture types held by a given list of Match and MatchCapture types.

MatchOr
template MatchOr(pattern...)

Return the matchOr return value for the given pattern.

MatchType
template MatchType(pattern...)

Check the match type returned by match for the given pattern.

TupleWrap
template TupleWrap(items...)

Wrap the tuple in a std.typecons.Tuple if its length isn't 1, otherwise return the sole item.

match
template match(pattern...)

Match multiple items in order. Each matcher in the pattern will be tested against the source in order, and will advance the range before the next item in the pattern. The full pattern has to match.

match
template match(handlers...)
Undocumented in source.
matchRepeatRange
template matchRepeatRange(pattern...)
matchUntil
template matchUntil(alias terminator, pattern...)

Return the matchOr return value for the given pattern.

Unions

LastResult
union LastResult

Union to hold results of each pattern match

Meta