keen/parse

Source
try-take bool(a char8 array-iterator, start string)
starts-with bool(a char8 array-iterator, start string)
grammar[t] record
func t mut(char8 array-iterator)
Opaque grammar type parsing a t value. Use the functions in this module to build a grammar.
parse[t] t(a t grammar, text string)
Match a string against a grammar. The whole string must match the grammar. If the string has leading or trailing spaces you must use a grammar that includes those. Throws a parse-error on failure.
parse[t] t(a t grammar, text char8 array-view)
parse-error record
input string
index nat64
expected string
== bool(a parse-error, b parse-error)
show string(a parse-error)
inner-parse-error record
expected string
show string(a inner-parse-error)
grammar-skip record
This is like grammar but produces no result.
new grammar-skip()
Grammar matching empty strings
and-return[t] t grammar(a grammar-skip, value t) t data
text-delimited string grammar(begin string, end string)
text-not-containing string grammar(ending string)
text-not-containing-any string grammar(possible-endings string[])
~~[t, u] (t, u) grammar(a t grammar, b u grammar)
Expects to parse a followed by b. By default this does not allow spaces in between. For that, use a ~~ spaces ~~ b.
~~[t] t grammar(a t grammar, b grammar-skip)
~~[t] t grammar(a grammar-skip, b t grammar)
~~ grammar-skip(a grammar-skip, b grammar-skip)
~~[t] t grammar(a string, b t grammar)
Skips an exact string, then parses b.
~~[t] t grammar(a t grammar, b string)
Parses a, then skips an exact string.
~~ grammar-skip(a string, b grammar-skip)
~~ grammar-skip(a grammar-skip, b string)
/[t] t grammar(a t grammar, b t grammar)
Tries to parse with a, and if that fails, tries to parse with b instead.
transform[output, input] output grammar(a input grammar, f output data(input))
Uses a function to transform the result if parsing is successful.
optional[t] t option grammar(a t grammar)
Allows parsing to fail, returning an empty option if it does.
optional grammar-skip(a string)
Optionally skips an exact string.
many[t] t[] grammar(a t grammar)
Parses the same grammar as many times as possible (including 0 times).
many grammar-skip(a grammar-skip)
one-or-more[t] t[] grammar(a t grammar)
Parses a at least once, then as many times as possible.
one-or-more grammar-skip(a grammar-skip)
separated-by[t] t[] grammar(a t grammar, separator string)

Parses a as many times as possible, with 'separator' in between.

This does not allow a trailing separator; it is a parse error to have a separator not followed by another a. This does allow to parse nothing, returning an empty array.

separated-by[t] t[] grammar(a t grammar, separator grammar-skip)
lazy record (has private fields)
Use this to allow recursive grammars.
with-block[t] t grammar(_ lazy, f t grammar data(void))
exact grammar-skip(a string)
Matches a exactly.
exact[t] t grammar(a string, value t) t data
Equivalent to a.exact transform of _ then value
whitespace grammar-skip()
skip-whitespace void(a char8 array-iterator)
is-space bool(a char8)
quoted-string string grammar()
A double-quoted string as in JSON, including escape sequences.
word string grammar()
Matches and returns a sequence of letters.
bool bool grammar()
Parse a string "true" or "false".
nat nat64 grammar()
Parses a natural number in decimal format. This allows leading 0s which have no effect.
int int64 grammar()
Parses a signed integer in decimal format. This allows e.g. "1", "+23", "-45".
is-digit bool(a char8)
float float64 grammar()
Parse a decimal number. This allows e.g. "+1.23".
is-whitespace bool(a char8)
is-whitespace-non-newline bool(a char8)