use of org.matheclipse.api.parser.FuzzyParser in project symja_android_library by axkr.
the class Pods method parseInput.
/**
* package private
*/
static IExpr parseInput(String inputStr, EvalEngine engine) {
engine.setPackageMode(false);
IExpr inExpr = F.NIL;
// }
if (!inExpr.isPresent()) {
final FuzzyParser parser = new FuzzyParser(engine);
try {
inExpr = parser.parseFuzzyList(inputStr);
} catch (SyntaxError serr) {
// this includes syntax errors
LOGGER.debug("Pods: FuzzyParser.parseFuzzyList() failed", serr);
TeXParser texConverter = new TeXParser(engine);
inExpr = texConverter.toExpression(inputStr);
}
}
if (inExpr == S.$Aborted) {
return F.NIL;
}
if (inExpr.isList() && inExpr.size() == 2) {
inExpr = inExpr.first();
}
if (inExpr.isTimes() && !inExpr.isNumericFunction(true) && inExpr.argSize() <= 4) {
if (((IAST) inExpr).isEvalFlagOn(IAST.TIMES_PARSED_IMPLICIT)) {
inExpr = flattenTimes((IAST) inExpr).orElse(inExpr);
IAST rest = ((IAST) inExpr).setAtClone(0, S.List);
IASTAppendable specialFunction = F.NIL;
String stemForm = getStemForm(rest.arg1().toString().toLowerCase());
IExpr head = rest.head();
if (stemForm != null) {
head = STEM.getSymbol(stemForm);
if (head != null) {
specialFunction = rest.setAtClone(0, head);
specialFunction.remove(1);
}
}
if (!specialFunction.isPresent()) {
stemForm = getStemForm(rest.last().toString().toLowerCase());
if (stemForm != null) {
head = STEM.getSymbol(stemForm);
if (head != null) {
specialFunction = rest.setAtClone(0, head);
specialFunction.remove(rest.size() - 1);
}
}
}
if (specialFunction.isPresent()) {
if (head != null) {
if (head == S.UnitConvert) {
IExpr temp = unitConvert(engine, rest.rest());
if (temp.isPresent()) {
return temp;
}
} else {
int i = 1;
while (i < specialFunction.size()) {
String argStr = specialFunction.get(i).toString().toLowerCase();
if (argStr.equalsIgnoreCase("by") || argStr.equalsIgnoreCase("for")) {
specialFunction.remove(i);
continue;
}
i++;
}
return specialFunction;
}
}
}
if (rest.arg1().toString().equalsIgnoreCase("convert")) {
rest = inExpr.rest();
}
if (rest.argSize() > 2) {
rest = rest.removeIf(x -> x.toString().equals("in"));
}
IExpr temp = unitConvert(engine, rest);
if (temp.isPresent()) {
return temp;
}
}
}
return inExpr;
}
Aggregations