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

50
LINES

< > BotCompany Repo | #1008908 // ctxParseExpression

JavaX fragment (include)

static CtxExpr ctxParseExpression(S exp) {
  Explain e = explain(exp, ctxParsingRules(), "exp");
  if (e == null) fail("Couldn't parse expression: " + exp);
  ret ctxParseExpression(e);
}

static CtxExpr ctxParseExpression(Explain exp) {
  try {
    if (exp.is("bracket")) {
      CtxExpr e = ctxParseExpression(exp.sub(0));
      if (e instanceof CtxConst)
        ret new CtxRegexp(e/CtxConst.value);
      ret e;
    }
    if (exp.is("fcall")) {
      CtxFCall call = new(exp.str(0));
      for (int i = 1; i < l(exp.subs); i++)
        call.add(ctxParseSub(exp, i));
      ret call;
    }
    if (exp.is("and"))
      ret new CtxAnd(ctxParseSub(exp, 0),
        ctxParseSub(exp, 1));
    if (exp.is("or"))
      ret new CtxOr(ctxParseSub(exp, 0),
        ctxParseSub(exp, 1));
    if (exp.is("neg"))
      ret new CtxNeg(ctxParseSub(exp, 0));
    if (exp.is("int"))
      ret new CtxConst(exp.tok().get(1));
    if (exp.is("quoted"))
      ret new CtxConst(unquoteCtx(exp.tok().get(1)));
      //ret new CtxRegexp(unquoteCtx(exp.tok().get(1)));
    //if (exp.is("id"))
    if (l(exp.tok()) == 3 && isIdentifier(exp.tok().get(1)))
      ret new CtxVar(exp.tok().get(1));
    if (exp.is("comp"))
      ret new CtxComp(ctxParseSub(exp, 0), ctxParseSub(exp, 1));
    if (exp.is("uneq"))
      ret new CtxUneq(ctxParseSub(exp, 0), ctxParseSub(exp, 1));
    if (exp.is("match"))
      ret new CtxMatch(ctxParseSub(exp, 0), unquoteCtx(exp.str(1)));
    if (exp.singleEqualChild())
      ret ctxParseExpression(exp.sub(0));
  } catch e {
    printExplainTree(exp);
    throw rethrow(e);
  }
  throw todo(exp.className() + " - " + quote(exp.string()));
}

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: #1008908
Snippet name: ctxParseExpression
Eternal ID of this version: #1008908/23
Text MD5: 9337bd72c6d14e1f319eaed068815366
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-21 01:14:22
Source code size: 1698 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 513 / 558
Version history: 22 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1009002 - ctxParseSub