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)
    mixin template makeParser (
    Input
    alias supply
    ) if (
    is(ElementType!Input : dchar)
    ) {}
  2. mixintemplate makeParser(Input, alias supply, alias basicMatcher)

Members

Mixins

__anonymous
mixin makeParser!(Input, supply, matchText)
Undocumented in source.

Static functions

matchText
auto matchText(Input input)
Undocumented in source.

Mixed In Members

From mixin makeParser!(Input, supply, matchText)

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.
MatchCaptureTypes
template MatchCaptureTypes(Ts...)

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

MatchType
template MatchType(pattern...)

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

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.

CaptureTupleIterator
struct CaptureTupleIterator(patterns...)

Iterate on the given pattern tuple.

TupleWrap
template TupleWrap(items...)

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

tupleWrap
TupleWrap!Ts tupleWrap(Ts args)
Undocumented in source. Be warned that the author may not have intended to support it.
funCC
alias funCC = unaryFun!fun
Undocumented in source.
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.
ReturnMatch
alias ReturnMatch = MatchOr!pattern
Undocumented in source.
Capture
alias Capture = ReturnMatch.Capture
Undocumented in source.
capture
Capture capture;
Undocumented in source.
MatchOr
template MatchOr(pattern...)
matchRepeatRange
template matchRepeatRange(pattern...)
matchUntil
template matchUntil(alias terminator, pattern...)

Return the matchOr return value for the given pattern.

ret
auto ret;
Undocumented in source.
Capture
alias Capture = Nullable!(TupleWrap!(ret.Capture))
Undocumented in source.
Return
alias Return = MatchCapture!Capture
Undocumented in source.
Result
alias Result = MatchCapture!T
Undocumented in source.
source
Input source;
Undocumented in source.
result
auto result;
Undocumented in source.
LastResult
union LastResult

Union to hold results of each pattern match

lastResult
LastResult lastResult;
Undocumented in source.
run
auto run(LastResult lastResult, Input input, Result match)

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

capture
auto capture;
Undocumented in source.
result
auto result;
Undocumented in source.
result
auto result;
Undocumented in source.

Meta