elainable/mrow
v0.1.2 ·
A parser combinator library for Luau
mrow
A parser combinator library for Luau
const mrow = require(path to require)
const number = mrow.token(mrow.int)
const list = mrow.between(
mrow.token(mrow.string("[")),
mrow.separated(number, mrow.token(mrow.string(","))),
mrow.token(mrow.string("]"))
)
const parse = mrow.create(mrow.between(mrow.spaces, list, mrow.eof))
print(parse(" [1, 2, 3] ").value) --> { 1, 2, 3 }
print(parse("[1, 2").error) --> "expected ',' or ']', but got end of input"
Install
pesde
pesde add elainable/mrow
Usage
mrow.create(frame) returns a function that turns a source string into
{ success = true, value = ... } or { success = false, error = "..." }.
End the grammar with mrow.eof when the whole input has to match.
- Characters:
stringanyone_ofnone_ofsatisfyspaceseof - Numbers:
uintint - Combinators:
sequencechoicemanysomeseparatedoptionalbetweentokenmaplabel - Recursion:
lazyleft_recursive
See tests for examples.
Custom frames
Every parser is a frame built with mrow.assembler and mrow.context, and you can write
your own. See src/parser/README.md.
mrow.disassembler(frame) returns the instructions of a frame as text.