knit_script.knit_script_interpreter.expressions.not_expression module

Expressions for interpreting conditions using Python conventions.

This module provides the Not_Expression class, which implements logical negation operations in knit script programs. It follows Python’s truthiness conventions for evaluating and negating expressions.

class Not_Expression(parser_node, negated_expression)[source]

Bases: Expression

Expression with a “not” operator negating them.

The Not_Expression class implements logical negation operations following Python’s conventions for truthiness evaluation. It takes any expression and returns the logical negation of its evaluated result, converting the result to a boolean using Python’s standard truthiness rules.

This expression type is essential for conditional logic in knit script programs,

allowing developers to negate boolean conditions, check for empty collections, None values, and other false conditions.

_negated_expression

The expression to logically negate.

Type:

Expression

Parameters:
  • parser_node (LRStackNode)

  • negated_expression (Expression)

__init__(parser_node, negated_expression)[source]

Initialize the Not_Expression.

Parameters:
  • parser_node (LRStackNode) – The parser node from the parse tree.

  • negated_expression (Expression) – The expression to apply logical negation to.

evaluate(context)[source]

Evaluate the expression to get the logical negation result.

Evaluates the contained expression and returns its logical negation, following Python’s truthiness conventions where empty collections, None, zero values, and False are considered false.

Parameters:

context (Knit_Script_Context) – The current context of the knit_script_interpreter.

Returns:

The logical negation of the evaluated expression result.

Return type:

bool

property line_number: int

Get the line number of the symbol that generated this statement.

Returns:

The line number where this element appears in the source file.

Return type:

int

property location: Location

Get the location of this symbol in KnitScript file.

Returns:

The location of this symbol in the source file, including file name, line number, and position information.

Return type:

Location