namarara/spec/example-single-expr.rb

23 lines
444 B
Ruby
Raw Normal View History

require 'namarara'
# Initialize Namarara
namarara = Namarara::Parser.new(Namarara::Lexer.new)
# Prepare variables
2019-12-27 19:42:56 +00:00
namarara.names = {
this: 'true',
that: 'false',
other: 'false',
something_else: 'true'
}
2019-12-27 19:42:56 +00:00
# Build a binary expression tree (aka BET) from string
# and inject values
exp_tree = namarara.parse('this AND (that OR other) AND something_else')
# Compute tree with variables
result = exp_tree.compute
2019-12-27 19:42:56 +00:00
puts result # = false