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: SwanItem

Base 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 Markup for 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:
str

Path within the owner and name of the Swan construct.

Raises:
ScadeOneException

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

has_markup(markup: str) bool#

Check if protected data has the specified markup.

Parameters:
markupstr

String markup.

Returns:
result: bool

True when instance markup is same as parameter.

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#

Protected data between markups.

Returns:
str

Protected data.

property is_protected: bool#

Tell if item is syntactically protected and provided as a string.

property markup: str#

Protection markup.

Returns:
str

Markup string.

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.

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

ProtectedItem

Sibling class.

None

ProtectedDecl

Protected declaration (constant, type, sensor, group, use directive).

GlobalDeclaration

ProtectedExpr

Protected expression.

Expression

ProtectedGroupRenaming

Protected group renaming.

GroupRenaming

ProtectedOpExpr

Protected operator expression within an instance block.

OperatorExpression

ProtectedPattern

Protected pattern in activate.

Pattern

ProtectedSection

Protected section (ex: invalid let equation block).

ScopeSection

ProtectedTypeExpr

Protected type expression.

TypeExpression

ProtectedVariable

Protected variable declaration (in var section, inputs or outputs).

Variable

ProtectedForwardReturnItem

Protected forward return.

ForwardReturnItem

Markup helper#

class ansys.scadeone.core.swan.Markup#

Bases: object

Class 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.

Parameters:
textstr

Text to protect

is_protectedbool, optional

True when text shall be protected, by default True

markupstr, optional

Markup to use, by default None, resulting in using Markup.Syntax

Returns:
str

Protected string {markup%text%markup} if is_protected is True, else text.

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