// tok = CNC static int matchStartUsingWordTree(L tok, Map tree) { S best = null; // best replacement found int bestIndex = 0; // till where to replace while true { if (j > 0) { // no default in root! S def = cast tree.get(""); if (def != null) { best = def; bestIndex = j; //print("best solution: " + sfu(bestSolution)); } } if (j >= l(tok)) break; O t = tree.get(tok.get(j)); if (translateUsingWordTreeC_debug) print(i + "-" + j + " / " + joinWithSpace(subList(tok, i, j+1)) + " => " + sfu(t)); if (t == null) break; if (t instanceof S) { int k = j+1; if (translateUsingWordTreeC_printReplacements) print("translateUsingWordTreeC: replacing " + sfu(subList(tok, i, k-1) + " with " + quote(t)); replaceTokens(tok, i, k, (S) t); ret k; } tree = (Map) t; j++; } }