Class: Mxrb::Runtime::Native::Expression
- Inherits:
-
Object
- Object
- Mxrb::Runtime::Native::Expression
- Defined in:
- lib/mxrb/runtime/native.rb
Overview
Deliberately small Mendix-expression evaluator. Unsupported syntax is rejected rather than guessed, preserving deterministic test semantics.
Constant Summary collapse
- COMPARISONS =
{ '=' => ->(left, right) { left == right }, '!=' => ->(left, right) { left != right }, '>' => ->(left, right) { left > right }, '<' => ->(left, right) { left < right }, '>=' => ->(left, right) { left >= right }, '<=' => ->(left, right) { left <= right } }.freeze
Instance Method Summary collapse
Instance Method Details
#evaluate(source, variables, node: nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mxrb/runtime/native.rb', line 60 def evaluate(source, variables, node: nil) text = strip_outer_parentheses(unwrap(source).strip) return nil if text.empty? || text == 'empty' return true if text.casecmp?('true') return false if text.casecmp?('false') return text[1...-1].gsub("''", "'") if quoted?(text) return Integer(text) if text.match?(/\A-?\d+\z/) return Float(text) if text.match?(/\A-?\d+\.\d+\z/) return variable(text, variables) if text.match?(%r{\A\$[A-Za-z_]\w*(?:/[A-Za-z_][\w.]*)?\z}) return node_member(text, node) if node && (text) logical(text, variables) { |part| evaluate(part, variables, node:) } rescue ArgumentError, TypeError raise NativeRuntimeError, "unsupported Mendix expression: #{source.inspect}" end |