Libraryless. Click here for Pure Java version (5913L/38K/127K).
1 | !752 |
2 | |
3 | concepts. |
4 | |
5 | concept Imperative {
|
6 | new Ref v; // verb |
7 | new Ref o; // object |
8 | } |
9 | |
10 | concept Measurement {
|
11 | new Ref x; // e.g. "all" |
12 | new Ref y; // e.g. "programs" |
13 | } |
14 | |
15 | concept Addition {
|
16 | new Ref x; // e.g. "programs" |
17 | new Ref prep; // preposition, e.g. "with" |
18 | new Ref z; // e.g. "a large number of files" |
19 | } |
20 | |
21 | p {
|
22 | testParse([[Find all programs with a file called "concepts.structure"]]); |
23 | } |
24 | |
25 | sbool properSentence(Concept c) {
|
26 | if (!c << Imperative || neq(c/Imperative.v, cstr("find"))) false;
|
27 | c = c/Imperative.o!; |
28 | ret matchCstr("all programs with a file called *", c);
|
29 | //if (!c << Measurement || neq(c/Measurement.x, cstr("all"))) false;
|
30 | //c = c/Measurement.y; |
31 | } |
32 | |
33 | !include #1005497 // testParse + parseToOptions using unrollOptions |
34 | |
35 | static void parse(S s, Collector<Concept> out) {
|
36 | new Matches m; |
37 | |
38 | if (flexMatchStartIC(ll("find"), s, m))
|
39 | ret if out.add(quick(Imperative, m)); |
40 | |
41 | if (flexMatchStartIC(ll("all", "a"), s, m))
|
42 | ret if out.add(quick(Measurement, m)); |
43 | |
44 | if (flexMatchIC2("* (called|with) *", s, m))
|
45 | ret if out.add(quick(Addition, m)); |
46 | |
47 | out.add(cstr(s)); // default |
48 | } |
49 | |
50 | static Concept quick(Class<? extends Concept> cClass, Matches m) {
|
51 | Concept c = cnew(cClass); |
52 | S order = toStringOpt(getOpt(cClass, "_fieldOrder")); |
53 | L<S> fields; |
54 | if (order != null) |
55 | fields = splitAtSpace(order); |
56 | else |
57 | fields = asList(asTreeSet(conceptFields(c))); |
58 | if (l(fields) != l(m.m)) |
59 | fail(struct(fields) + " / " + struct(m.m)); |
60 | for i over fields: |
61 | cset(c, fields.get(i), parseToOptions(m.unq(i))); |
62 | ret c; |
63 | } |
Began life as a copy of #1005487
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1005502 |
| Snippet name: | Parse Sentence Multi 4, using (a|b) syntax [works] |
| Eternal ID of this version: | #1005502/1 |
| Text MD5: | c2914e61cd3be96df13dd2fb464d1edf |
| Transpilation MD5: | f1c6d0e6ed10222671b4d89c0e3d0d66 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-11-24 00:13:45 |
| Source code size: | 1613 bytes / 63 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 771 / 891 |
| Referenced in: | [show references] |