Value from parsing
Source that value was parsed from
Line at the end of the result
Column at the end of the result
Column at the end of the result
Line at the end of the result
Source that value was parsed from
Value from parsing
The core parser which provides functions for combining parsers
Defines how to parse source
Defines how to parse source
Captures the result of this parser and bind another parser
const parser = regexp(/\d/y).bind(digit => text(`${digit}abc`))
parser.matches('11abc') // true
parser.matches('99abc') // true
Maps the result of a parser to a different value
const parser = regexp(/\d/y).map(Number)
parser.parseToEnd('1') // 1
Mapping function
Returns true if the parser can parse the given string
const parser = text('a')
parser.matches('a') // true
parser.matches('b') // false
Input
Returns true if the parse can parse the given string to the end
const parser = text('a')
parser.matchesToEnd('a') // true
parser.matchesToEnd('ab') // false
Input
Attempts to parse a string to the end. Fails if the parser does not parse the entire input
const parser = text('a')
parser.parseToEnd('a') // 'a'
parse.parseToEnd('a1') instanceof ParseError // true
Input string
Source for parsing
Source input
Where in the input to begin parsing
Line which source[index]
is on
Column which source[index]
is on
Column which source[index]
is on
Where in the input to begin parsing
Line which source[index]
is on
Source input
Get the remaining input
Attempt to match the source against a regular expression
Regular expression to match
Error message if it fails
Attempt to match the source against a literal string
Text to match
Error message, if it fails
A parser that always succeeds and returns a constant value
constant('hello').parseToEnd('') // 'hello'
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
Result of parsing