ts_lib_parsy.error module#
- truncate_text_horizontally(lines: List[str], column: int, half_width: int = 40) Tuple[List[str], int][source]#
Given a list of lines, a target column (the column index where parsing failed), and the target width to truncate to - truncate all lines while keeping them aligned, centered around the target column.
- line_context(stream: str, index: int, lines_of_context: int = 2, half_width: int = 40) Tuple[List[str], str, List[str], int][source]#
Select a window of rows and columns of text Break text based on newlines, then given an index into that text, return:
The lines before the target line
The target line
The lines after the target line
The column index of the target character
- display_line_context(error: ParseError) str[source]#
Create a string containing the context of a file around a parsy parsing error
- parser_failure_message(error: ParseError, show_expected: bool = True, show_context: bool = True) str[source]#
Create a message from a Parsy parsing error, including the lines of text where parsing failed, along with the list of parser descriptions which were expected to match this part of the text. The expected parser text comes from the parsy.Parser.desc method.
For example, an error output could look like this:
Parsing failed, expected to match one of: - End of row of `Measurement Data` section containing 1 column(s) - `Measurement Data` section comment surrounded by double quotes -------------------------------------------------------------------------------- Wavelength: 450nm Interval: 1 A01: 0.040, 1.10 ~~~~~~~~~~^ Parsing failed here A02: 0.040 A03: 0.039 --------------------------------------------------------------------------------