Syntax Checker

The checking is performed at execution of an operator. So, the user file can mix legacy operators and pure Python instructions.

Warning

Default keywords must be added before checking the syntax.

exception code_aster.Cata.Language.SyntaxChecker.CheckerError(orig, msg, stack)[source]

Bases: Exception

Exception raised during checking the syntax.

Parameters:
  • orig (Exception) – Type of exception (TypeError, KeyError, ValueError).

  • msg (str) – Message of the error.

  • stack (str) – Checking stack: [factor keyword, simple keyword].

_msg

Message of the error.

Type:

str

_orig

Type of exception.

Type:

Exception

_stack

Checking stack as string.

Type:

str

__init__(orig, msg, stack)[source]
property original

Return the original exception.

property msg

Property that holds the main message.

code_aster.Cata.Language.SyntaxChecker.fromTypeName(typename)[source]

Convert a typename to a list of valid Python types (or an empty list) Example: ‘I’ returns [int, …]

code_aster.Cata.Language.SyntaxChecker._gettype(obj)[source]

Return the type of an object

code_aster.Cata.Language.SyntaxChecker.isValidType(obj, expected)[source]

Check that obj has one of the expected type

class code_aster.Cata.Language.SyntaxChecker.SyntaxCheckerVisitor(max_check=99999)[source]

Bases: object

This class walks along the tree of a Command object to check its syntax.

Warning: Default keywords must be added before visiting the objects.

Parameters:

max_check (int) – Limit the number of checked occurrences (default: 99999).

_stack

Stack of checked objects for error report.

Type:

list

_parent_context

Context of the parent used to evaluate block conditions.

Type:

dict

__init__(max_check=99999)[source]

Initialization

error(orig, msg)[source]

Raise a CheckerError exception.

set_parent_context(context)[source]

Set the parent context.

If the checker is directly called on a keyword (without checking the command itself) the values defined upper may be required to evaluate blocks conditions but the parent context has not been filled.

This parent context could be an optional argument in visit* functions.

visitCommand(step, userDict=None)[source]

Visit a Command object

visitMacro(step, userDict=None)[source]

Visit a Macro object

visitBloc(step, userDict=None)[source]

Visit a Bloc object

visitFactorKeyword(step, userDict=None)[source]

Visit a FactorKeyword object

visitSimpleKeyword(step, skwValue)[source]

Visit a SimpleKeyword object

It checks that : - the type is well known, - the values are in into list, - the values are in [val_min, val_max] (using val_min_included and val_max_included), - the number of values is in [min, max].

_visitComposite(step, userDict)[source]

Visit a composite object (containing BLOC, FACT and SIMP objects)

It checks that : - the number of occurences is as expected, - the rules are validated, - the mandatory simple keywords are present.

One walks the Bloc objects to add the keywords according to the conditions.

code_aster.Cata.Language.SyntaxChecker.checkCommandSyntax(command, keywords, add_default=True, max_check=99999)[source]

Check the syntax of a command keywords contains the default keywords and the user keywords filled by the user.

Default keywords must be added before checking the syntax if add_default is set to False.

Parameters:
  • command (Command) – Command object to be checked.

  • keywords (dict) – Dict of keywords. None values are removed from the user dict.

  • add_default (bool, optional) – Tell if default keywords have to be added or not.

  • max_check (int) – Limit the number of checked occurrences (default: 99999).