@Override public String toString() { return order.toString(); }
private void applyForBestFit( int from, ParseContext ctxt, Object originalResult, int originalStep, int originalAt, TreeNode originalLatestChild) { int bestAt = ctxt.at; int bestStep = ctxt.step; Object bestResult = ctxt.result; TreeNode bestChild = ctxt.getTrace().getLatestChild(); for (int i = from; i < parsers.length; i++) { ctxt.set(originalStep, originalAt, originalResult); ctxt.getTrace().setLatestChild(originalLatestChild); Parser<?> parser = parsers[i]; boolean ok = parser.apply(ctxt); if (!ok) continue; int at2 = ctxt.at; if (order.compare(at2, bestAt)) { bestAt = at2; bestStep = ctxt.step; bestResult = ctxt.result; bestChild = ctxt.getTrace().getLatestChild(); } } ctxt.set(bestStep, bestAt, bestResult); ctxt.getTrace().setLatestChild(bestChild); } }