exceptions module

Error handling.

Used in the Logic Simulator project. Mainly used by the parser.

class exceptions.Errors

Bases: object

Collect and handle errors found while parsing circuit descriptions.

Parameters
add_error(error: exceptions.ParseBaseException, show_end_of_word: bool, show_cursor=True, parse_entry_func_name='parse_network', base_depth=2) None

Add an error to the error list.

Parameters
  • error (ParseBaseException) – The error instance

  • show_end_of_word (bool) – Set caret sign to the end or beginning of symbol

  • show_cursor (bool) – Show caret sign or not

  • parse_entry_func_name (str) – The name of the top level parse function

  • base_depth – Extra stack depth added on top of the top level parse function, by error handling functions.

print_error_messages(names: names.Names, scanner: Scanner) None

Pretty print all error messages.

class exceptions.ParseBaseException(description=None, end_of_word=False, show_cursor=True)

Bases: object

Base parse exception.

description: Union[None, str]

Error description

symbol

The symbol associated with the error

Type

Union[Symbol, None]

depth

The stack depth where the error is thrown

Type

int

explain(names: names.Names, scanner: Scanner, show_depth=True) str

Return an explanation of the error.

If show_depth is True, the error message will be indented according to the stack depth of the function that throws the error.

message = 'Base parse exception'
class exceptions.ParseBaseExceptionMeta(classname, bases, dictionary)

Bases: type

Metaclass create ParseBaseException classes.

This allows default message to be defined using the doc string, simplify the code.

class exceptions.SemanticErrors

Bases: object

Different types of semantic errors.

class ConnectInToIn(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Attempting to connect input pin to input pin.

message = 'Attempting to connect input pin to input pin'
symbol: Union[Symbol, None]
class ConnectOutToOut(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Attempting to connect output pin to output pin.

message = 'Attempting to connect output pin to output pin'
symbol: Union[Symbol, None]
class FloatingInput(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Floating input.

message = 'Floating input'
symbol: Union[Symbol, None]
class InvalidAndParam(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Invalid number of inputs for the gate.

message = 'Invalid number of inputs for the gate'
symbol: Union[Symbol, None]
class InvalidClockParam(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Invalid clock period.

message = 'Invalid clock period'
symbol: Union[Symbol, None]
class MonitorInputPin(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Attempting to monitor an input pin.

message = 'Attempting to monitor an input pin'
symbol: Union[Symbol, None]
class MonitorSamePin(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Warning: duplicate monitor pin.

message = 'Warning: duplicate monitor pin'
symbol: Union[Symbol, None]
class MultipleConnections(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Attempting to connect multiple pins to a single pin.

message = 'Attempting to connect multiple pins to a single pin'
symbol: Union[Symbol, None]
class NameClash(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

NameClash.

message = 'NameClash'
symbol: Union[Symbol, None]
class UndefinedDevice(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Undefined device name.

message = 'Undefined device name'
symbol: Union[Symbol, None]
class UndefinedInPin(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Undefined input pin.

message = 'Undefined input pin'
symbol: Union[Symbol, None]
class UndefinedOutPin(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Undefined output pin.

message = 'Undefined output pin'
symbol: Union[Symbol, None]
class exceptions.SyntaxErrors

Bases: object

Different types of syntax errors.

class InvalidSwitchParam(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Invalid parameter for SWITCH device.

message = 'Invalid parameter for SWITCH device'
symbol: Union[Symbol, None]
class MissingParam(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Missing parameter for device type.

message = 'Missing parameter for device type'
symbol: Union[Symbol, None]
class MissingSemicolon(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Missing ‘;’ at the end of statement.

message = "Missing ';' at the end of statement"
symbol: Union[Symbol, None]
class NoConnections(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

No connections found.

message = 'No connections found'
symbol: Union[Symbol, None]
class NoDevices(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

No devices found.

message = 'No devices found'
symbol: Union[Symbol, None]
class NoMonitors(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

No monitor pins found.

message = 'No monitor pins found'
symbol: Union[Symbol, None]
class UnexpectedEOF(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Unexpected end of file.

message = 'Unexpected end of file'
symbol: Union[Symbol, None]
class UnexpectedParam(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Unexpected parameter for device type.

message = 'Unexpected parameter for device type'
symbol: Union[Symbol, None]
class UnexpectedToken(description=None, end_of_word=False, show_cursor=True)

Bases: exceptions.ParseBaseException

Unexpected token.

message = 'Unexpected token'
symbol: Union[Symbol, None]