code: func (p *parser) parseRegex() (rx *regexp.Regexp, err error) {
  	i := p.i
  	if len(p.s) < i+2 {
  		return nil, errors.New("expected regular expression, found EOF instead")
  	}
  
  	// number of open parens or brackets;
  	// when it becomes negative, finished parsing regex
  	open := 0
  
  loop:
  	for i < len(p.s) {
  		switch p.s[i] {
  		case '(', '[':
  			open++
  		case ')', ']':
  			open--
  			if open < 0 {
  				break loop
  			}
  		}
  		i++
  	}
  
  	if i >= len(p.s) {
  		return nil, errors.New("EOF in regular expression")
  	}
  	rx, err = regexp.Compile(p.s[p.i:i])
  	p.i = i
  	return rx, err
  }
docs: // parseRegex parses a regular expression; the end is defined by encountering an
  // unmatched closing ')' or ']' which is not consumed