Value to return
Generate an error
const result = error('Error message').parseToEnd('')
result instanceof ParseError // true
result.message // 'Error message'
Error message
Join together an array of strings
const threeAs = repeat(text('a', 3))
threeAs.parseToEnd('aaa') // ['a', 'a', 'a']
const joined = join(threeAs)
joined.parseToEnd('aaa') // 'aaa'
Parser which returns a set of string
What the elements should be separated with
Lazily evaluate a parser. Useful for rules which are self-referential
let digit: Parser<string> = error('Not yet defined')
const parser = lazy(() => digit)
digit = regexp(/d/y)
parser.matches('1') // true
Parses a list of elements separated by a common separator
const digit = regexp(/d/y)
const parser = list(digit, text(','))
parser.parseToEnd('1,2,3') // [1, 2, 3]
Parser for each element of the list
Parser for the separator in the list
Attempts to parse using parser
. Returns a default value if it fails
const parser = maybeWithDefault(text('a'), 'b')
parser.parseToEnd('a') // 'a'
parser.parseToEnd('') // 'b'
Parser to execute
Default value to return if parser
fails
Match against a regular expression.
Regular expressions must be sticky (ex: /\d/y
)
Regular expression to match with
Error message, if it fails
Repeat a parser a set number of times
const parser = repeat(regexp(/d/y), 4)
parser.matches('1234') // true
parser.parseToEnd('1234') // ['1', '2', '3', '4']
Parser to execute
Number of times to execute it
Error message, if it fails
Match a literal string
String to match
Error message, if it fails
Generated using TypeDoc
A parser that always succeeds and returns a constant value
constant('hello').parseToEnd('') // 'hello'