Libraryless. Click here for Pure Java version (4815L/31K).
| 1 | static L<ExtS> smartParser1_generic(S program, O... _) {
 | 
| 2 | optPar bool verbose; | 
| 3 | new L<ExtS> out; | 
| 4 | |
| 5 | // split into paragraphs and unindent | 
| 6 | |
| 7 | LS paragraphs = map autoUnindent(map rtrim(tok_splitAtEmptyLines(program))); | 
| 8 |   if (verbose) print("Got " + n2(paragraphs, "parapraph"));
 | 
| 9 | |
| 10 | // print the parapraphs | 
| 11 |   if (verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs)));
 | 
| 12 | |
| 13 | // throw away comment-only and quoted paragraphs (assume it's a title) | 
| 14 | LS paragraphs2 = antiFilter(paragraphs, s -> | 
| 15 | isSingleLine(trim(s)) && isQuoted(trim(s)) || countJavaTokens(s) == 0 | 
| 16 | || endsWith(rtrim(s), "----")); | 
| 17 |   if (verbose) print("Got " + n2(paragraphs2, "filtered paragraph"));
 | 
| 18 |   if (verbose) print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs2)));
 | 
| 19 | |
| 20 | // find fact paragraphs | 
| 21 | |
| 22 | Pair<LS> p1 = filterAntiFilter(s -> | 
| 23 | !isSingleLine(trim(s)) && allLinesAreUnindented(s), paragraphs2); | 
| 24 | LS multiFactParagraphs = p1.a, paragraphs3 = p1.b; | 
| 25 | |
| 26 | for (S para : multiFactParagraphs) | 
| 27 | for (S s : tlft(para)) | 
| 28 | out.add(ext fact(s)); | 
| 29 | |
| 30 | // find logic rules | 
| 31 | |
| 32 | new LS paragraphs4; | 
| 33 |   for (S para : paragraphs3) {
 | 
| 34 | PairS p = splitAtDoubleArrow_pair(para); | 
| 35 | if (p == null) continue with paragraphs4.add(para); | 
| 36 | out.add(ext logicRule(para)); | 
| 37 | } | 
| 38 | |
| 39 |   if (verbose) pnlStruct("Unparsed - assuming facts", paragraphs4);
 | 
| 40 | |
| 41 | // assume the unparsed stuff consists of facts | 
| 42 | for (S para : paragraphs4) | 
| 43 | out.add(ext fact(para)); | 
| 44 | |
| 45 | ret out; | 
| 46 | } | 
Began life as a copy of #1025615
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1025648 | 
| Snippet name: | smartParser1_generic | 
| Eternal ID of this version: | #1025648/3 | 
| Text MD5: | f01c694e9982addee465a6cf5eb12874 | 
| Transpilation MD5: | c7abe6c6924c3fbb6109d6e9f432749a | 
| Author: | stefan | 
| Category: | javax / a.i. | 
| Type: | JavaX fragment (include) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2019-10-12 17:27:39 | 
| Source code size: | 1513 bytes / 46 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 377 / 489 | 
| Version history: | 2 change(s) | 
| Referenced in: | [show references] |