Libraryless. Click here for Pure Java version (5353L/34K).
1 | //import static main.DateStructures.*; |
2 | |
3 | sclass EnglishDateParser > DateStructures { |
4 | bool assumeFuture = true; // e.g. for "tuesday" [not used] |
5 | |
6 | SomeDate parse(S s) null { |
7 | new ProbabilisticParser1 parser; |
8 | |
9 | // action that parses a number |
10 | ProbabilisticParser1.Action number = parser.new Any { |
11 | double calcProbabilityForMatchedText(S s) { |
12 | ret isInteger(s) ? 100 : 50; |
13 | } |
14 | }; |
15 | |
16 | LS tok = javaTok(s); |
17 | |
18 | BasicLogicRule rule = parser.ruleFromActions( |
19 | number, |
20 | parser.new ConsumeToken("/"), |
21 | number, |
22 | parser.new ConsumeToken("/"), |
23 | number |
24 | ); |
25 | parser.addState(tok, rule).userObject = func(Matches m) -> SomeDate { |
26 | new Day(parseInt($3), new Month(parseInt($2), new Year(parseInt($1)))) |
27 | }; |
28 | |
29 | parser.think(); |
30 | ProbabilisticParser1.State state = parser.bestDoneState(); |
31 | print(state); |
32 | if (state != null) { |
33 | Matches m = parser.stateToMatches(state); |
34 | print(m); |
35 | ret (SomeDate) callF(state.userObject, m); |
36 | } |
37 | } |
38 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028544 |
Snippet name: | EnglishDateParser v2 [dev.] |
Eternal ID of this version: | #1028544/4 |
Text MD5: | 1acd37e2ffc9e6accd404ee6d17f272c |
Transpilation MD5: | 0922b76d971071b552417bcc80b4efda |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-06-25 19:00:47 |
Source code size: | 1023 bytes / 38 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 184 / 264 |
Version history: | 3 change(s) |
Referenced in: | [show references] |