Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > BotCompany Repo | #1002475 // Very New Parser Bot

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (4842L/33K/107K).

1  
!759
2  
3  
static Class parser;
4  
5  
p {
6  
  print("parser bot loading");
7  
  parser = hotwire_overBot("#1002719");
8  
  print("parser bot loaded");
9  
  makeBot();
10  
}
11  
12  
answer {
13  
  // turing-testable!
14  
  if "does * parse as * with rules *" exceptionToUser {
15  
    S text = m.unq(0);
16  
    S className = m.unq(1);
17  
    S rules = m.unq(2);
18  
    ret doesParse(text, className, rules);
19  
  }
20  
  
21  
  if "does * jparse as *" exceptionToUser {
22  
    S text = m.unq(0);
23  
    S className = m.unq(1);
24  
    S rules = "#1002329"; // Java parsing rules
25  
    ret doesParse(text, className, rules);
26  
  }
27  
    
28  
  if "parse * with rules *" exceptionToUser {
29  
    S text = m.unq(0);
30  
    S rules = m.unq(1);
31  
    
32  
    S explainClass = null;
33  
34  
    O result;
35  
    time {
36  
      result = call(parser, "parse", text, rules);
37  
    }
38  
    
39  
    /*if (debug)
40  
      ret "```" + call(result, "prettierAnalysis") + "```";
41  
    else if (explain)
42  
      ret structure(call(result, "explain", explainClass));
43  
    else*/ {
44  
      L<S> classes = cast call(result, "fullMatchClasses");
45  
      ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]";
46  
    }
47  
  }
48  
}
49  
50  
static S doesParse(S text, S className, S rules) {
51  
  O result;
52  
  L<S> classes;
53  
  time {
54  
    result = call(parser, "parse", text, rules);
55  
    classes = (L) call(result, "fullMatchClasses");
56  
  }
57  
  
58  
  S answer = classes.contains(className) ? "yes" : "no";
59  
  S timing = " [" + getLastTiming() + " ms]";
60  
  ret answer + timing;
61  
}

Author comment

Began life as a copy of #1002372

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002475
Snippet name: Very New Parser Bot
Eternal ID of this version: #1002475/1
Text MD5: 148fe0cc643846811edbb1b8c40d75d2
Transpilation MD5: e8e429673b50909861c26ef0e390fa5d
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-02 20:38:31
Source code size: 1554 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 647 / 1159
Referenced in: [show references]