src/rsql-parser.js
/**
 *  tokenize rsql section string to operation units,
 *    resolve and, or
 */
tokenize rsql section string to operation units,
resolve and, or
tokenize rsql section string to operation units resolve and or
function tokenizeRsqlSection(sectionString) {
  var sectionUnit = {};
  var tokenOrs, tokenAnds;
  var _and = [];
  if (sectionString.includes(',')) {
    var _or = [];
    tokenOrs = sectionString.split(",");
    for (var i = 0; i < tokenOrs.length; i++) {
      if (tokenOrs[i].includes(';')) {
        _and = [];
        tokenAnds = tokenOrs[i].split(';');
        for (var j = 0; j < tokenAnds.length; j++) {
          if (objUtil.isEmpty(tokenAnds[j])) {
            logger.debug('Ignoring the empty and token...');
          }
          else {
            analyzeNAddSection(tokenAnds[j], _and);
          }
        }
        logger.debug('Add the and unit in or array only if _and array is not empty!');
        if (!objUtil.isEmpty(_and)) {
          var andUnit = {};
          andUnit.and = _and;
          _or.push(andUnit);
        }
      }
      else {
        if (objUtil.isEmpty(tokenOrs[i])) {
          logger.debug('Ignoring the empty or token...');
        }
        else {
          analyzeNAddSection(tokenOrs[i], _or);
        }
      }
    }
    if (objUtil.isEmpty(_or)) {
      logger.debug('Add _or array to sectionUnit only if it is not empty!');
    }
    else if (_or.length === 1) {
      sectionUnit = _or[0];
    }
    else {
      sectionUnit.or = _or; 
    }
  }
  else if (sectionString.includes(';')) {
    _and = [];
    tokenAnds = sectionString.split(';');
    for (var i = 0; i < tokenAnds.length; i++) {
      if (objUtil.isEmpty(tokenAnds[i])) {
        logger.debug('Ignoring the empty and token...');
      }
      else {
        analyzeNAddSection(tokenAnds[i], _and);
      }
    }
    logger.debug('Add _and array to sectionUnit only if it is not empty!');
    if (!objUtil.isEmpty(_and)) {
      sectionUnit.and = _and; 
    }
  }
  else {
    logger.debug('single element(should be operation unit itself) -', sectionUnit);
    if (!objUtil.isEmpty(sectionString)) {
      sectionUnit = sectionString; 
    }
  }
  return sectionUnit;
}
function tokenizeRsqlSection ( sectionString ) { var sectionUnit = { } ; var tokenOrs , tokenAnds ; var _and = [ ] ; if ( sectionString . includes ( ',' ) ) { var _or = [ ] ; tokenOrs = sectionString . split ( "," ) ; for ( var i = 0 ; i < tokenOrs . length ; i ++ ) { if ( tokenOrs [ i ] . includes ( ';' ) ) { _and = [ ] ; tokenAnds = tokenOrs [ i ] . split ( ';' ) ; for ( var j = 0 ; j < tokenAnds . length ; j ++ ) { if ( objUtil . isEmpty ( tokenAnds [ j ] ) ) { logger . debug ( 'Ignoring the empty and token...' ) ; } else { analyzeNAddSection ( tokenAnds [ j ] , _and ) ; } } logger . debug ( 'Add the and unit in or array only if _and array is not empty!' ) ; if ( ! objUtil . isEmpty ( _and ) ) { var andUnit = { } ; andUnit . and = _and ; _or . push ( andUnit ) ; } } else { if ( objUtil . isEmpty ( tokenOrs [ i ] ) ) { logger . debug ( 'Ignoring the empty or token...' ) ; } else { analyzeNAddSection ( tokenOrs [ i ] , _or ) ; } } } if ( objUtil . isEmpty ( _or ) ) { logger . debug ( 'Add _or array to sectionUnit only if it is not empty!' ) ; } else if ( _or . length === 1 ) { sectionUnit = _or [ 0 ] ; } else { sectionUnit . or = _or ; } } else if ( sectionString . includes ( ';' ) ) { _and = [ ] ; tokenAnds = sectionString . split ( ';' ) ; for ( var i = 0 ; i < tokenAnds . length ; i ++ ) { if ( objUtil . isEmpty ( tokenAnds [ i ] ) ) { logger . debug ( 'Ignoring the empty and token...' ) ; } else { analyzeNAddSection ( tokenAnds [ i ] , _and ) ; } } logger . debug ( 'Add _and array to sectionUnit only if it is not empty!' ) ; if ( ! objUtil . isEmpty ( _and ) ) { sectionUnit . and = _and ; } } else { logger . debug ( 'single element(should be operation unit itself) -' , sectionUnit ) ; if ( ! objUtil . isEmpty ( sectionString ) ) { sectionUnit = sectionString ; } } return sectionUnit ; }
tokenize rsql section string to operation units,
    resolve and, or
tokenize rsql section string to operation units resolve and or
// check and, or build arrays // check for ors first // build _or array in section unit // tokenize into _or elements // check for token contains _and elements // init _and array // tokenize to _and elements // build and array // add each _and element into _and array //_and.push(tokenAnds[j]); /* if the element is a section(not operation unit) 
              continue tokenize section recursively.
              a section should be parenthesized.
          */ // build and unit in _or array // add to _or array base on token type // Add _or array to sectionUnit only if it is not empty! // if _or array only contains one element - assign the element to sectionUnit // assign _or to sectionUnit.or when _or array contains multiple elements // build _and array in section unit - only contains ands // tokenize into and elements //_and.push(tokenAnds[i]); /*  - if the element is a section(not operation unit) 
          continue tokenize section recursively.
          a section should be parenthesized.
          - the empty token will be ignored
      */ // single element - should be operation unit itself // assign to sectionUnit only if it is not empty