getPotentialDefinable static method
Detect potential variable and function names
This method analyzes the given string and assumes if there are any variable and function names. This method doesn't give you a 100% guarantee if you use implicit multiplication, since there's no way to be sure if an unprocessed substring is a whole name or multiple variables being multiplied, or if that's a function getting multiplied with parentheses. Because of that, this method assumes you don't use implicit multiplication.
Returns a list of strings of potential undeclared variable names.
Use hideBuiltIns
if you want to remove built-in variables like e
and
pi
from result. Can be useful if you are going to prompt user to enter the
values.
Implementation
static _MathExpressionDefinable getPotentialDefinable(
/// The expression to convert
String expression, {
/// Hide built-in variables like `e` and `pi`
bool hideBuiltIns = false,
}) {
final funcs = getPotentialFunctionNames(expression, hideBuiltIns: false);
final vars = RegExp(_variableNameBaseRegExp)
.allMatches(expression)
.map((element) => element.group(0)!)
.where((element) {
return !(_bracketFuncs.contains(element)) &&
!(hideBuiltIns && _variableBuiltIns.contains(element)) &&
!funcs.contains(element);
}).toSet();
return _MathExpressionDefinable(vars, funcs);
}