FABulous.fabric_generator.parser.parse_switchmatrix

Parser functions for switch matrix and list file configurations.

This module provides utilities for parsing switch matrix CSV files and list files used in fabric definition. It handles expansion of port definitions, connection mappings, and validation of port configurations.

Classes

Functions

expandListPorts(port, portList)[source]
Parameters:
Return type:

None

Expand the .list file entry into a list of tuples.

param port:

The port entry to expand. If it contains “[”, it’s split into multiple entries based on “|”.

type port:

str

param portList:

The list where expanded port entries are appended.

type portList:

list[str]

raises ValueError:

If the port entry contains “[” or “{” without matching closing bracket “]”/”}”.

parseList(filePath: Path, collect: Literal['pair'] = 'pair')[source]

Parse a list file and expand the list file information into a list of tuples.

param filePath:

The path to the list file to parse.

type filePath:

Path

param collect:

Collect value by source, sink or just as pair. Defaults to “pair”.

type collect:

Literal[“pair”, “source”, “sink”], optional

raises FileNotFoundError:

The file does not exist.

raises InvalidListFileDefinition:

Invalid format in the list file.

returns:

Return either a list of connection pairs or a dictionary of lists which is collected by the specified option, source or sink.

rtype:

list[tuple[str, str]] | dict[str, list[str]]

parseMatrix(fileName, tileName)[source]
Parameters:
Return type:

dict[str, list[str]]

Parse the matrix CSV into a dictionary from destination to source.

param fileName:

Directory of the matrix CSV file.

type fileName:

Path

param tileName:

Name of the tile needed to be parsed.

type tileName:

str

raises InvalidSwitchMatrixDefinition:

Non matching matrix file content and tile name

returns:

Dictionary from destination to a list of sources.

rtype:

dict[str, list[str]]

parsePortLine(line)[source]
Parameters:

line (str)

Return type:

tuple[list[Port], tuple[str, str] | None]

Parse a single line of the port configuration from the CSV file.

param line:

CSV line containing port configuration data.

type line:

str

raises InvalidPortType:

If the port definition is invalid.

returns:

A tuple containing a list of parsed ports and an optional common wire pair.

rtype:

tuple[list[Port], tuple[str, str] | None]

Module Attributes

oppositeDic[source]