knit_script.knit_script_exceptions.parsing_exception module

Module containing parsing exception class.

This module provides the Parsing_Exception class, which handles syntax and parsing errors that occur when processing KnitScript source code. It wraps and enhances parglare ParseError objects with KnitScript-specific formatting and context information, providing detailed location information, code context, and expected token information to help developers debug syntax errors in their knit script programs.

exception Parsing_Exception(parglare_parse_error)[source]

Bases: Knit_Script_Exception

Exception raised when there is an error parsing KnitScript code.

The Parsing_Exception class provides enhanced error reporting for syntax errors in KnitScript source code. It wraps parglare ParseError objects and extracts detailed location information, code context, and expected token information to create comprehensive error messages that help developers identify and fix syntax issues.

This exception provides formatted error messages that include the file name (if available), line number, a visual representation of the error location within the source code, and information about what tokens the parser was expecting at the point of failure.

parse_error

The original ParseError from the parglare parser.

Type:

ParseError

error_location

The location information for where the parsing error occurred.

Type:

Location

_location_message

Formatted location information including file and line number.

Type:

str

_location_example

Code context showing the position where the error occurred.

Type:

str

_expected

Formatted list of expected tokens at the error position.

Type:

str

Parameters:

parglare_parse_error (ParseError)

__init__(parglare_parse_error)[source]

Initialize the Parsing_Exception.

Creates a new parsing exception from a parglare ParseError, extracting location information and formatting a comprehensive error message with context and expected token information.

Parameters:

parglare_parse_error (ParseError) – The original ParseError from the parglare parser containing the raw parsing failure information.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.