qmi.utils.adbasic_parser

Parse an ADbasic program.

This module provides functions to parse an ADbasic program and its include files, extracting information from the symbol definitions in the program.

This module can also be executed with a toplevel ADbasic filename as an argument, to get an overview of the defined symbols.

Functions

analyze_parameter_info(symbols)

Analyze a set of ADbasic symbol definitions to extract parameter information.

parse_adbasic_program(filename, include_dir)

Parse an ADbasic program (and, recursively, its include files) to find #Define lines.

print_parameter_info(param_info)

Print the result of analyze_adbasic_symbols().

print_symbol_info(symbols)

Print the result of parse_adbasic_program().

run()

Classes

ArrayElemDesc(data_index, elem_index)

Represents an element inside a global Data_nnn array.

FParDesc(fpar_index)

Represents a global FPar_nn variable.

ParDesc(par_index)

Represents a global Par_nn variable.

ParameterInfo(param, data)

Represents the collection of externally accessible parameters of an ADbasic program.

SymbolInfo(filename, line_nr, label, value)

Symbol defined in the ADbasic program source.

Exceptions

ParseException(filename, line_nr, message)

Raised when parsing fails.

class qmi.utils.adbasic_parser.SymbolInfo(filename: str, line_nr: int, label: str, value: str)

Symbol defined in the ADbasic program source.

filename: str

Alias for field number 0

line_nr: int

Alias for field number 1

label: str

Alias for field number 2

value: str

Alias for field number 3

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

class qmi.utils.adbasic_parser.ParDesc(par_index: int)

Represents a global Par_nn variable.

par_index: int

Alias for field number 0

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

class qmi.utils.adbasic_parser.FParDesc(fpar_index: int)

Represents a global FPar_nn variable.

fpar_index: int

Alias for field number 0

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

class qmi.utils.adbasic_parser.ArrayElemDesc(data_index: int, elem_index: int)

Represents an element inside a global Data_nnn array.

data_index: int

Alias for field number 0

elem_index: int

Alias for field number 1

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

class qmi.utils.adbasic_parser.ParameterInfo(param: dict[str, ParDesc | FParDesc | ArrayElemDesc], data: dict[str, int])

Represents the collection of externally accessible parameters of an ADbasic program.

param

Mapping from parameter name to a ParDesc, FParDesc or ArrayElemDesc instance.

Type:

dict[str, qmi.utils.adbasic_parser.ParDesc | qmi.utils.adbasic_parser.FParDesc | qmi.utils.adbasic_parser.ArrayElemDesc]

data

Mapping from data name to the index of the global Data_nnn array.

Type:

dict[str, int]

param: dict[str, ParDesc | FParDesc | ArrayElemDesc]

Alias for field number 0

data: dict[str, int]

Alias for field number 1

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

exception qmi.utils.adbasic_parser.ParseException(filename: str, line_nr: int, message: str)

Raised when parsing fails.

add_note()

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

with_traceback()

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

qmi.utils.adbasic_parser.parse_adbasic_program(filename: str, include_dir: str) list[SymbolInfo]

Parse an ADbasic program (and, recursively, its include files) to find #Define lines.

Parameters:
  • filename – File name of ADBasic source to parse.

  • include_dir – Base directory for resolving relative include paths. May be empty to use the current working directory.

Returns:

List of SymbolInfo objects to describe defined symbols.

Return type:

all_defined_symbols

qmi.utils.adbasic_parser.analyze_parameter_info(symbols: list[SymbolInfo]) ParameterInfo

Analyze a set of ADbasic symbol definitions to extract parameter information.

Only the following types of symbol definitions are processed:
  • #Define PAR_parname Par_nn (binds parname to global Par variable).

  • #Define PAR_parname FPar_nn (binds parname to global FPar variable).

  • #Define DATA_arrayname Data_nnn (binds arrayname to global Data array).

  • #Define PAR_parname DATA_arrayname[ii] (binds parname to a specific element in a global data array).

Parameters:

symbols – List of symbol definitions (as produced by parse_adbasic_program).

Returns:

Instance containing a description of all named parameters and named arrays.

Return type:

ParameterInfo

qmi.utils.adbasic_parser.print_symbol_info(symbols: list[SymbolInfo]) None

Print the result of parse_adbasic_program().

qmi.utils.adbasic_parser.print_parameter_info(param_info: ParameterInfo) None

Print the result of analyze_adbasic_symbols().