instruction module

Define a master class for Element and Command.

Todo

The line is edited to remove personalized name, weight and always have the same arguments at the same position. But after I shall re-add them with reinsert_optional_commands_in_line. This is very patchy and un-Pythonic.

class Instruction(line, dat_idx=None, **kwargs)[source]

Bases: ABC

An object corresponding to a line in a DAT file.

Parameters:
n_attributes: int | range | Collection
is_implemented: bool
__init__(line, dat_idx=None, **kwargs)[source]

Instantiate corresponding line and line number in DAT file.

Parameters:
  • line (DatLine) – Line containing the instructions.

  • dat_idx (int | None, default: None) – Position in the DAT. Note that this index will vary if some instructions (empty lines, comments in particular) are removed from the dat content.

Return type:

None

line: DatLine
idx: dict[str, int]
_assert_correct_number_of_args(idx)[source]

Check if given number of arguments is ok.

Parameters:

idx (int)

Return type:

None

__str__()[source]

Give name of current command.

Used by LW to identify elements.

Return type:

str

property name: str

Give personalized name of instruction if exists, default otherwise.

to_line(*args, **kwargs)[source]

Convert the object back into a DAT line.

Return type:

list[str]

increment_dat_position(increment=1)[source]

Increment dat index for when another instruction is inserted.

Parameters:

increment (int, default: 1)

Return type:

None

insert_dat_line(*args, dat_filecontent, previously_inserted=0, **kwargs)[source]

Insert the current object in the dat_filecontent object.

Parameters:
  • dat_filecontent (list[DatLine]) – The list of instructions, in the form of a list of lines.

  • previously_inserted (int, default: 0) – Number of Instruction that were already inserted in the given dat_filecontent.

Return type:

None

insert_line(*args, dat_filecontent, previously_inserted=0, **kwargs)[source]

Insert the current object in the dat_filecontent object.

Parameters:
  • dat_filecontent (list[Collection[str]]) – The list of instructions, in the form of a list of lines.

  • previously_inserted (int, default: 0) – Number of Instruction that were already inserted in the given dat_filecontent.

Return type:

None

insert_object(instructions)[source]

Insert current instruction in a list full of other instructions.

Parameters:

instructions (MutableSequence[Self])

Return type:

None

classmethod from_args(dat_idx, *args, **kwargs)[source]

Instantiate instruction from its arguments directly.

Parameters:

dat_idx (int)

Return type:

Self

classmethod _args_to_line(*args, **kwargs)[source]

Create the line of the dat file from arguments of the command.

Return type:

str

_abc_impl = <_abc._abc_data object at 0x7318faa95640>
class Dummy(line, warning=False, **kwargs)[source]

Bases: Instruction

An object corresponding to a non-implemented element or command.

Parameters:
is_implemented: bool = False
__init__(line, warning=False, **kwargs)[source]

Create the dummy object, raise a warning if necessary.

Parameters:
  • line (DatLine) – Arguments of the line in the DAT file.

  • dat_idx – Line number in the DAT file.

  • warning (bool, default: False) – To raise a warning when the element is not implemented. The default is False.

Return type:

None

_abc_impl = <_abc._abc_data object at 0x7318fb975700>
class Comment(line, dat_idx=None, **kwargs)[source]

Bases: Dummy

An object corresponding to a comment.

Parameters:
__init__(line, dat_idx=None, **kwargs)[source]

Create the object, but never raise a warning.

Parameters:
  • line (DatLine) – Arguments of the line in the DAT file.

  • dat_idx (int | None, default: None) – Line number in the DAT file.

Return type:

None

_abc_impl = <_abc._abc_data object at 0x7318fb6ae580>
class LineJump(line, dat_idx=None, **kwargs)[source]

Bases: Comment

An object corresponding to an empty line.

Basically a comment.

Parameters:
_abc_impl = <_abc._abc_data object at 0x7318fb6ae5c0>