CLParse

class bapsflib._hdf.maps.controls.parsers.CLParse(command_list: str | Iterable[str])

Bases: object

Class for parsing RE from a command list. (A command list is a list of strings where each string is a set of commands sent to a control device to define that control device’s state.)

Parameters:

command_list (Union[str, Iterable[str]]) – the command list for a control device

Methods Summary

apply_patterns(patterns)

Applies the regular expressions defined in patterns to parse the command list.

try_patterns(patterns)

Prints to the results of applying the REs in patterns to the command list.

Methods Documentation

apply_patterns(patterns: str | Iterable[str])

Applies the regular expressions defined in patterns to parse the command list.

Parameters:

patterns (Union[str, Iterable[str]]) – list of raw strings defining regular expressions for parsing the command list

Returns:

  • boolTrue if the command list is parsed successfully, False otherwise.

  • dict – results from the command list parsing

Examples

>>> # define a command list
>>> cl = ["VOLT 20.0", "VOLT 25.0", "VOLT 30.0"]
>>>
>>> # define clparse object
>>> clparse = CLParse(cl)
>>>
>>> # apply patterns
>>> patterns = (
>>>     r"(?P<FREQ>(\bFREQ\s)"
>>>     r"(?P<VAL>(\d+\.\d*|\.\d+|\d+\b)))"
>>> )
>>> results = clparse.apply_patterns(patterns)
>>> results[0]
True
>>> results[1]
{'VOLT': {'cl str': ('VOLT 20.0', 'VOLT 25.0', 'VOLT 30.0'),
          'command list': (20.0, 25.0, 30.0),
          're pattern': re.compile(pattern, re.UNICODE),
          'dtype': numpy.float64}}
try_patterns(patterns: str | Iterable[str])

Prints to the results of applying the REs in patterns to the command list. Pretty print of apply_patterns().

Parameters:

patterns (Union[str, Iterable[str]]) – list of raw strings defining regular expressions for parsing the command list