API Doc
dine.exceptions module
- exception dine.exceptions.InvalidBranchException
Bases:
ParseException
- exception dine.exceptions.ParseException(msg)
Bases:
Exception
dine.parser module
- class dine.parser.Parser(parse_fn, *, label)
Bases:
Generic[A]- and_then(other)
Parses A and then B
- apply(f_parser)
Functional apply function for parsers
This function takes a parser that parses a converting function from type A to type B and converts it into a function that converts a parser of A to a parser of B.
- bind(f)
This method may be used to put a parser after the current parser, with the later parser potentially depends on the output of the current parser.
This method passes the output of the current parser to the function f to create a new parser. This new parser will take the remaining of the parse stream if the current parser parses successfully. This method is akin to the bind function in functional programming.
- Parameters
f (Callable[[A], Parser[B]]) – a parser creating function that takes an object of type A (the type of the current parser) and create a parser of type B. If the current parser successfully parses, the B parser then takes the remaining stream from the result of the current parser.
- Return type
A parser of type B
- static char(char)
Parser for a single character
- Parameters
char (str) – the character to parse
- Return type
Parser[str]
- static choice(parsers)
Parser that parses the first matching alternative
Parser for a list of alternatives. The first matching alternative is parsed.
- static just(a)
A parser that always parses successfully and returns the desired value without affecting the parse stream
- Parameters
a (A) – the value
- Returns
A parser that always successfully parses the value while keeping the parse stream unchanged
- Return type
Parser[A]
- many0()
Parses 0 or more times
- Returns
Parser that parses A 0 or more times
- Return type
Parser[list]
- many0_sep_by(sep_parser)
Parses 0 or more times with separator
Parses A 0 or more times with a separator between each pair of occurences.
- many1_sep_by(sep_parser)
Parses 1 or more times with separator
Parses A 1 or more times with a separator between each pair of occurences.
- map(f)
If the parser parses successfully, pass the result to a function
- Parameters
f (Callable[[A], B]) – the function that takes the output of the parser and convert it to a new object
- Return type
Parser[B]
- optional(default=None)
Parses 0 or 1 time
- Returns
Parser that parses A 0 or 1 time
- Return type
Parser[list]
- or_else(other)
Parses A or B
- preceded_by(other)
Parses A preceded by something
- static satisfy(predicate, *, label='satisfy')
Parser that parses the next character if the predicate is True
- Parameters
label (str) – label of the parser
predicate (Callable[[str], bool]) – the condition on which the next character is parsed or not
- Return type
Parser[str]
- static sequence(parsers)
Parser for a sequence of things
- static string(literal)
Parser that parses a string literal
- Parameters
literal (str) – The string literal
- Return type
Parser[str]
- succeeded_by(other)
Parses A preceded by something
- surrounded_by(lparser, rparser)
Parses A surrounded by two other things
dine.result module
- class dine.result.ParseFailure(loc, label, msg)
Bases:
ParseResultResult of the parser when it does not parse successfully
- class dine.result.ParseResult(loc)
Bases:
Generic[A]Base class for parse result
- class dine.result.ParseSuccess(loc, val, rs)
Bases:
ParseResult[A]Result of the parser when it parses successfully
dine.stream module
- class dine.stream.Location(line, col)
Bases:
object