raesl.compile.ast.exprs#

Expressions to store and reason about values and boundaries.

Module Contents#

Classes#

DataValue

Some kind of data value. Do not use this, but use a derived class instead.

Value

A value with an optional unit. Don't modify these objects in-place, create a new

VariableValue

Class representing a variable or parameter as value.

Expression

Base class of an expression.

Comparison

Class storing a comparison.

RelationComparison

A relation between a variable and either a value or a variable.

ObjectiveComparison

An intended direction for a variable. Note that the 'maximize' parameter

Disjunction

Disjunctive expression (also known as 'or' expression).

Attributes#

_MATH_OP_TRANSLATE

class raesl.compile.ast.exprs.DataValue#

Some kind of data value. Do not use this, but use a derived class instead.

abstract get_units() Set[str] | None#

Obtain the units of the value. Gives a set of names without square brackets where lack of units results in the empty set, and not supporting units gives None.

Returns:

Names of the available units without square brackets or None.

class raesl.compile.ast.exprs.Value(value: raesl.compile.scanner.Token, unit: raesl.compile.scanner.Token | None = None)#

Bases: DataValue

A value with an optional unit. Don’t modify these objects in-place, create a new object instead.

Parameters:
  • value – Stored value as text.

  • unit – Either None or text describing the unit. Treat as read-only, as changing it may break the cache.

_unit_cache#

Units of the literal after normalizing self.unit. Computed on demand.

get_units() Set[str] | None#

Obtain the units of the value. Gives a set of names without square brackets where lack of units results in the empty set, and not supporting units gives None.

Returns:

Names of the available units without square brackets or None.

__eq__(other)#

Return self==value.

__repr__()#

Return repr(self).

class raesl.compile.ast.exprs.VariableValue(var_tok: raesl.compile.scanner.Token)#

Bases: DataValue

Class representing a variable or parameter as value.

Parameters:
  • var_tok – Token stating the possibly dotted name of the variable.

  • var_node – If not None, the node represented by the object. Set during type checking.

get_units() Set[str] | None#

Obtain the units of the value. Gives a set of names without square brackets where lack of units results in the empty set, and not supporting units gives None.

Returns:

Names of the available units without square brackets or None.

class raesl.compile.ast.exprs.Expression#

Base class of an expression.

class raesl.compile.ast.exprs.Comparison(is_constraint: bool)#

Bases: Expression

Class storing a comparison.

Parameters:

is_constraint – Whether the comparison is considered to be a constraint rather than a requirement.

raesl.compile.ast.exprs._MATH_OP_TRANSLATE#
class raesl.compile.ast.exprs.RelationComparison(is_constraint: bool, lhs_var: VariableValue, isaux_tok: raesl.compile.scanner.Token, cmp_tok: raesl.compile.scanner.Token, rhs_varval: DataValue)#

Bases: Comparison

A relation between a variable and either a value or a variable.

Parameters:
  • is_constraint – Whether the comparison is considered to be a constraint rather than a requirement.

  • lhs_var – Left hand side variable being compared.

  • isaux_tok – ‘is’ for a constraint, else the aux word for expressing strength of the comparison.

  • cmp_tok – One of the key words that expression the comparison to perform.

  • math_compare – Translated ‘cmp_tok’, with the ascii math text.

  • rhs_varval – Right hand side variable or value.

get_location() raesl.types.Location#

Return a location to point at the comparison for error reporting purposes.

class raesl.compile.ast.exprs.ObjectiveComparison(lhs_var: VariableValue, aux_tok: raesl.compile.scanner.Token, maximize: bool)#

Bases: Comparison

An intended direction for a variable. Note that the ‘maximize’ parameter controls both the ‘maximize’ and ‘minimize’ desires.

Parameters:
  • lhs_var – Variable with the objective.

  • aux_tok – One of the auxiliary verbs expressing strength of the objective.

  • maximize – If set the comparison expresses the desire to maximize the variable.

minimize#

Opposite of maximize.

property minimize: bool#
get_location() raesl.types.Location#

Return a location to point at the comparison for error reporting purposes.

class raesl.compile.ast.exprs.Disjunction(childs: Sequence[Expression])#

Bases: Expression

Disjunctive expression (also known as ‘or’ expression). It is true iff at least one of it child expressions is true.

Parameters:

childs – Child expressions of the disjunction. It is recommended to have at least two children in an object.