pycoparsec package¶
Submodules¶
pycoparsec.parser module¶
- exception pycoparsec.parser.DoneParsing(remaining: ~typing.Iterator[~pycoparsec.parser.S] = <tuple_iterator object>)[source]¶
Bases:
Exception
,Generic
[S
]The parser that raised this exception reached the end of the input. Eventually, there will be ways to perform early exits or otherwise indicate parsing is finished. That will be what the currently unused
remaining
argument will be for.
- exception pycoparsec.parser.FailedParsing[source]¶
Bases:
Exception
The parser that raised this exception did not match the current tokens.
- class pycoparsec.parser.Parser[source]¶
Bases:
Generic
[S
,O
]This class implements a parser-combinator style parser on arbitrary None-less iterators.
- Variables:
matcher – The meat-and-potatoes of the parser. Takes in the next token from the stream, and the rest of the token iterator. Gives back either a constructed output object or None if the parse failed.
choices – A list of other Parsers to try in order if this Parser fails. By default, a newly constructed parser always fails, so something like
Parser().choice(parser1, parser2)
will always defer toparser1
and thenparser2
.
- choice(choices: List[Parser[S, O]]) Parser[S, O] [source]¶
Add a list of alternative Parsers in the case that this Parser fails.
- exactly(token: S, factory: Callable[[S], O]) Parser[S, O] [source]¶
Match one element of the input stream exactly, then exit.
- then(parser: Parser[S, O]) Parser[S, O] [source]¶
Chain another parser onto this one, linking their success states together.
Successful parse chains call __add__ on the output object to append them together. If the default behavior of __add__ does not support the behavior you want, please make a new class which overrides __add__ and inherits behavior from your desired output type.