parseExpression2 method
Implementation
void parseExpression2(JrlLine line, String source) {
RegExp varExp = RegExp(r"#(\w+)"); // Matches variables
RegExp expressionExp =
RegExp(r"\(([^)]+)\)"); // Matches expressions inside parentheses
Map<String, dynamic> locvars = {};
/// Map of variables used in the operation for templating and expressions.
Map<String, dynamic> locexpressions = {};
/// Map of expressions tied to the operation for dynamic evaluation.
// Parse variables first
varExp.allMatches(source).forEach((match) {
String variable = match.group(1)!;
if (!locvars.containsKey(variable)) {
locvars[variable] = variable;
}
});
// Parse expressions
expressionExp.allMatches(source).forEach((match) {
String expressionStr = match.group(1)!;
try {
Expression expression = Expression.parse(expressionStr);
locexpressions[match.group(1)!] = expression;
//line.valexp = expression;//TODO activat ewhen validated
} catch (e) {
print("Error parsing expression: $expressionStr");
}
});
print("ilocal variables $locvars and expressions $locexpressions");
}