dictIO.dictParser module#

class dictIO.dictParser.DictParser#

Bases: object

Parser for dictionaries in dictIO dict file format, as well as JSON and XML.

DictParser is a convenience class. DictParser.parse() combines the operations of DictReader.read() and DictWriter.write() .

static parse(source_file: str | PathLike[str], includes: bool = True, mode: str = 'w', order: bool = False, comments: bool = True, scope: MutableSequence[str] | None = None, output: str | None = None) CppDict | None#

Parse a dictionary file and save it with prefix ‘parsed.’.

DictParser.parse() combines the otherwise atomic operations of DictReader.read() and DictWriter.write() in one chunk:

1: parsed_dict = DictReader.read(source_file)

2: DictWriter.write(parsed_dict, target_file)

The parsed dict is saved with prefix ‘parsed.’ Example: Parsing source file ‘xyz’ will result in parsed file ‘parsed.xyz’ being generated.

The parsed dict will by default be written in dictIO’s default dict file format. Optionally, output format can be changed to JSON, XML and OpenFOAM.

Parameters:
  • source_file (Union[str, os.PathLike[str]]) – dict file to be parsed

  • includes (bool, optional) – merge sub-dicts being referenced through #include directives, by default True

  • mode (str, optional) – append to output file (‘a’) or overwrite output file (‘w’), by default ‘w’

  • order (bool, optional) – sort the parsed dict, by default False

  • comments (bool, optional) – writes comments to output file, by default True

  • scope (MutableSequence[str], optional) – scope the dict will be reduced to after parsing, by default None

  • output (str, optional) – format of the output file. Choices are ‘cpp’, ‘foam’, ‘xml’ and ‘json’., by default None

Returns:

the parsed dict

Return type:

Union[CppDict, None]

Raises:

FileNotFoundError – if source_file does not exist