Parser interface and combinators

Public API.

Parser

class reparsec.Parser
parse(stream, recover=False, *, max_insertions=5, get_loc=<function _get_loc>, fmt_loc=<function _fmt_loc>)

Parses input.

Parameters:
  • stream (TypeVar(S_contra, contravariant=True)) – Input to parse

  • recover (bool) – Flag to enable error recovery

  • max_insertions (int) – Maximal number of token insertions in a row during error recovery

  • get_loc (Callable[[Loc, TypeVar(S_contra, contravariant=True), int], Loc]) – Function that constructs new Loc from a previous Loc, a stream, and position in the stream

  • fmt_loc (Callable[[Loc], str]) – Function that converts Loc to string

Return type:

ParseResult[TypeVar(A_co, covariant=True), TypeVar(S_contra, contravariant=True)]

fmap(fn)

Transforms the result of the parser by applying fn to it.

>>> from reparsec.sequence import satisfy
>>> satisfy(str.isdigit).fmap(lambda x: int(x) + 1).parse("0").unwrap()
1
Parameters:

fn (Callable[[TypeVar(A_co, covariant=True)], TypeVar(B)]) – Function to produce new value from the result of the parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

bind(fn)

Calls fn with the result of the parser and then applies the returned parser.

>>> from reparsec.sequence import satisfy, sym
>>> parser = satisfy(lambda _: True).bind(lambda x: sym(x))
>>> parser.parse("aa").unwrap()
'a'
>>> parser.parse("bb").unwrap()
'b'
>>> parser.parse("ab").unwrap()
Traceback (most recent call last):
...
reparsec.types.ParseError: at 1: expected 'a'
Parameters:

fn (Callable[[TypeVar(A_co, covariant=True)], ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]]) – Function that returns a new parser using the result of this parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

seql(other)

Alias for TupleParser.__lshift__()

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

seqr(other)

Alias for TupleParser.__rshift__()

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

__lshift__(other)

Applies two parsers sequentially and returns the result of the first parser.

>>> from reparsec.sequence import sym
>>> (sym("a") << sym("b")).parse("ab").unwrap()
'a'
Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

__rshift__(other)

Applies two parsers sequentially and returns the result of the second parser.

>>> from reparsec.sequence import sym
>>> (sym("a") >> sym("b")).parse("ab").unwrap()
'b'
Parameters:
  • second – Second parser

  • other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)])

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

__add__(other)

Applies two parsers sequentially and returns a tuple of their results.

>>> from reparsec.sequence import sym
>>> parser = sym("a") + sym("b")
>>> parser.parse("ab").unwrap()
('a', 'b')
>>> parser.parse("ac").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 1: expected 'b'
Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), Tuple[TypeVar(A_co, covariant=True), TypeVar(B)]]

__or__(other)

Applies the first parser and returns its’ result unless it fails without consuming any input. In this case the second parser is applied and its’ result is returned.

>>> from reparsec.sequence import sym
>>> parser = sym("a") | sym("b")
>>> parser.parse("a").unwrap()
'a'
>>> parser.parse("b").unwrap()
'b'
>>> parser.parse("c").unwrap()
Traceback (most recent call last):
...
reparsec.types.ParseError: at 0: expected 'a' or 'b'
Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), Union[TypeVar(A_co, covariant=True), TypeVar(B)]]

maybe()

Applies the parser and returns None if it failed withoud consuming input. Otherwise returns the result of the parser.

Identical to parser | Pure(None). :rtype: TupleParser[TypeVar(S_contra, contravariant=True), Optional[TypeVar(A_co, covariant=True)]]

>>> from reparsec.sequence import sym
>>> parser = (sym("a") << sym("b")).maybe()
>>> parser.parse("ab").unwrap()
'a'
>>> parser.parse("bb").unwrap()
>>> parser.parse("aa").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 1: expected 'b'
many()

Applies the parser multiple times, until it fails. Returns a list of the parsed values if the parser failed withoud consuming input. :rtype: TupleParser[TypeVar(S_contra, contravariant=True), List[TypeVar(A_co, covariant=True)]]

>>> from reparsec.sequence import sym
>>> parser = (sym("a") << sym("b")).many()
>>> parser.parse("abab").unwrap()
['a', 'a']
>>> parser.parse("abbb").unwrap()
['a']
>>> parser.parse("abaa").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 3: expected 'b'
attempt()

Applies the parser, and pretends that no input was consumed if it fails.

This can be seen as switching the parser behaviour from LL(1)-like to PEG-like. :rtype: TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

>>> from reparsec.sequence import sym
>>> parser = (sym("a") << sym("b"))
>>> parser.maybe().parse("aa").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 1: expected 'b'
>>> parser.attempt().maybe().parse("aa").unwrap()
label(expected)

Applies the parser, and replaces list of expected values with [expected] if no input was consumed.

>>> from reparsec.sequence import sym
>>> parser = (sym("a") + sym("b")).label("x")
>>> parser.parse("bb").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: expected x
>>> parser.parse("aa").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 1: expected 'b'
Parameters:

expected (str) – Description of the expected input

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

recover()

Allows the parser to recover with repair sequences that starts with automatically inserted tokens. :rtype: TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

>>> from reparsec.sequence import eof, sym
>>> parser = (sym("a") + sym("b")) | (sym("b") + sym("c"))
>>> parser.parse("c", recover=True).unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: expected 'a' or 'b' (inserted 'a'),
at 0: expected 'b' (inserted 'b')
>>> parser = (sym("a") + sym("b")) | (sym("b").recover() + sym("c"))
>>> parser.parse("c", recover=True).unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: expected 'a' or 'b' (inserted 'b')
recover_with(x, label=None)

Applies the parser and returns its’ result unless it failed without consuming input while error recovery is enabled. In this case, the x is returned as a result of recovering from the error.

>>> from reparsec.sequence import satisfy
>>> parser = satisfy(str.isalpha).recover_with("b")
>>> parser.parse("a").unwrap()
'a'
>>> parser.parse("0").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: unexpected input
>>> parser.parse("0", recover=True).unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: unexpected input (inserted 'b')
>>> parser.parse("0", recover=True).unwrap(recover=True)
'b'
Parameters:
  • x (TypeVar(B)) – Parsed value

  • label (Optional[str]) – Description of the expected input

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), Union[TypeVar(A_co, covariant=True), TypeVar(B)]]

recover_with_fn(fn, label=None)

Applies the parser and returns its’ result unless it failed without consuming input while error recovery is enabled. In this case, the fn is called to produce a value that will be returned as a result of recovering from the error.

>>> from reparsec.sequence import satisfy
>>> parser = satisfy(str.isalpha).recover_with_fn(lambda s, p: "b")
>>> parser.parse("a").unwrap()
'a'
>>> parser.parse("0").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: unexpected input
>>> parser.parse("0", recover=True).unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 0: unexpected input (inserted 'b')
>>> parser.parse("0", recover=True).unwrap(recover=True)
'b'
Parameters:
  • fn (Callable[[TypeVar(S_contra, contravariant=True), int], TypeVar(A_co, covariant=True)]) – Function that produces a parsed value

  • label (Optional[str]) – Description of the expected input

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

sep_by(sep)

Applies the parser multiple times, with sep in between. Returns a list of the values parsed by the parser.

>>> from reparsec.sequence import sym
>>> parser = sym("a").sep_by(sym(","))
>>> parser.parse("a,a,a").unwrap()
['a', 'a', 'a']
Parameters:

sep (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Separators parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), List[TypeVar(A_co, covariant=True)]]

between(open, close)

Applies open, then the parser, then close, and returns the value parsed by the parser.

>>> from reparsec.sequence import sym
>>> parser = sym("a").between(sym("("), sym(")"))
>>> parser.parse("(a)").unwrap()
'a'
Parameters:
  • open (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – ‘Opening bracket’ parser

  • close (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(C)]) – ‘Closing bracket’ parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

chainl1(op)

Applies the parser one or more times, with op in between. Returns a value of left-associative application of functions returned by op to the values parsed by the parser.

>>> from reparsec.sequence import sym
>>> parser = sym("a").chainl1(
...     sym("+").fmap(lambda _: "({}+{})".format)
... )
>>> parser.parse("a+a+a").unwrap()
'((a+a)+a)'
Parameters:

op (ParseObj[TypeVar(S_contra, contravariant=True), Callable[[TypeVar(A_co, covariant=True), TypeVar(A_co, covariant=True)], TypeVar(A_co, covariant=True)]]) – Operator parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

chainr1(op)

Applies the parser one or more times, with op in between. Returns a value of right-associative application of functions returned by op to the values parsed by the parser.

>>> from reparsec.sequence import sym
>>> parser = sym("a").chainr1(
...     sym("^").fmap(lambda _: "({}^{})".format)
... )
>>> parser.parse("a^a^a").unwrap()
'(a^(a^a))'
Parameters:

op (ParseObj[TypeVar(S_contra, contravariant=True), Callable[[TypeVar(A_co, covariant=True), TypeVar(A_co, covariant=True)], TypeVar(A_co, covariant=True)]]) – Operator parser

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]

Helper types

class reparsec.TupleParser

A subclass of Parser with ability to build a tuple of up to eight results.

then(other)

Applies up to eight parsers sequentially and returns a tuple of their results.

>>> from reparsec.sequence import sym
>>> parser = sym("a").then(sym("b")).then(sym("c"))
>>> parser.parse("abc").unwrap()
('a', 'b', 'c')
>>> parser.parse("ac").unwrap()
Traceback (most recent call last):
  ...
reparsec.types.ParseError: at 1: expected 'b'
Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(B)]) – Next parser

Return type:

Tuple2[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True), TypeVar(B)]

class reparsec.Delay

A subclass of TupleParser to use as a forward declaration.

>>> from reparsec import Delay
>>> from reparsec.sequence import sym
>>> parser = Delay()
>>> parser.define((sym("a") + parser).maybe())
>>> parser.parse("aaa").unwrap()
('a', ('a', ('a', None)))
define(parser)

Define the parser.

>>> from reparsec import Delay
>>> from reparsec.sequence import sym
>>> parser = Delay()
>>> parser.parse("a")
Traceback (most recent call last):
  ...
RuntimeError: Delayed parser was not defined
>>> parser.define(sym("a"))
>>> parser.parse("a").unwrap()
'a'
Parameters:

parser (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A_co, covariant=True)]) – Parser definition

Return type:

None

class reparsec.Tuple2

A subclass of Parser that always returns tuples of two values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A2)]) – Next parser

Return type:

Tuple3[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple3

A subclass of Parser that always returns tuples of three values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A3)]) – Next parser

Return type:

Tuple4[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple4

A subclass of Parser that always returns tuples of four values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A4)]) – Next parser

Return type:

Tuple5[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple5

A subclass of Parser that always returns tuples of five values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A5)]) – Next parser

Return type:

Tuple6[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple6

A subclass of Parser that always returns tuples of six values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A6)]) – Next parser

Return type:

Tuple7[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5), TypeVar(A6)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple7

A subclass of Parser that always returns tuples of seven values.

then(other)

See TupleParser.then().

Parameters:

other (ParseObj[TypeVar(S_contra, contravariant=True), TypeVar(A7)]) – Next parser

Return type:

Tuple8[TypeVar(S_contra, contravariant=True), TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5), TypeVar(A6), TypeVar(A7)]

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5), TypeVar(A6)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

class reparsec.Tuple8

A subclass of Parser that always returns tuples of eight values.

apply(fn)

Applies fn to elements of parsed tuple.

Parameters:

fn (Callable[[TypeVar(A0), TypeVar(A1), TypeVar(A2), TypeVar(A3), TypeVar(A4), TypeVar(A5), TypeVar(A6), TypeVar(A7)], TypeVar(B)]) – Function to apply

Return type:

TupleParser[TypeVar(S_contra, contravariant=True), TypeVar(B)]

Combinators

reparsec.fmap(parser, fn)

Parser.fmap() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

  • fn (Callable[[TypeVar(A)], TypeVar(B)]) – Function to produce value from the result of parser

Return type:

TupleParser[TypeVar(S), TypeVar(B)]

reparsec.bind(parser, fn)

Parser.bind() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

  • fn (Callable[[TypeVar(A)], ParseObj[TypeVar(S), TypeVar(B)]]) – Function that returns a new parser using the result of the parser

Return type:

TupleParser[TypeVar(S), TypeVar(B)]

reparsec.seq(parser, second)

Parser.__add__() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – First parser

  • second (ParseObj[TypeVar(S), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S), Tuple[TypeVar(A), TypeVar(B)]]

reparsec.seql(parser, second)

Parser.seql() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – First parser

  • second (ParseObj[TypeVar(S), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.seqr(parser, second)

Parser.seqr() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – First parser

  • second (ParseObj[TypeVar(S), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S), TypeVar(B)]

reparsec.alt(parser, second)

Parser.__or__() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – First parser

  • second (ParseObj[TypeVar(S), TypeVar(B)]) – Second parser

Return type:

TupleParser[TypeVar(S), Union[TypeVar(A), TypeVar(B)]]

reparsec.maybe(parser)

Parser.maybe() as a function.

Parameters:

parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

Return type:

TupleParser[TypeVar(S), Optional[TypeVar(A)]]

reparsec.many(parser)

Parser.many() as a function.

Parameters:

parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

Return type:

TupleParser[TypeVar(S), List[TypeVar(A)]]

reparsec.attempt(parser)

Parser.attempt() as a function.

Parameters:

parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.label(parser, expected)

Parser.label() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

  • expected (str) – Description of the expected input

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.recover(parser)

Parser.recover() as a function.

Parameters:

parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.recover_with(parser, x, label=None)

Parser.recover_with() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

  • x (TypeVar(A)) – Parsed value

  • label (Optional[str]) – Description of the expected input

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.recover_with_fn(parser, fn, label=None)

Parser.recover_with_fn() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Parser

  • fn (Callable[[TypeVar(S), int], TypeVar(A)]) – Function that produces a parsed value

  • label (Optional[str]) – Description of the expected input

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.sep_by(parser, sep)

Parser.sep_by() as a function.

Parameters:
  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Items parser

  • sep (ParseObj[TypeVar(S), TypeVar(B)]) – Separators parser

Return type:

TupleParser[TypeVar(S), List[TypeVar(A)]]

reparsec.between(open, close, parser)

Parser.between() as a function.

Parameters:
  • open (ParseObj[TypeVar(S), TypeVar(B)]) – ‘Opening bracket’ parser

  • close (ParseObj[TypeVar(S), TypeVar(C)]) – ‘Closing bracket’ parser

  • parser (ParseObj[TypeVar(S), TypeVar(A)]) – Value parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.chainl1(arg, op)

Parser.chainl1() as a function.

Parameters:
  • arg (ParseObj[TypeVar(S), TypeVar(A)]) – Argument parser

  • op (ParseObj[TypeVar(S), Callable[[TypeVar(A), TypeVar(A)], TypeVar(A)]]) – Operator parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

reparsec.chainr1(arg, op)

Parser.chainr1() as a function.

Parameters:
  • arg (ParseObj[TypeVar(S), TypeVar(A)]) – Argument parser

  • op (ParseObj[TypeVar(S), Callable[[TypeVar(A), TypeVar(A)], TypeVar(A)]]) – Operator parser

Return type:

TupleParser[TypeVar(S), TypeVar(A)]

Output

class reparsec.ParseResult

Result of the parsing.

abstract fmap(fn)

Transforms ParseResult[A_co, S] into ParseResult[B, S] by applying fn to value.

Parameters:

fn (Callable[[TypeVar(A_co, covariant=True)], TypeVar(B)]) – Function to apply to value

Return type:

ParseResult[TypeVar(B), TypeVar(S)]

abstract unwrap(recover=False)

Returns parsed value if there is one. Otherwise throws ParseError.

Parameters:

recover (bool) – Flag to enable error recovery

Raise:

ParseError

Return type:

TypeVar(A_co, covariant=True)

exception reparsec.ParseError(errors)

Exception that is raised if a parser was unable to parse the input.

Parameters:

errors (List[ErrorItem]) – List of errors

class reparsec.ErrorItem(loc, loc_str, expected, op=None)

Description of a single parse error.

Parameters:
  • loc (Loc) – Location of the error

  • loc_str (str) – String representation of the location

  • expected (List[str]) – List of expected tokens descriptions

  • op (Union[Skip, Insert, None]) – Input modification that was applied to recover from the error

property msg: str

Human-readable description of the error.

class reparsec.Loc(pos, line, col)
pos: int

Alias for field number 0

line: int

Alias for field number 1

col: int

Alias for field number 2

class reparsec.Insert(label)
Parameters:

label (str)

class reparsec.Skip(count)
Parameters:

count (int)