code: private String tokenize(String text) throws JellyException {
          int parenthesis=0;
          for(int idx=0;idx<text.length();idx++) {
              char ch = text.charAt(idx);
              switch (ch) {
              case ',':
                  if(parenthesis==0)
                      return text.substring(0,idx);
                  break;
              case '(':
              case '{':
              case '[':
                  parenthesis++;
                  break;
              case ')':
                  if(parenthesis==0)
                      return text.substring(0,idx);
                  // fall through
              case '}':
              case ']':
                  parenthesis--;
                  break;
              case '"':
              case '\'':
                  // skip strings
                  idx = text.indexOf(ch,idx+1);
                  break;
              }
          }
          throw new JellyException(expressionText+" is missing ')' at the end");
      }
docs: Takes a string like "arg)" or "arg,arg,...)", then
  find "arg" and returns it.
  
  Note: this code is also copied into idea-stapler-plugin,
  so don't forget to update that when this code changes.