2019-12-27 19:30:23 +00:00
|
|
|
|
|
|
|
require 'namarara'
|
|
|
|
|
|
|
|
# Initialize Namarara
|
|
|
|
namarara = Namarara::Parser.new(Namarara::Lexer.new)
|
|
|
|
|
|
|
|
# Prepare variables
|
2019-12-27 19:42:56 +00:00
|
|
|
namarara.names = {
|
2019-12-27 19:30:23 +00:00
|
|
|
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')
|
|
|
|
|
2019-12-27 19:30:23 +00:00
|
|
|
# Compute tree with variables
|
|
|
|
result = exp_tree.compute
|
2019-12-27 19:42:56 +00:00
|
|
|
puts result # = false
|
|
|
|
|