sdpc.parsers

Simple parsers

Here are some commonly used parsers. Also as an example for how to use the combinators.

Members

Aliases

digit
alias digit(string _digits) = transform!(ch!_digits, (ch) => cast(int)_digits.indexOf(ch))

Parse a sequences of digits, return an array of number

skip_whitespace
alias skip_whitespace = skip!(choice!(token!" ", token!"\n", token!"\t"))

Skip white spaces

word
alias word(alias accept = alphabet) = transform!(many!(ch!accept), (x) => x.idup)

Parse a sequence of characters

Functions

identifier
auto identifier(R i)

Parse an identifier, starts with a letter or _, followed by letter, _, or digits

nop
auto nop(R i)

Consumes nothing, always return OK

parse_escape1
auto parse_escape1(R i)

Parse escaped character, \n, \r, \b, \" and \\

parse_string
auto parse_string(R i)

Parse a string enclosed by a pair of quotes, and containing escape sequence

Structs

ParseError
struct ParseError(R)
Undocumented in source.
ch
struct ch(alias accept)

Match any character in accept

not_ch
struct not_ch(alias reject)

Match any character except those in reject

token
struct token(string t)

Match a string, return the matched string

Templates

number
template number(string accept = digits, int base = 10)

Parse a number

Variables

alphabet
string alphabet;
Undocumented in source.
digits
string digits;
Undocumented in source.
lower
string lower;
Undocumented in source.
upper
string upper;
Undocumented in source.

Meta