soleil.overrides.parser#

Functions

extract_string_expression(source, expr)

parse_overrides(overrides)

Takes code containing one or more assignment such as 'a.b[0].x = a.c + 3' and returns a list of Overrides

parse_ref(ref)

Takes a reference such as 'a.b[0].x and parses it into a sequence of attribute or item references.

Classes

Override(target, assign_type, value_expr[, ...])

Contains a parsed override and components.

OverrideSplitter()

Splits python code containing one or more assignments into overrides, enforcing override syntax restrictions

OverrideType(value)

An enumeration.

RefExtractor(*args, **kwargs)

Parses a reference string, raising an error on invalid strings.

ValueVerifier()

Checks that a specified value expression is valid

class soleil.overrides.parser.OverrideType(value)#

Bases: Enum

An enumeration.

existing = 0#

Override an existing value

class soleil.overrides.parser.Override(target: VarPath, assign_type: OverrideType, value_expr: Expression, source: str | None = None, used: int = 0)#

Bases: object

Contains a parsed override and components.

source: str | None = None#

The source code corresponding to this override, if available

used: int = 0#

The number of times the override has been used – can be used multiple times when overrides are shared by a spawned parent class and its child class

get_value(_globals=None, _locals=None)#

Extracts the assignment value from the specified globals and locals.

class soleil.overrides.parser.RefExtractor(*args, **kwargs)#

Bases: _RestrictedNodeVisitor

Parses a reference string, raising an error on invalid strings.

Builds a list of references.

default_nodes: Tuple[Type[AST], ...] = (<class '_ast.Expr'>, <class '_ast.Module'>, <class '_ast.Index'>, <class '_ast.Load'>, <class '_ast.Store'>)#

Will call ast.NodeVisitor.generic_visit on these nodes

specialized_nodes: Tuple[Type[AST], ...] = (<class '_ast.Attribute'>, <class '_ast.Subscript'>, <class '_ast.Constant'>, <class '_ast.Name'>)#

A specialized method is implemented for these nodes

class soleil.overrides.parser.ValueVerifier#

Bases: _RestrictedNodeVisitor

Checks that a specified value expression is valid

default_nodes: Tuple[Type[AST], ...] = (<class '_ast.Constant'>, <class '_ast.Name'>, <class '_ast.Attribute'>, <class '_ast.Subscript'>, <class '_ast.BinOp'>, <class '_ast.operator'>, <class '_ast.Tuple'>, <class '_ast.List'>, <class '_ast.Load'>, <class '_ast.UnaryOp'>, <class '_ast.USub'>)#

Will call ast.NodeVisitor.generic_visit on these nodes

specialized_nodes: Tuple[Type[AST], ...] = ()#

A specialized method is implemented for these nodes

class soleil.overrides.parser.OverrideSplitter#

Bases: _RestrictedNodeVisitor

Splits python code containing one or more assignments into overrides, enforcing override syntax restrictions

specialized_nodes: Tuple[Type[AST], ...] = (<class '_ast.Assign'>,)#

A specialized method is implemented for these nodes

soleil.overrides.parser.parse_ref(ref: str)#

Takes a reference such as 'a.b[0].x and parses it into a sequence of attribute or item references.

soleil.overrides.parser.parse_overrides(overrides: str) List[Override]#

Takes code containing one or more assignment such as 'a.b[0].x = a.c + 3' and returns a list of Overrides