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

49
LINES

< > BotCompany Repo | #1012905 // je_checkRule

JavaX fragment (include)

static new ThreadLocal<Bool> je_checkRule_debug;

static bool je_checkRule(L<JE_CascadeEntry> rule) {
  try {
    ret je_checkRule_impl(rule);
  } catch e {
    printShortOrLongException(e, isTrue(je_checkRule_debug!));
  }
  false;
}

static bool je_checkRule_impl(L<JE_CascadeEntry> rule) {
  bool debug = isTrue(je_checkRule_debug!);
  for (JE_CascadeEntry e : rule) {
    if (eqicOneOf(e.op, "if", "and")) {
      if (e.java) {
        // direct match on input with: if "bla"
        if (l(e.tok) == 3 && isQuoted(get(e.tok, 1))) {
          S input = (S) ai_getVar("#input");
          S pat = unquote(get(e.tok, 1));
          if (!eqic(input, pat)) {
            debug print "Rule fail on input: " + pat + " / " + input;
            false;
          }
        } else {
          O result = safeInterpretedJavaEval(e.tok);
          if (!isTrue_able(result))
            fail("Weird result type of function " + join(e.tok) + ": " + (result instanceof S ? quote((S) result) : className(result)));
          if (!isTrue(result)) {
            debug print "Rule fail on Java: " + join(e.tok);
            false;
          }
        }
      } else {
        L<S> tok = tok_withoutOuterBrackets(e.tok);
        T3<S> t = ai_tripelizeOrParseTriple(join(tok));
        if (!has(t)) {
          debug print "Rule fail on triple: " + ai_renderTriple(t);
          false;
        }
      }
    } else if (eqic(e.op, "then"))
      break;
    else
      fail("Unsupported operator: " + e.op);
  }
  debug print "Rule hit";
  true;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012905
Snippet name: je_checkRule
Eternal ID of this version: #1012905/12
Text MD5: d26882b38ae85f3367ed45a3eb2d0058
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-18 19:08:13
Source code size: 1575 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 295 / 344
Version history: 11 change(s)
Referenced in: [show references]