1 | static Exp nlLogic_parseExpression(S s) { |
2 | if (s == null) null; |
3 | L<S> tok = javaTokPlusAllThreeBrackets(s); |
4 | |
5 | // a && b |
6 | PairS p = splitAtTokens_once(tok, ll("&", "", "&")); |
7 | if (p != null) |
8 | ret And(nlLogic_parseExpression(first(p)), nlLogic_parseExpression(second(p))); |
9 | |
10 | // !a |
11 | if (eqGet(tok, 1, "!")) |
12 | ret ExpNot(nlLogic_parseExpression(join(dropFirst(2, tok)))); |
13 | |
14 | // function with options - a[bla, blubb](...) |
15 | if (l(tok) == 7 && isIdentifier(tok.get(1)) |
16 | && isSquareBracketed(tok.get(3)) |
17 | && isRoundBracketed(tok.get(5))) |
18 | ret Func(tok.get(1), |
19 | tok_splitAtComma(deSquareBracket(tok.get(3))), |
20 | nlLogic_parseExpression(deRoundBracket(tok.get(5)))); |
21 | |
22 | // function - a(...) |
23 | if (l(tok) == 5 && isIdentifier(tok.get(1)) && isRoundBracketed(tok.get(3))) { |
24 | S name = tok.get(1), arg = deRoundBracket(tok.get(3)); |
25 | bool parseInnerPart = false; |
26 | ret Func(name, parseInnerPart ? nlLogic_parseExpression(arg) |
27 | : Sentence2(unquoteIfNormalQuoted(arg))); |
28 | } |
29 | |
30 | // a = b |
31 | LS l = splitAtTokens(tok, ll("=")); |
32 | if (l(l) == 2) |
33 | ret Eq(nlLogic_parseExpression(first(l)), nlLogic_parseExpression(second(l))); |
34 | |
35 | // default |
36 | ret Sentence2(l(tok) == 3 && isQuoted(tok.get(1)) ? unquote(second(tok)) : join(tok)); |
37 | } |
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: | #1017548 |
Snippet name: | nlLogic_parseExpression |
Eternal ID of this version: | #1017548/12 |
Text MD5: | 08996e91773b7d0e0f7979f664379161 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-08-25 10:41:22 |
Source code size: | 1313 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 415 / 473 |
Version history: | 11 change(s) |
Referenced in: | [show references] |