code: func (p *Parser) parseTarget(tr targetRequirement) (*Target, error) {
  	if tok, pos, lit := p.ScanIgnoreWhitespace(); tok != INTO {
  		if tr == targetRequired {
  			return nil, newParseError(tokstr(tok, lit), []string{"INTO"}, pos)
  		}
  		p.Unscan()
  		return nil, nil
  	}
  
  	// db, rp, and / or measurement
  	idents, err := p.parseSegmentedIdents()
  	if err != nil {
  		return nil, err
  	}
  
  	if len(idents) < 3 {
  		// Check for source measurement reference.
  		if ch := p.peekRune(); ch == ':' {
  			if err := p.parseTokens([]Token{COLON, MEASUREMENT}); err != nil {
  				return nil, err
  			}
  			// Append empty measurement name.
  			idents = append(idents, "")
  		}
  	}
  
  	t := &Target{Measurement: &Measurement{IsTarget: true}}
  
  	switch len(idents) {
  	case 1:
  		t.Measurement.Name = idents[0]
  	case 2:
  		t.Measurement.RetentionPolicy = idents[0]
  		t.Measurement.Name = idents[1]
  	case 3:
  		t.Measurement.Database = idents[0]
  		t.Measurement.RetentionPolicy = idents[1]
  		t.Measurement.Name = idents[2]
  	}
  
  	return t, nil
  }
docs: // parseTarget parses a string and returns a Target.