Protected items#
Swan code in a model may be syntactically incorrect but must still be
saved and read without errors by the parser. Such invalid code
is protected using markups. Invalid syntax is protected as {syntax%invalid code %syntax}
and corresponds to a specific token of the Swan grammar used by the tools [1].
Additionally, other markups are used by the serialization mechanism of the editor [2].
Such pieces of code are represented by a ProtectedItem
(or a derived class) instance, which stores the code text and the associated markup.
Protection class#
- class ansys.scadeone.core.swan.ProtectedItem(data: str, markup: str = 'syntax')#
Bases:
SwanItemBase class for protected data. A protected data is a piece of Swan code enclosed between markups, mostly to store syntactically incorrect code. A protected data is enclosed within the pair
{markup%..%markup}, where markup is defined by the regular expression: [‘a’-‘z’ ‘A’-‘Z’ 0-9 _]*.See
Markupfor existing markups.- 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:
strPath within the owner and name of the Swan construct.
- Raises:
ScadeOneExceptionIf 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.
- property model: IModel#
Return model containing the Swan item.
- property module: ModuleBase | None#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBodyandModuleInterfaceor None if the object is itself a module.
List of protected items#
The following table lists the classes derived from ProtectedItem, which protect
invalid textual parts entered in the Scade One editor. The Sibling class column indicates
the base class of the protected item. Even though the item is invalid, it is part of a Swan construct.
Class |
Description |
Other base |
|---|---|---|
Sibling class. |
None |
|
Protected declaration (constant, type, sensor, group, use directive). |
||
Protected expression. |
||
Protected group renaming. |
||
Protected operator expression within an instance block. |
||
Protected pattern in activate. |
||
Protected section (ex: invalid let equation block). |
||
|
Protected type expression. |
|
Protected variable declaration (in var section, inputs or outputs). |
||
Protected forward return. |
Markup helper#
- class ansys.scadeone.core.swan.Markup#
Bases:
objectClass defining the markups used by the Swan serialization.
- static to_str(text: str, is_protected: bool = True, markup: str | None = None) str#
Return text as the protected string
{markup%text%markup}if required.
- Const = 'const'#
Incorrect const declaration.
- Dim = 'dim'#
Incorrect forward dimension.
- Empty = 'empty'#
Empty instance block body. This is an invalid construct, but it is needed for the editor.
- Group = 'group'#
Incorrect group declaration.
- Luid = 'luid'#
Protected instance id.
- OpExpr = 'op_expr'#
Operator expression. Specific markup for the editor. The content is re-parsed by the API.
- Sensor = 'sensor'#
Incorrect sensor declaration.
- Signature = 'signature'#
Incorrect operator declaration in interface. Actually, “signature” is used.
- Syntax = 'syntax'#
General syntax error.
- SyntaxText = 'syntax_text'#
Textual operator with syntax error.
- Text = 'text'#
Textual operator or generic operator content. The content is re-parsed by the API.
- Type = 'type'#
Incorrect type declaration.
- Use = 'use'#
Incorrect use declaration.
- Var = 'var'#
Incorrect variable declaration.
Footnotes