parseExpression method

void parseExpression(
  1. JrlLine line,
  2. String source,
  3. RegExp expPresent
)

Helper method to extract variables from the description. Helper method to extract variables from the valuta field. check if it can be evaluated with expressions: ^0.2.3: Parses expressions within the description or valuta fields. These expressions are stored in expressions and evaluated later.

Implementation

//void _extractVariablesFromDescription(JrlLine line, String desc) {
//  RegExp rex = RegExp(r"#(\w+)");
//  final matches = rex.allMatches(desc);
//  final extractedVariables = matches.map((match) => match.group(1)).toList();

//  // Store extracted variables in line.vars and the operation's `vars`.
//  for (final variable in extractedVariables) {
//    if (!vars.containsKey(variable)) {
//      vars[variable!] = variable;
//    }
//  }
//}

/// Helper method to extract variables from the `valuta` field.
//void _extractVariablesFromValuta(JrlLine line, String valuta) {
//  RegExp rex = RegExp(r"#(\w+)");
//  rex.allMatches(valuta).forEach((match) {
//    vars[match.group(1)!] = match.group(1);
//    line.valname = match.group(1);
//  });
//  line.valuta = -1; // Force invalid value until evaluation
//}
///check if it can be evaluated with expressions: ^0.2.3:
///Parses expressions within the description or valuta fields.
/// These expressions are stored in `expressions` and evaluated later.
void parseExpression(JrlLine line, String source, RegExp expPresent) {
  //we need to extract the variables
  RegExp rex = RegExp(r"(\(.*\))");
  rex.allMatches(source).forEach((match) {
    String testExp = match.group(1).toString();
    testExp = testExp.replaceAll("#", "");
    try {
      Expression expression = Expression.parse(testExp);
      expressions[match.group(1)!] = expression;
      //print("adding expression ${match.group(1)} with $expression");
      //line.valexp =expression ?? new Expression();//force invalid value
      line.valexp = expression; //force invalid value
    } catch (e) {
      print("error parsing expression '$testExp'");
    }
  });
}