Ejemplo n.º 1
0
Archivo: tag.go Proyecto: flowup/gogen
// ParseTags will create a TagMap from comments given by
// parameter
func ParseTags(commentMap ast.CommentMap) *TagMap {
	tagMap := NewTagMap()
	for _, comment := range commentMap.Comments() {
		// split comment to lines
		lines := strings.Split(comment.Text(), "\n")
		for _, line := range lines {
			// if line does not match this regexp made by Miro do not read tags from line
			if !regexp.MustCompile(`(\@\S+)(:? ([\S]+))*`).Match([]byte(line)) {
				continue
			}
			line, tagName, _ := parseValue(line)
			// if there is a tag on the line read its parameters and their values
			if len(tagName) > 0 && tagName[0] == '@' {
				tag := NewTag(tagName)
				//fmt.Println("Tag Name:", tagName)
				// while there is some input check for parameters
				for line != "" {
					var parName, parVal string
					line, parName, parVal = parseValue(line)
					if parName != "" {
						//fmt.Println("Parameter name:", parName, "Parameter value", parVal)
						tag.Set(parName, parVal)
					}
				}
				// save tag to map
				tagMap.Set(tagName, tag)
			}
		}
	}

	return tagMap
}