rads.config.xml_parsers module¶
Parser combinators for reading XML files.
This module is heavily based on PEGTL, a parser combinator library for C++.
Exceptions¶
Name |
Description |
|---|---|
Parse error that fails parsing of XML file. |
|
Parse error that fails a single parser. |
Parser Combinators (class based API)¶
Name |
Description |
|---|---|
Base class of all parser combinators. |
|
Apply a function the value result of a parser. |
|
Delay parser construction until evaluation. |
|
Require parser to succeed. |
|
Non consuming match. |
|
Invert a parser match, non consuming. |
|
Match zero or more times (greedily). |
|
Chain parsers together, all or nothing match. |
|
Chain parsers together, taking first success. |
|
Always succeeds, non consuming. |
|
Always fails, non consuming. |
|
Match beginning of XML block. |
|
Match end of XML block. |
|
Match any XML element. |
|
Match an XML element by it’s tag name. |
Parser Combinators (function based API)¶
Name |
Description |
|---|---|
Delay parser construction until evaluation. |
|
Non consuming match. |
|
Invert a parser match, non consuming. |
|
Optional match, always succeeds. |
|
Match one or more times (greedily). |
|
Match a sequence of parsers, all or nothing. |
|
Use first matching parser. |
|
Match zero ore more times (greedily). |
|
Require parser to succeed. |
|
Match N times. |
|
Consume elements until a match, match not consumed. |
|
Always fails, non consuming. |
|
Always succeeds, non consuming. |
|
Match beginning of XML block. |
|
Match end of XML block. |
|
Match any XML element. |
|
Match an XML element by it’s tag name. |
-
exception
rads.config.xml_parsers.TerminalXMLParseError(file: Optional[str], line: Optional[int], message: Optional[str] = None)[source]¶ Bases:
ExceptionA parse error that should fail parsing of the entire file.
- Parameters
file – Name of file that was being parsed when the error occurred.
line – Line number in the file that was being parsed when the error occurred.
message – An optional message (instead of the default ‘parsing failed’) detailing why the parse failed.
-
file= None¶ Filename where the error occurred.
-
message= 'parsing failed'¶ The message provided when the error was constructed.
-
exception
rads.config.xml_parsers.XMLParseError(file: Optional[str], line: Optional[int], message: Optional[str] = None)[source]¶ Bases:
rads.config.xml_parsers.TerminalXMLParseErrorA parse error that signals that a given parser failed.
Unlike
TerminalXMLParseErroris expected and simply signals that the parser did not match and another parser should be tried.- Parameters
file – Name of file that was being parsed when the error occurred.
line – Line number in the file that was being parsed when the error occurred.
message – An optional message (instead of the default ‘parsing failed’) detailing why the parse failed.
-
rads.config.xml_parsers.next_element(pos: rads.xml.base.Element) → rads.xml.base.Element[source]¶ Get next element lazily.
- Parameters
pos – Current element.
- Returns
Next sibling XML element.
- Raises
XMLParseError – If there is no next sibling element.
-
rads.config.xml_parsers.first_child(pos: rads.xml.base.Element) → rads.xml.base.Element[source]¶ Get first child of element, lazily.
-
class
rads.config.xml_parsers.Parser[source]¶ Bases:
abc.ABCBase parser combinator.
-
abstract
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
__add__(other: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Sequence[source]¶ Combine two parsers, matching the first followed by the second.
Multiple consecutive uses of ‘+’ will result in a single
Sequencebecause theSequenceclass automatically flattens itself.- Parameters
other – The parser to match after this one.
- Returns
A new parser that will match this parser followed by the other parser (if the this parser matched).
-
__or__(other: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Alternate[source]¶ Combine two parsers, matching the first or the second.
Multiple consecutive uses of ‘|’ will result in a single
Alternatebecause theAlternateclass automatically flattens itself.- Parameters
other – The parser to match if this parser does not.
- Returns
A new parser that will match either this parser or the other parser (if the this parser did not match).
-
__xor__(func: Callable[[Any], Any]) → rads.config.xml_parsers.Apply[source]¶ Apply a function to the value result of this parser.
- Parameters
func –
The function to apply to the value result of matching this parser.
Note
This will not be ran until this parser is matched.
- Returns
A new parser that will match this parser and upon a successful match apply the given func to the value result.
-
__invert__() → rads.config.xml_parsers.Not[source]¶ Invert this parser.
If this parser would match a given position, now it will not. If it would not match now it will, but it will not consume any elements.
- Returns
A new parser that will not match whenever this parser does, and will match whenever this parser does not. However, it will not consume any elements.
-
__lshift__(message: str) → rads.config.xml_parsers.Must[source]¶ Require the parser to succeed.
This will convert all
XMLParseErrors toTerminalXMLParseErrors.- Parameters
message – The message that will be raised if the parser does not match.
- Returns
A new parser that will elevate any local parse failures to global failures and overwrite their message with message.
-
abstract
-
class
rads.config.xml_parsers.Apply(parser: rads.config.xml_parsers.Parser, func: Callable[[Any], Any], catch: Optional[Collection[type]] = None)[source]¶ Bases:
rads.config.xml_parsers.ParserApply a function to the value result of the parser.
- Parameters
parser – The parser whose value result to apply the given func to the value result of.
func – The function to apply.
catch –
An exception or iterable of exceptions to convert into
XMLParseErrors. The default is not to catch any exceptions. To catch all exceptions simply passExceptionas it is the base class of all exceptions that should be caught.Note
Any exceptions that are derived from the exceptions given will also be caught.
-
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.Lazy(parser_func: Callable[[], rads.config.xml_parsers.Parser])[source]¶ Bases:
rads.config.xml_parsers.ParserDelay construction of parser until evaluated.
Note
This lazy behavior is useful when constructing recursive parsers in order to avoid infinite recursion.
- Parameters
parser_func – A zero argument function that returns a parser when called. This will be used to delay construction of the parser.
-
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.Must(parser: rads.config.xml_parsers.Parser, message: Optional[str] = None)[source]¶ Bases:
rads.config.xml_parsers.ParserRaise a XMLParseError to a TerminalXMLParseError ending parsing.
- Parameters
parser – Parser that must match.
message – New message to apply to the
GlobalParserFailureif the parser does not match.
-
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.At(parser: rads.config.xml_parsers.Parser)[source]¶ Bases:
rads.config.xml_parsers.ParserMatch a parser, consuming nothing.
- Parameters
parser – Parser to match.
-
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.Not(parser: rads.config.xml_parsers.Parser)[source]¶ Bases:
rads.config.xml_parsers.ParserInvert a parser match, consuming nothing.
- Parameters
parser – Parser to invert the match of.
-
__call__(position: rads.xml.base.Element) → Tuple[None, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.Repeat(parser: rads.config.xml_parsers.Parser)[source]¶ Bases:
rads.config.xml_parsers.ParserMatch a parser zero or more times (greedily).
- Parameters
parser – Parser to match repeatedly.
-
__call__(position: rads.xml.base.Element) → Tuple[List[Any], rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
class
rads.config.xml_parsers.Sequence(*parsers: rads.config.xml_parsers.Parser)[source]¶ Bases:
rads.config.xml_parsers._MultiParserChain parsers together, succeeding only if all succeed in order.
Note
Consecutive Sequence’s are automatically flattened.
- Parameters
*parsers – Parsers to match in sequence.
-
__call__(position: rads.xml.base.Element) → Tuple[List[Any], rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
__add__(other: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Sequence[source]¶ Combine this sequence and a parser, returning a new sequence.
Note
If the other parser is a
Sequencethen the parsers in the otherSequencewill be unwrapped and appended individually.- Parameters
other – The parser to combine with this sequence to form the new sequence.
- Returns
A new sequence which matches this sequence followed by the given parser (if the sequence matched).
-
__iadd__(other: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Sequence[source]¶ Combine this sequence with the given parser (in place).
Note
If the other parser is a
Sequencethen the parsers in the otherSequencewill be unwrapped and appended to this sequence individually.- Parameters
other – The parser to combine with (append to) this sequence.
- Returns
This sequence parser.
-
class
rads.config.xml_parsers.Alternate(*parsers: rads.config.xml_parsers.Parser)[source]¶ Bases:
rads.config.xml_parsers._MultiParserMatch any one of the parsers, stops on first match.
Note
Consecutive Alternate’s are automatically flattened.
- Parameters
*parsers – Pool of parsers to find a match in.
-
__call__(position: rads.xml.base.Element) → Tuple[Any, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
__or__(other: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Alternate[source]¶ Combine this alternate and a parser, returning a new alternate.
Note
If the other parser is a
Alternatethen the parsers in the otherAlternatewill be unwrapped and added individually.- Parameters
other – The parser to combine with this alternate to form the new alternate.
- Returns
A new alternate which matches any parser from this alternate or the given parser (if no parser of this alternate matches).
-
class
rads.config.xml_parsers.Success[source]¶ Bases:
rads.config.xml_parsers.ParserParser that always succeeds, consuming nothing.
-
__call__(position: rads.xml.base.Element) → Tuple[None, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
-
class
rads.config.xml_parsers.Failure[source]¶ Bases:
rads.config.xml_parsers.ParserParser that always fails, consuming nothing.
-
__call__(position: rads.xml.base.Element) → NoReturn[source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
-
class
rads.config.xml_parsers.Start[source]¶ Bases:
rads.config.xml_parsers.ParserMatch start of an element, consuming nothing.
-
__call__(position: rads.xml.base.Element) → Tuple[None, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
-
class
rads.config.xml_parsers.End[source]¶ Bases:
rads.config.xml_parsers.ParserMatch end of an element, consuming nothing.
-
__call__(position: rads.xml.base.Element) → Tuple[None, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
-
class
rads.config.xml_parsers.AnyElement[source]¶ Bases:
rads.config.xml_parsers.ParserParser that matches any element.
-
__call__(position: rads.xml.base.Element) → Tuple[rads.xml.base.Element, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
-
class
rads.config.xml_parsers.Tag(name: str)[source]¶ Bases:
rads.config.xml_parsers.ParserMatch an element by it’s tag name.
- Parameters
name – Tag name to match.
-
__call__(position: rads.xml.base.Element) → Tuple[rads.xml.base.Element, rads.xml.base.Element][source]¶ Call the parser, trying to match at the given position.
If the match fails a
XMLParseErrorwill be raised. This call will only return if the parser matches at the given position.- Parameters
position – An XML element that the parser should attempt to match at.
- Returns
A tuple giving the value result of the match (which depends on the particular parser) and the element to match at.
The next element can be the same element as given in position (a non consuming parser) or any later sibling element.
Further, it will actually be a
yzal.Thunkand will therefore delay it’s construction until it is needed. Therefore, anyXMLParseErrorthat may be generated by moving to a later element will occur when the returned element is used.- Raises
XMLParseError – If the parser does not match at the given position.
TerminalXMLParseError – If the parser encounters an unrecoverable error.
-
rads.config.xml_parsers.lazy(parser_func: Callable[[], rads.config.xml_parsers.Parser]) → rads.config.xml_parsers.Parser[source]¶ Delays construction of parser until evaluated.
- Parameters
parser_func – A zero argument function that returns a parser when called. This will be used to delay construction of the parser.
- Returns
A new parser that is equivalent to the parser returned by parser_func.
-
rads.config.xml_parsers.at(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Succeeds if and only if the given parser succeeds, consumes nothing.
- Parameters
parser – The parser that must succeed.
- Returns
A new parser that succeeds if and only if parser succeeds, but does not consume input.
-
rads.config.xml_parsers.not_at(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Succeeds if and only if the given parser fails, consumes nothing.
- Parameters
parser – The parser that must fail.
- Returns
A new parser that succeeds if and only if parser fails, but does not consume input.
-
rads.config.xml_parsers.opt(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Parser that always succeeds, regardless of the given parser.
- Parameters
parser – An optional parser that can succeed or fail.
- Returns
A new parser that optionally matches parser. If parser succeeds this parser will be transparent, as if parser was called directly. If parser fails this
opt()returns None as the result and does not consume anything.
-
rads.config.xml_parsers.plus(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Match the given parser as much as possible, must match at least once.
- Parameters
parser – Parser to match one or more times (greedily).
- Returns
A new parser that matches parser one or more times. Failing if no matches are made.
-
rads.config.xml_parsers.seq(*parsers: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Match sequence of parsers in order, succeeding if and only if all succeed.
- Parameters
*parsers – One or more parsers to match in order.
- Returns
A new parser that matches all the given parser’s in order, failing if any one of the parser’s fail.
-
rads.config.xml_parsers.sor(*parsers: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Match the first of the given parsers, failing if all fail.
- Parameters
*parsers – One or more parsers to match. The first parser that succeeds will take the place of this parser. If all fail then this parser will also fail.
- Returns
A new parser that matches the first parser that succeeds or fails if all parser’s fail.
-
rads.config.xml_parsers.star(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Match the given parser as much as possible, can match zero times.
- Parameters
parser – Parser to match zero or more times (greedily).
- Returns
A new parser that matches parser one or more times. Failing if no matches are made.
-
rads.config.xml_parsers.must(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Raise a local parse failure to a global parse failure.
Local parse failures (
XMLParseError) are typically caught byAlternateor other such parsers that allow some parser’s to fail. In particular, local failures are an expected part of parser combinators and simply signal that a particular parser could not parse the given elements. A global parse failure (TerminalXMLParseError) should only be caught at the top level and signals that the entire parse is a failure.- Parameters
parser – A parser that must match, else the entire parse is failed.
- Returns
A parser that must succeed, if it fails a
GlobalParserFailureis raised.
-
rads.config.xml_parsers.rep(parser: rads.config.xml_parsers.Parser, times: int) → rads.config.xml_parsers.Parser[source]¶ Match the given parser a given number of times.
Fails if the parser does not succeed the given number of times.
- Parameters
parser – The parser to match times.
times – Number of times the parser must succeed.
- Returns
A parser that succeeds only if the given parser matches the given number of times.
-
rads.config.xml_parsers.until(parser: rads.config.xml_parsers.Parser) → rads.config.xml_parsers.Parser[source]¶ Match all elements until the given parser matches.
Does not consume the elements that the given parser matches.
- Parameters
parser – The parser to end matching with.
- Returns
A parser that will consume all elements until the given parser matches. It will not consume the elements that the given parser matched.
-
rads.config.xml_parsers.failure() → rads.config.xml_parsers.Parser[source]¶ Parser that always fails.
- Returns
A new parser that always fails, consuming nothing.
-
rads.config.xml_parsers.success() → rads.config.xml_parsers.Parser[source]¶ Parser that always succeeds.
- Returns
A new parser that always succeeds, consuming nothing.
-
rads.config.xml_parsers.start() → rads.config.xml_parsers.Parser[source]¶ Match the beginning of an element.
- Returns
A new parser that matches the beginning of an element, consuming nothing.
-
rads.config.xml_parsers.end() → rads.config.xml_parsers.Parser[source]¶ Match the end of an element.
- Returns
A new parser that matches the end of an element, consuming nothing.