couchbaselabs / gojsonsm

Go implementation of my JSONSM algorithm.
9 stars 7 forks source link

Fixes #106: #109

Closed nelio2k closed 5 years ago

nelio2k commented 5 years ago

Checking parenthesis for subExpression during outputExpression leads to only counting the subExpression parenthesis as the final tally, and causes correct parenthesis cases to be incorrect as the prev counts are lost.

For example, the statement: ((TRUE OR FALSE) AND (FALSE OR TRUE))

For the parenthesis check, it gets the total Open and total Close, which are 3 each. That is correct.

But during the OutputExpression() call for the subExpression, it counts 1 open and 2 closes:

GetTotalOpen on ( FALSE(bool) OR TRUE(bool) ) )
( FALSE(bool) OR TRUE(bool) ) ) returned: andOpen: 1 subOpen: 0 totalCnt: 1
GetTotalClose on ( FALSE(bool) OR TRUE(bool) ) )
( FALSE(bool) OR TRUE(bool) ) ) returned: andClose: 2 subClose: 0 totalCnt: 2
Open: 1 close: 2

As OutputExpression() calls parenthesis check un-necessarily on the subExpression, the count returns the final tally as 1 open and 2 closes, and returns a non-nil err. The count is invalid in the scope of the subExpression, but is valid in the overall expression.