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).

!759

static Class parser;

p {
  print("parser bot loading");
  parser = hotwire_overBot("#1002719");
  print("parser bot loaded");
  makeBot();
}

answer {
  // turing-testable!
  if "does * parse as * with rules *" exceptionToUser {
    S text = m.unq(0);
    S className = m.unq(1);
    S rules = m.unq(2);
    ret doesParse(text, className, rules);
  }
  
  if "does * jparse as *" exceptionToUser {
    S text = m.unq(0);
    S className = m.unq(1);
    S rules = "#1002329"; // Java parsing rules
    ret doesParse(text, className, rules);
  }
    
  if "parse * with rules *" exceptionToUser {
    S text = m.unq(0);
    S rules = m.unq(1);
    
    S explainClass = null;

    O result;
    time {
      result = call(parser, "parse", text, rules);
    }
    
    /*if (debug)
      ret "```" + call(result, "prettierAnalysis") + "```";
    else if (explain)
      ret structure(call(result, "explain", explainClass));
    else*/ {
      L<S> classes = cast call(result, "fullMatchClasses");
      ret (empty(classes) ? "not parsed" : "parsed as " + structure(classes)) + " [" + getLastTiming() + " ms, " + getOpt(parser, "timing") + " ms actual]";
    }
  }
}

static S doesParse(S text, S className, S rules) {
  O result;
  L<S> classes;
  time {
    result = call(parser, "parse", text, rules);
    classes = (L) call(result, "fullMatchClasses");
  }
  
  S answer = classes.contains(className) ? "yes" : "no";
  S timing = " [" + getLastTiming() + " ms]";
  ret answer + timing;
}

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: 646 / 1156
Referenced in: [show references]