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

50
LINES

< > BotCompany Repo | #1008908 // ctxParseExpression

JavaX fragment (include)

1  
static CtxExpr ctxParseExpression(S exp) {
2  
  Explain e = explain(exp, ctxParsingRules(), "exp");
3  
  if (e == null) fail("Couldn't parse expression: " + exp);
4  
  ret ctxParseExpression(e);
5  
}
6  
7  
static CtxExpr ctxParseExpression(Explain exp) {
8  
  try {
9  
    if (exp.is("bracket")) {
10  
      CtxExpr e = ctxParseExpression(exp.sub(0));
11  
      if (e instanceof CtxConst)
12  
        ret new CtxRegexp(e/CtxConst.value);
13  
      ret e;
14  
    }
15  
    if (exp.is("fcall")) {
16  
      CtxFCall call = new(exp.str(0));
17  
      for (int i = 1; i < l(exp.subs); i++)
18  
        call.add(ctxParseSub(exp, i));
19  
      ret call;
20  
    }
21  
    if (exp.is("and"))
22  
      ret new CtxAnd(ctxParseSub(exp, 0),
23  
        ctxParseSub(exp, 1));
24  
    if (exp.is("or"))
25  
      ret new CtxOr(ctxParseSub(exp, 0),
26  
        ctxParseSub(exp, 1));
27  
    if (exp.is("neg"))
28  
      ret new CtxNeg(ctxParseSub(exp, 0));
29  
    if (exp.is("int"))
30  
      ret new CtxConst(exp.tok().get(1));
31  
    if (exp.is("quoted"))
32  
      ret new CtxConst(unquoteCtx(exp.tok().get(1)));
33  
      //ret new CtxRegexp(unquoteCtx(exp.tok().get(1)));
34  
    //if (exp.is("id"))
35  
    if (l(exp.tok()) == 3 && isIdentifier(exp.tok().get(1)))
36  
      ret new CtxVar(exp.tok().get(1));
37  
    if (exp.is("comp"))
38  
      ret new CtxComp(ctxParseSub(exp, 0), ctxParseSub(exp, 1));
39  
    if (exp.is("uneq"))
40  
      ret new CtxUneq(ctxParseSub(exp, 0), ctxParseSub(exp, 1));
41  
    if (exp.is("match"))
42  
      ret new CtxMatch(ctxParseSub(exp, 0), unquoteCtx(exp.str(1)));
43  
    if (exp.singleEqualChild())
44  
      ret ctxParseExpression(exp.sub(0));
45  
  } catch e {
46  
    printExplainTree(exp);
47  
    throw rethrow(e);
48  
  }
49  
  throw todo(exp.className() + " - " + quote(exp.string()));
50  
}

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: 601 / 646
Version history: 22 change(s)
Referenced in: [show references]