lib/modl/parser/evaluator.rb in modl-0.3.23 vs lib/modl/parser/evaluator.rb in modl-0.3.24
- old
+ new
@@ -30,14 +30,14 @@
def self.evaluate(global, condition)
return false if global.nil? || !global.is_a?(GlobalParseContext) || !condition.is_a?(MODL::Parser::Parsed::ParsedCondition)
start = 0
if condition.text
- value1, success = value(global, condition.text)
+ value1, success = value(global, condition.text, true)
else
start = 1
- value1, success = value(global, condition.values[0].text)
+ value1, success = value(global, condition.values[0].text, true)
end
# Handle single-value conditions of the form '{x?}'
if condition.values.length == start
@@ -52,13 +52,13 @@
i = start
result = false
while i < condition.values.length
item = condition.values[i]
if item.primitive.constant
- value2 = Substitutions.process UnicodeEscapes.process(item.text)
+ value2 = Substitutions.process(item.text)
else
- value2, success = value(global, item.text)
+ value2, success = value(global, item.text, false)
end
partial = false
case condition.operator
when '='
wild = value2.is_a?(String) && value2.include?('*') ? true : false
@@ -84,11 +84,11 @@
result |= partial
end
result
end
- def self.value(global, k)
+ def self.value(global, k, replaceFromPairIfPossible)
success = false
if k.is_a?(String) && k.include?('%')
value1, _ignore = MODL::Parser::RefProcessor.deref(k, global)
success = true
elsif k.is_a?(FalseClass)
@@ -103,15 +103,18 @@
key = k
ikey = key.to_i
if ikey.to_s == key
index_val = global.index[ikey]
value1 = index_val.respond_to?(:text) ? index_val.text : nil
- value1 = Substitutions.process UnicodeEscapes.process(value1)
+ value1 = Substitutions.process(value1)
else
pair = global.pair(key)
- return Substitutions.process UnicodeEscapes.process(k) unless pair
-
- value1 = Substitutions.process UnicodeEscapes.process(pair.text)
+ return Substitutions.process(k) unless pair
+ if replaceFromPairIfPossible
+ value1 = Substitutions.process(pair.text)
+ else
+ value1 = k
+ end
end
success = true
end
[value1, success]
end