bool smartParser1_verbose; void smartParser1(S program) { // split into paragraphs and unindent LS paragraphs = map(s -> withoutLeadingLinesEmptyAfterTrim_autoUnindent(rtrim(s)), tok_splitAtEmptyLines(program)); if (smartParser1_verbose) print("Got " + n2(paragraphs, "parapraph")); // print the parapraphs if (smartParser1_verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs))); // throw away comment-only and quoted paragraphs (assume it's a title) LS paragraphs2 = antiFilter(paragraphs, s -> isSingleLine(trim(s)) && isQuoted(trim(s)) || countJavaTokens(s) == 0 || endsWith(rtrim(s), "----")); if (smartParser1_verbose) print("Got " + n2(paragraphs2, "filtered paragraph")); if (smartParser1_verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs2))); // find fact paragraphs if (smartParser1_verbose) print(map allLinesAreUnindented(paragraphs2)); Pair p1 = filterAntiFilter(s -> !isSingleLine(trim(s)) && allLinesAreUnindented(s), paragraphs2); LS multiFactParagraphs = p1.a, paragraphs3 = p1.b; for (S para : multiFactParagraphs) for (S s : tlft(para)) addFactFromProgram(s); // find logic rules new LS paragraphs4; for (S para : paragraphs3) { PairS p = splitAtFirstDoubleArrow(javaTokWithBrackets(para)); if (p == null) continue with paragraphs4.add(para); addLogicRule(new LogicRule(splitAtAmpersand2(p.a), p.b), para); } if (smartParser1_verbose) pnlStruct("Unparsed - assuming facts", paragraphs4); // assume the unparsed stuff consists of facts for (S para : paragraphs4) addFactFromProgram(para); }