* the user's query converted into ConsCell format
* @return the query with the relevant input filters applied
* @throws ParserException
*/
public ConsCell preProcess(ConsCell input) throws ParserException {
ConsCell current = input;
if (current.length() == 0 || (current.length() == 1 && current.getCarType() == ConsType.EMPTY))
return current;
do {
if (current.getCarType() == ConsType.CONS_CELL)
current.replaceCar(preProcess((ConsCell) current.getCar()));
if (current.getCarType() == ConsType.OBJECT && ((String) current.getCar()).startsWith("{[")) {
currentEqn.matrices.add(new Matrix((String) current.getCar()));
current.replaceCar(new ConsCell("{M" + (currentEqn.matrices.size() - 1) + "}", ConsType.OBJECT));
}
} while (!((current = current.getNextConsCell()).isNull())); //This steps current forward while checking for nulls
current = input;
for (InputFilterPlugin plugin : preProcessFilters)
current = plugin.preProcess(current).getFirstConsCell();
input = current;
do {
if (current.getCarType() == ConsType.IDENTIFIER && abbreviations.containsKey(current.getCar()))
current.replaceCar(new ConsCell(abbreviations.get(current.getCar()), ConsType.IDENTIFIER));
if (!current.getNextConsCell().isNull() && (current.getCarType() == ConsType.NUMBER || current.getCarType() == ConsType.CONS_CELL ||
current.getCarType() == ConsType.OBJECT || current.getCarType() == ConsType.STRING)) {
ConsCell cdr = current.getNextConsCell();
if (cdr.getCarType() == ConsType.NUMBER || cdr.getCarType() == ConsType.CONS_CELL || cdr.getCarType() == ConsType.OBJECT ||
(cdr.getCarType() == ConsType.IDENTIFIER && !cdr.getCar().equals("="))) //If there is an implied multiplication sign
current.insert(new ConsCell('*', ConsType.OPERATOR));
if (cdr.getCarType() == ConsType.STRING) //String concatenation
current.insert(new ConsCell('+', ConsType.OPERATOR));
}
} while (!(current = current.getNextConsCell()).isNull()); //This steps current forward while checking for nulls
return input; //Returns the first ConsCell in the list because we don't care about which one was last processed, just the whole thing.
}