parseString method
Parses string
(a mathematical formula) and returns the FormulaAst
.
If variables
are provided, their names can be used in the formula.
The variables are other, formerly parsed FormulaAst
s. They should
be provided in definition order, so that later definitions of a formula
with the same name will override earlier ones.
If the formula should be its own variable, provide its name
.
Implementation
FormulaAst parseString(String string,
{List<FormulaAst> variables = const [], String? name}) {
if (name != null) {
if (name.isEmpty) {
throw ArgumentError('Name of variable cannot be empty');
}
if (name.contains(' ')) {
throw ArgumentError('Name of variable cannot have spaces in it: $name');
}
}
final result = formulaParser.parse(string);
return FormulaAst(
result.isFailure ? null : result.value,
result.isFailure,
result.isFailure ? result.message : null,
result.buffer,
result.position,
name: name);
}