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

46
LINES

< > TinyBrain | #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 << CtxConst)
        ret new CtxRegexp(e/CtxConst.value);
      ret e;
    }
    if (exp.is("fcall"))
      ret new CtxFCall(exp.str(0), ctxParseSub(exp, 1));
    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   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1008908
Snippet name: ctxParseExpression
Eternal ID of this version: #1008908/20
Text MD5: 4ba59a698a9969fb8e637762fdc8cb84
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-25 18:54:01
Source code size: 1597 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 41 / 47
Version history: 19 change(s)
Referenced in: [show]