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

24
LINES

< > TinyBrain | #1008881 - getWoodyRuleFromSource

JavaX fragment (include)

static WoodyRule getWoodyRuleFromSource(L<S> lines, int lineIndex) {
  S s = lines.get(lineIndex);
  Explain e = explain(s, ctxParsingRules(), "rule");
  if (e == null)
    fail("Bad rule: " + s);
    
  new WoodyRule rule;
  rule.nameInFile = e.sub(0).string();
  rule.lineInFile = lineIndex;
  rule.condition = e.sub(1).string();
  pcall {
    rule.parsedCondition = ctxParseExpression(e.sub(1));
  }
  
  Pair<SS, Int> p = ctxParseProperties(lines, lineIndex+1);
  rule.properties.putAll(p.a);
  
  int opening = indexOfTrim(lines, "{", lineIndex);
  if (opening >= 0) {
    int closing = indexOfClosingCurlyBracket(lines, opening);
    rule.body = lines(subList(lines, opening+1, closing));
  }
  ret rule;
}

Author comment

Began life as a copy of #1008873

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1008881
Snippet name: getWoodyRuleFromSource
Eternal ID of this version: #1008881/6
Text MD5: 8f8ec1cefe7001e1cfe5af94a5f77334
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-18 20:09:39
Source code size: 735 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 42 / 69
Version history: 5 change(s)
Referenced in: [show]