0

I'm not sure where exactly to start with this one. I know I can do bit-wise logical combinations of masks like so: (mask1 & mask2) | mask3 | (mask4 & (mask5 | mask6))

Now, if I had a user input a string like: '(criteria1 & criteria2) | criteria3 | (criteria4 & (criteria5 | criteria6))', but needed to interpret each criteria through a function to determine and return a mask, how can I retain the parentheses and logic and then combine the masks?

Matt Takao
  • 2,406
  • 3
  • 16
  • 30

1 Answers1

0

After some work I was able to do this with regular expressions and eval().

Using regex, I extracted both the 'template' and the 'criteria'. The 'template' would look something like 1 & 2 | (3 & 4 & (5 or 6)), and the associated 'criteria' would be something like ['criteria1', 'criteria2', ..., 'criteria6']. Then I could manipulate the criteria however I wanted, then substitute the manipulated values back into the template string. Finally, I could just run eval(template) or whatever name of the final string to be executed.

Matt Takao
  • 2,406
  • 3
  • 16
  • 30