-
Notifications
You must be signed in to change notification settings - Fork 2
$$ Variables and Patterns
The Parm class implements a pattern-matching system that allows for dynamic variable substitution and evaluation. The system is built around several specialized patterns that use $ and $$ prefixes to indicate different types of variable access and operations.
The class defines four main pattern types:
-
Global Variables (
$VARNAME):- Pattern:
\$[A-Z]{2,}([-+*/%]\d+)? - Examples:
$FOO,$BAR+4,$COUNT-2 - Purpose: Access global variables stored in
GlobalStore, with optional math operations
- Pattern:
-
Loop Number (
$$L):- Pattern:
\$\$L - Purpose: Returns the current loop iteration number (0-indexed)
- Pattern:
-
List Access (
$$Nand$$num):- Pattern:
\$\$(?:N([-+*/%]\d+)?|(\d+)) - Examples:
-
$$N- Access element at current loop index -
$$N+2- Access element at loop index + 2 -
$$N*3- Access element at loop index * 3 -
$$1- Access first element -
$$5- Access fifth element
-
- Purpose: Retrieves items from an input list based on loop number or explicit index
- Pattern:
-
Python Code (
`code`):- Pattern:
`([^`]+)` - Examples:
`len("test")`,`math.sin(0.5)` - Purpose: Evaluates arbitrary Python expressions within a safe execution environment
- Pattern:
-
The system processes expressions in a specific order:
- First: Global variables
- Second: Loop numbers
- Third: List access
- Fourth: Python code evaluation
-
When
eval()is called on a parameter, the system:- Checks if the parameter contains patterns
- For each pattern match, it applies the corresponding transformation
- Returns the fully resolved value
-
List access requires an input node that returns a list
- The system calculates the appropriate index (with overflow protection)
- Returns the corresponding list item as a string
-
The Python code evaluation runs in a sandboxed environment with limited built-ins and modules for security
This pattern system enables powerful template-based string manipulation and data access while maintaining a controlled execution environment.