src/rsql-parser.js
/**
 *  find same level sections that are not nested
 */
find same level sections that are not nested
find same level sections that are not nested
function peerParenthesizedSections(text, sections) {
  var end = text.lastIndexOf(')');
  var i = end - 1;
  var nesting = 1;
  if (end === -1) {
    return;
  }
  while (nesting > 0) {
    var c = text.charAt(i);
    if (c === ')') {
      nesting++;
    } 
    else if (c === '(') {
      nesting--;
    }
    i--;
  }
  if (text.substring(i, i+2) !== '=(') {
    sections.push(text.substring(i+2, end));
  }
  peerParenthesizedSections(text.substring(0, i), sections);
}
function peerParenthesizedSections ( text , sections ) { var end = text . lastIndexOf ( ')' ) ; var i = end - 1 ; var nesting = 1 ; if ( end === - 1 ) { return ; } while ( nesting > 0 ) { var c = text . charAt ( i ) ; if ( c === ')' ) { nesting ++ ; } else if ( c === '(' ) { nesting -- ; } i -- ; } if ( text . substring ( i , i + 2 ) !== '=(' ) { sections . push ( text . substring ( i + 2 , end ) ) ; } peerParenthesizedSections ( text . substring ( 0 , i ) , sections ) ; }
find same level sections that are not nested
find same level sections that are not nested
// end when no more parenthesized section in string // find current section // push current section into the array exclude section start with =( // recurersivelly find the next section - for maskParenthesizedSections