// combines a value with the merged token range of two PWTs static ParsedWithTokens pwt_combine(A value, ParsedWithTokens p1, ParsedWithTokens p2) { assertSame(p1.tok, p2.tok); ret new ParsedWithTokens(value, p1.tok, min(p1.iStart, p2.iStart), max(p1.iRemaining, p2.iRemaining)); } // increases the token range of a PWT merging another PWT static ParsedWithTokens pwt_combine(ParsedWithTokens p1, ParsedWithTokens p2) { ret pwt_combine(p1!, p1, p2); } // Second meaning: Combines all parses pb out of a list B // with all parses pa out of a list A // where pb occurred to the right of pb. // (Also applies a user-defined combination function merging pa and pb into a new PWT value.) static L> pwt_combine(Iterable> l1, Iterable> l2, IF2 f) { new L> out; for (ParsedWithTokens a : l1) for (ParsedWithTokens b : pwt_toTheRightOf(l2, a)) out.add(pwt_combine(f.get(a!, b!), a, b)); ret out; } // Same thing with 3 lists. static L> pwt_combine(Iterable> l1, Iterable> l2, Iterable> l3, IF3 f) { new L> out; for (ParsedWithTokens a : l1) for (ParsedWithTokens b : pwt_toTheRightOf(l2, a)) for (ParsedWithTokens c : pwt_toTheRightOf(l3, b)) out.add(pwt_combine(f.get(a!, b!, c!), a, c)); ret out; }