code: public String readToken(String remainder) {
          final String token;
          try {
              Stack<Character> parens = new Stack<Character>();
  
              int nextExpression;
              for (nextExpression = 0; nextExpression < remainder.length(); nextExpression++) {
                  char c = remainder.charAt(nextExpression);
  
                  // check for quotation
                  String match = null;
                  for (Pattern pattern : literalPatterns) {
                      Matcher matcher = pattern.matcher(remainder).region(
                              nextExpression, remainder.length());
                      if (matcher.lookingAt()) {
                          match = matcher.group(0);
                          break;
                      }
                  }
  
                  if (match != null) {
                      // we found and can consume a quotation
                      nextExpression += match.length() - 1;
                  } else if (c == '(') {
                      parens.push(c);
                  } else if (c == ')') {
                      if (parens.isEmpty()) {
                          break;
                      } else {
                          parens.pop();
                      }
                  } else if (c == '&' || c == '|') {
                      break;
                  }
              }
  
              token = remainder.substring(0, nextExpression).trim();
          } catch (Exception e) {
              throw new TokenizeLogicException("Error parsing token: "
                      + remainder, e);
          }
  
          if (token.isEmpty()) {
              throw new TokenizeLogicException("zero-length token found.");
          }
  
          return token;
      }
docs: *
  The readToken method reads a token from the remaining LogicExpression string.
  
  A token may contain a string.  If it contains parentheses, the token
  will last until the parentheses are balanced.  And &, |, or unbalanced )
  will mark the end of a token.
  
  This is a default implementation that may be overriden.
  @param  remainder  the remaining text to tokenize
  @return  a token from the beginning on `remaining`