Pragma#

From a lexical point of view, pragmas are of the form #pragma...#end where ... is any text, with ## to denotes # to avoid confusion with an enclosed #end. Practical pragmas are of the form #pragma pragma_name <some content> #end where some content is any character string, including spaces and newlines.

A Pragma object stores a pragma information as a key for the pragma name and a value for the pragma content (value can be empty). The Pragma class is the base class for all pragmas, including diagram pragmas and other pragmas. It is also used to represent pragmas that are not (yet) known to the library.

../../../_images/pragma.svg

Fig. 18 Pragma class diagram#

class ansys.scadeone.core.swan.Pragma(key: PragmaKey | str, data: str | None = None)#

Bases: SwanItem

Pragma structure.

static filter(pragmas: List[Pragma], key: str, with_key: bool = True) List[Pragma]#

Filters a list of pragmas with/without a given key.

Parameters:
pragmasList[Pragma]

List of pragmas.

keystr

Key to filter.

with_keybool, optional

If True, return pragmas with the given key, otherwise without the key, by default True.

Returns:
List[Pragma]

List of pragmas with the given key.

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 data: str | None#

Return the pragma data.

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 key: PragmaKey | str#

Return the pragma key.

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.