buildingmotif.label_parsing.parser#

Functions

analyze_failures(failures)

Analyze the failures of a parser.

first_true(iterable[, default, pred])

Returns the first true value in the iterable.

parse(parser, target)

Parse the given target string using the given parser.

parse_list(parser, target_list)

Parse a list of strings using the given parser.

results_to_tokens(results)

Classes

ParseResult(tokens, success, _errors)

Parser(*args, **kwargs)

class ParseResult(tokens: List[buildingmotif.label_parsing.tokens.TokenResult], success: bool, _errors: List[str] = <factory>)[source]#
tokens: List[TokenResult]#
success: bool#
property errors#

Return a list of errors and the offset into the string where the error occurred.

class Parser(*args, **kwargs)[source]#
results_to_tokens(results)[source]#
analyze_failures(failures: Dict[str, List[TokenResult]])[source]#

Analyze the failures of a parser.

parse_list(parser, target_list) Tuple[Dict[str, List[TokenResult]], Dict[str, List[TokenResult]]][source]#

Parse a list of strings using the given parser.

Parameters:
  • parser (Parser) – the parsing combinator function

  • target_list (List[str]) – the list of strings to parse

Returns:

a tuple of the results and failures

parse(parser: Parser, target: str) ParseResult[source]#

Parse the given target string using the given parser.

Parameters:
  • parser (Parser) – the parsing combinator function

  • target (str) – the target string to parse

Returns:

the result of the parser

Return type:

ParseResult

first_true(iterable, default=None, pred=None)[source]#

Returns the first true value in the iterable.

If no true value is found, returns default

If pred is not None, returns the first item for which pred(item) is true.