Skip to content

Commit 83e3bf9

Browse files
committed
1106
1 parent 7bf519b commit 83e3bf9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @param {String} expression
2+
# @return {Boolean}
3+
def parse_bool_expr(expression)
4+
parse = lambda { |expression, index|
5+
if expression[index] == 't'
6+
return true, index + 1
7+
elsif expression[index] == 'f'
8+
return false, index + 1
9+
elsif expression[index] == '!'
10+
bool, next_index = parse.call(expression, index + 2)
11+
return !(bool), next_index + 1
12+
else
13+
result = is_and = expression[index] == '&'
14+
next_index = index + 2
15+
while expression[next_index] != ')'
16+
sub_result, next_index = parse.call(expression, next_index)
17+
result = is_and ? (result & sub_result) : (result | sub_result)
18+
next_index += 1 if expression[next_index] == ","
19+
end
20+
return result, next_index + 1
21+
end
22+
}
23+
24+
parse.call(expression, 0).first
25+
end

0 commit comments

Comments
 (0)