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

47
LINES

< > BotCompany Repo | #1017739 // Live Parse Spike [OK]

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

Download Jar. Libraryless. Click here for Pure Java version (5837L/41K).

!7

p-exp {
  S input = "Stell dir vor die Hütte brennt";
  L<S> tok = javaTok(input);
  Parser parser = FixedTokenIC("Stell", func -> Parser {
    FixedTokenIC("dir", func -> Parser {
      FixedTokenIC("vor", func -> Parser {
        RestParser(voidfunc(S s) {
          print("Got sentence: " + s)
        })
      })
    })
  });
  tok.add("<over>");
  for i over tok: {
    parser = parser.consumeToken(tok.get(i), i);
    if (parser == null && i < l(tok)-1)
      print("No parse after " + joinSubList(tok, 0, i+1));
  }
}

abstract sclass Parser {
  abstract Parser consumeToken(S t, int idx);
}

srecord FixedTokenIC(S token, F0<Parser> nextParser) extends Parser {
  Parser consumeToken(S t, int idx) {
    if (even(idx)) this; // N token
    if (!eqic(token, t)) null;
    ret nextParser!;
  }
}

srecord RestParser(VF1<S> onParse) > Parser {
  new L<S> consumed;
  
  Parser consumeToken(S t, int idx) {
    if (eq(t, "<over>")) {
      callF(onParse, join(consumed));
      null;
    } else {
      consumed.add(t);
      this;
    }
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1017739
Snippet name: Live Parse Spike [OK]
Eternal ID of this version: #1017739/7
Text MD5: 2fe1a839c7cf32c7c13478f14627e9a5
Transpilation MD5: c875e4d7b1a4396b9acdc1dfaf21a5b4
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-07 20:18:52
Source code size: 1098 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 435 / 973
Version history: 6 change(s)
Referenced in: