Basic classes#

This section contains the description of classes that are commonly used by other classes.

SwanItem class#

The SwanItem is the top-level class for all constructs.

class ansys.scadeone.core.swan.SwanItem#

Base class for Scade objects.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

HasPragma class#

The HasPragma is the top-level class for all constructs which have pragmas. It is a subclass of SwanItem.

class ansys.scadeone.core.swan.HasPragma(pragmas: List[Pragma] | None = None)#

Bases: SwanItem

Base class for objects with pragmas.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

Identifier classes#

Swan identifiers are represented by the following classes with a simple identifier or a path identifier, which is a list of identifiers separated by ‘::’.

A luid (Luid) is used to name instances of operators, automata, or activate.

A lunum (Lunum) is used to reference a block in a Diagram.

class ansys.scadeone.core.swan.Identifier(value: str, comment: str = '', is_name: bool = False)#

Bases: SwanItem

Class for identifier.

An Identifier can be invalid if it was protected while saving it for some reason. In that case, the property _is_valid_ is set to True.

Parameters:
valuestr

Identifier string.

commentstr, optional

Comment, can be multiline, by default None.

is_namebool, optional

True when Identifier is a name, aka. ‘Identifier.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property comment: str#

Comment part string.

property is_name: bool#

Return true when Identifier is a name.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

There is no specific derived class for protected Identifier, hence it is handled at by the Identifier class itself:

  • with the is_valid property: when false, the Identifier should be protected.

  • with the is_protected property: when true, the Identifier should be protected.

The two properties are complementary.

The __str__ method returns the Identifier value, with a protection markup when needed.

property is_valid: bool#

Return true when Identifier is valid.

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property value: str#

Identifier as a string.

class ansys.scadeone.core.swan.PathIdentifier(path_id: List[Identifier] | str)#

Bases: SwanItem

Class for path identifiers, i.e: P1::Id.

The class manipulates the PathIdentifier as separate items.

If the original path was protected (given as a string), the property is_valid is False, and the path is considered to be a single string and is_protected is True.

path_id argument is:

  • a list of identifiers, for a valid path.

  • a string if the path was protected.

static from_string(path: str) PathIdentifier#

Create a PathIdentifier from a string.

Parameters:
pathstr

String containing the path identifier.

Returns:
PathIdentifier

PathIdentifier instance.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

classmethod is_valid_file_path(path: str) bool#

Check if path is a valid file path identifier, i.e. id {- id}, with no possible spaces around ‘-‘.

The path string is the basename of a module or an instance file.

Parameters:
pathstr

String containing the path identifier.

Returns:
bool

True when path is valid.

classmethod is_valid_path(path: str) bool#

Check if path is a valid path identifier, i.e. id {:: id}, with possible spaces around ‘::’.

Parameters:
pathstr

String containing the path identifier.

Returns:
bool

True when path is valid.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

static split(path: str) Tuple[str, str]#

Split a path into path::name.

Parameters:
pathstr

Path string.

Returns:
Tuple[str, str]

path, name.

property as_string: str#

Compute name by joining name parts with ‘::’.

property is_protected: bool#

True when path is from a protected source, i.e., a string.

property is_valid: bool#

True when path is a sequence of Identifier.

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property path_id: List[Identifier] | str#

PathId as a list of Identifier, or a string if protected.

class ansys.scadeone.core.swan.Luid(value: str)#

Bases: SwanItem

Class for LUID support. The ‘$’ prefix is not saved (potentially removed at creation).

as_luid() str#

Luid value with ‘$’ prefix. Equivalent to str(luid).

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static is_valid(luid: str) bool#

True when a luid is a valid LUID.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property value: str#

Luid value.

class ansys.scadeone.core.swan.Lunum(value: str)#

Bases: SwanItem

Class for LUNUM support: ‘#’ is part of the LUNUM.

get_full_path() str#

Full path of the Swan construct.

This method is implemented by derived classes that correspond to a declaration at the module level (such as sensor, type, group, const, operator), or a module itself.

Returns:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

If the method is not implemented for the current SwanItem type.

static is_valid(lunum: str) bool#

True when a lunum is a valid LUNUM.

static set_owner(owner: SwanItem | IModel | None, children: SwanItem | Iterable[SwanItem] | None) None#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem], None]

Items to set owner.

property is_protected: bool#

Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).

property model: IModel#

Return model containing the Swan item.

property module: ModuleBase | None#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface or None if the object is itself a module.

property owner: SwanItem | IModel | None#

Owner of current Swan construct.

property value: str#

Luid value as a string.

Miscellaneous#

The following class is a helper for Swan literal expressions.

class ansys.scadeone.core.swan.SwanRE#

Bases: object

Container of compiled regular expressions. These expressions can be matched with some strings. Some regular expressions use groups to extract parts.

Attributes:

TypedInteger: regular expressions for integers with post type (_i, _ui).

Integer part is in the value group, type in the type group, and size in the size group.

TypeFloat: regular expression for floats with post type (_f).

Mantissa is in the mantissa group, exponent in the exp group, type in the type group, and size in the size group.

classmethod is_bool(string: str) bool#

Check whether a string is a Swan boolean value.

Parameters:
stringstr

String to check.

Returns:
bool

True if string is a Swan char value

classmethod is_char(string: str) bool#

Check whether a string is a Swan char value.

Parameters:
stringstr

String to check.

Returns:
bool

True if string is a Swan char value.

classmethod is_float(string: str) bool#

Check whether a string is a Swan integer.

Parameters:
stringstr

Integer value, as decimal, bin, octal, or hexadecimal, with or without type information.

Returns:
bool

True when string is an integer.

classmethod is_integer(string: str) bool#

Check whether a string is a Swan integer.

Parameters:
stringstr

Integer value, as decimal, bin, octal, or hexadecimal, with or without type information.

Returns:
bool

True when string is an integer.

classmethod is_numeric(string: str) bool#

Check whether a string is a Swan numeric value, that is, an integer of float value.

Parameters:
stringstr

String to check.

Returns:
bool

True if string is a Swan numeric value.

classmethod parse_float(string: str, minus: bool = False) FloatTuple | None#

Match a string representing a float and return a description of that float as a FloatTuple.

Parameters:
stringstr

String representing a float, with or without type information.

minusbool

True when the value is preceded with a ‘-’ minus operator.

Returns:
FloatTuple or None

If the string value matches SwanRE.TypedFloat pattern, a FloatTuple is returned. It is a namedtuple with fields:

  • value: computed value

  • mantissa: the mantissa part

  • exp: the exponent part

  • size: the size part

Note: if there is no type information, type is _f32.

classmethod parse_integer(string: str, minus: bool = False) IntegerTuple | None#

Matches a string representing an integer and returns a description of that integer as an IntegerTuple.

Parameters:
stringstr

String representing an integer, with or without type information.

minusbool

True when the value is preceded with a ‘-’ minus operator.

Returns:
IntegerTuple or None

If the string value matches SwanRE.TypedInteger pattern, an IntegerTuple is returned. It is a namedtuple with fields:

  • value: computed value

  • is_bin, is_oct, is_hex, is_dec: flags set according to found type

  • is_signed: True when integer is signed

  • size: the size part

Note: if there is no type information, type is _i32.