!7 module LLtoNL > DynRecordingTextArea { S output; transient S calcedInput; transient ReliableSingleThread rstCalc; visualize { ret jvsplit( jSection("INPUT (LL)", super.visualize()), jSection("OUTPUT (NL)", dm_fieldTextArea('output))); } start { doEvery(1.0, r calc); } void calc enter { if (neq(text, calcedInput)) { calcedInput = text; new LS out; final new MultiMap definitions; for (S s : tlft(text)) { LS tok = javaTokWithAllBrackets(s); continue unless isSquareBracketed(second(tok)) && eq(":", get(tok, 3); S id = second(tok); tok = subList(tok, 4); clearToken(tok, 0); definitions.put(id, tok); //out.add(join(tok)); } //out.add("Keys: " + keys(definitions)); out.addAll(map joinIfStringList(getEmits(r { render(definitions) }))); setField(output := lines(out)); } } void render(MultiMap definitions) { new Map simpleDefs; new Matches m; for (Pair p : multiMapToPairs(definitions)) if (matchStart("there is", p.b, m)) simpleDefs.put(p.a, m.rest()); LL bla = definitions.get("[1]"); if (l(bla) < 2) ret; // Make the first line LS line = concatLists( ll(dropSuffixICTrim("(definition)", join(first(bla))), " means: "), second(bla)); emit(join(line)); // Expand [2] etc. in the line print(sfu(simpleDefs)); new LS line2; for (S s : line) { S def = simpleDefs.get(s); if (def != null) line2.add(def); else line2.add(s); } if (eq(join(line), join(line2))) ret; emit(join(line2)); } }