Swan constructs#
This section describes the ansys.scadeone.core.swan module which contains all classes available to represent a Swan model.
Some class descriptions use the Extended Backus-Naur form to represent Swan constructs.
Each class defined in this module corresponds to a Swan construct. For instance the ModuleBody class
represents a Swan module body, the ConstDeclarations class represents constant declarations,
and the Diagram class represents a diagram. This pattern continues for all Swan constructs.
The class hierarchy closely mirrors the Swan language and its grammar. Refer to the Help menu in the Swan IDE for a complete description of the Swan language.
Swan objects can be created from a Swan model read from a project or built from scratch using the classes described in the following sections.
Swan objects as strings#
Swan objects can be complex, and pretty-printing them is often desirable. The default __str__() method is not always sufficient to represent a Swan object as a string. To obtain a string representation of a Swan construct, use the ansys.scadeone.core.swan.swan_to_str() method. Example:
from ansys.scadeone.core.swan import swan_to_str
print(swan_to_str(my_construct))
The default __str__() method is implemented for the following classes:
Luid,
Lunum,
Literal,
Identifier,
PathIdentifier,
Pattern derived classes,
Pragma, and pragma related classes (see: Diagram Pragmas), and
ProtectedItem.
Protected object concept#
The Swan editor allows the user to enter syntactically invalid Swan code. Such code is protected to become acceptable tokens for the Swan parser. See Protected items for more details.