class MODL::Parser::Parsed::ParsedConditionTest
Class to represent a parsed grammar object
Attributes
subConditionList[RW]
Public Class Methods
new(global)
click to toggle source
# File lib/modl/parser/parsed.rb, line 772 def initialize(global) @global = global @subConditionList = [] end
Public Instance Methods
enterModl_condition_test(ctx)
click to toggle source
# File lib/modl/parser/parsed.rb, line 796 def enterModl_condition_test(ctx) ctx_children = ctx.children unless ctx_children.empty? last_operator = nil should_negate = false ctx_children.each do |child| if child.is_a? MODLParser::Modl_condition_groupContext condition_group = ParsedConditionGroup.new @global child.enter_rule(condition_group) p2 = OpenStruct.new p2.a = last_operator p2.b = should_negate p1 = OpenStruct.new p1.a = condition_group p1.b = p2 @subConditionList << p1 last_operator = nil should_negate = false elsif child.is_a? MODLParser::Modl_conditionContext condition = ParsedCondition.new @global child.enter_rule(condition) p2 = OpenStruct.new p2.a = last_operator p2.b = should_negate p1 = OpenStruct.new p1.a = condition p1.b = p2 @subConditionList << p1 last_operator = nil should_negate = false else if child.text == '!' should_negate = true else last_operator = child.text end end end end end
evaluate()
click to toggle source
# File lib/modl/parser/parsed.rb, line 777 def evaluate result = false @subConditionList.each do |s| last_operator = s.b.a should_negate = s.b.b partial = s.a.evaluate case last_operator when '&' result &= should_negate ? !partial : partial when '|' result |= should_negate ? !partial : partial else result |= should_negate ? !partial : partial end end result end