views:

28

answers:

2

I have this, I built it programatically:

(( cat1:bobo AND ( ( cat2:jojo ) OR ( cat2:coco ) ) ))

For the sake of debugging, I am looking for a good method that would basically reduce it to least amount of parens needed:

cat1:bobo AND ( cat2:jojo  OR  cat2:coco )

I'm on C#, but if you have a good technique you've seen, I will port it.

A: 

if you built it programmatically, you have an expression tree of some sort. nodes that aren't AND- or OR- nodes don't have to render parentheses

Jimmy
+1  A: 

Assuming you're parsing the expression into some sort of tree structure, then the approach I've taken in the past is just to navigate through the tree and remove any nodes that are just a container for other nodes.

lzcd