// parseIndexTag functions parses DOSA index tag
191563
func parseIndexTag(indexName, dosaAnnotation string) (string, *PrimaryKey, error) {
	// index name struct must be exported in the entity,
	// otherwise it will be ignored when upserting the schema.
	if len(indexName) != 0 && unicode.IsLower([]rune(indexName)[0]) {
		expected := []rune(indexName)
		expected[0] = unicode.ToUpper(expected[0])
		return "", nil, fmt.Errorf("index name (%s) must be exported, "+
			"try (%s) instead", indexName, string(expected))
	}
	tag := dosaAnnotation
	// find the primaryKey
	matchs := indexKeyPattern0.FindStringSubmatch(tag)
	if len(matchs) != 4 {
		return "", nil, fmt.Errorf("dosa.Index %s with an invalid dosa index tag %q", indexName, tag)
	}
	pkString := matchs[1]
	key, err := parsePrimaryKey(indexName, pkString)
	if err != nil {
		return "", nil, errors.Wrapf(err, "struct %s has an invalid index key %q", indexName, pkString)
	}
	toRemove := strings.TrimSuffix(matchs[0], matchs[2])
	toRemove = strings.TrimSuffix(matchs[0], matchs[3])
	tag = strings.Replace(tag, toRemove, "", 1)

	//find the name
	fullNameTag, name, err := parseNameTag(tag, indexName)
	if err != nil {
		return "", nil, errors.Wrapf(err, "invalid name tag: %s", tag)
	}

	tag = strings.Replace(tag, fullNameTag, "", 1)
	tag = strings.TrimSpace(tag)
	if tag != "" {
		return "", nil, fmt.Errorf("index field %s with an invalid dosa index tag: %s", indexName, tag)
	}

	return name, key, nil
}
740062
func ParseIfAddrsTemplate(input string, ifAddrs sockaddr.IfAddrs, tmplIn *template.Template) (string, error) {
	// Create a template, add the function map, and parse the text.
	tmpl, err := tmplIn.Option("missingkey=error").
		Funcs(SourceFuncs).
		Funcs(SortFuncs).
		Funcs(FilterFuncs).
		Funcs(HelperFuncs).
		Parse(input)
	if err != nil {
		return "", errwrap.Wrapf(fmt.Sprintf("unable to parse template %+q: {{err}}", input), err)
	}

	var outWriter bytes.Buffer
	err = tmpl.Execute(&outWriter, ifAddrs)
	if err != nil {
		return "", errwrap.Wrapf(fmt.Sprintf("unable to execute sockaddr input %+q: {{err}}", input), err)
	}

	return outWriter.String(), nil
}
499161
func parseFieldTags(f reflect.StructField) fieldTags {
	var ret fieldTags

	for i, s := range strings.Split(f.Tag.Get("json"), ",") {
		switch {
		case i == 0 && s == "-":
			ret.omit = true
		case i == 0:
			ret.name = s
		case s == "omitempty":
			ret.omitEmpty = true
		case s == "!omitempty":
			ret.noOmitEmpty = true
		case s == "string":
			ret.asString = true
		case s == "required":
			ret.required = true
		}
	}

	return ret
}
175102
func NewTag(code int, value DataType) *Tag {
	tag := new(Tag)
	tag.Code = code
	tag.Value = value
	return tag
}
583106
func (p *gc_parser) parse_var_decl() (string, *ast.GenDecl) {
	p.expect_keyword("var")
	name := p.parse_exported_name()
	typ := p.parse_type()
	return name.X.(*ast.Ident).Name, &ast.GenDecl{
		Tok: token.VAR,
		Specs: []ast.Spec{
			&ast.ValueSpec{
				Names: []*ast.Ident{name.Sel},
				Type:  typ,
			},
		},
	}
}
293060
func ParseClientGenTags(lines []string) (Tags, error) {
	ret := Tags{}
	values := types.ExtractCommentTags("+", lines)
	value := []string{}
	value, ret.GenerateClient = values["genclient"]
	// Check the old format and error when used to avoid generating client when //+genclient=false
	if len(value) > 0 && len(value[0]) > 0 {
		return ret, fmt.Errorf("+genclient=%s is invalid, use //+genclient if you want to generate client or omit it when you want to disable generation", value)
	}
	_, ret.NonNamespaced = values[genClientPrefix+"nonNamespaced"]
	// Check the old format and error when used
	if value := values["nonNamespaced"]; len(value) > 0 && len(value[0]) > 0 {
		return ret, fmt.Errorf("+nonNamespaced=%s is invalid, use //+genclient:nonNamespaced instead", value[0])
	}
	_, ret.NoVerbs = values[genClientPrefix+"noVerbs"]
	_, ret.NoStatus = values[genClientPrefix+"noStatus"]
	onlyVerbs := []string{}
	if _, isReadonly := values[genClientPrefix+"readonly"]; isReadonly {
		onlyVerbs = ReadonlyVerbs
	}
	// Check the old format and error when used
	if value := values["readonly"]; len(value) > 0 && len(value[0]) > 0 {
		return ret, fmt.Errorf("+readonly=%s is invalid, use //+genclient:readonly instead", value[0])
	}
	if v, exists := values[genClientPrefix+"skipVerbs"]; exists {
		ret.SkipVerbs = strings.Split(v[0], ",")
	}
	if v, exists := values[genClientPrefix+"onlyVerbs"]; exists || len(onlyVerbs) > 0 {
		if len(v) > 0 {
			onlyVerbs = append(onlyVerbs, strings.Split(v[0], ",")...)
		}
		skipVerbs := []string{}
		for _, m := range SupportedVerbs {
			skip := true
			for _, o := range onlyVerbs {
				if o == m {
					skip = false
					break
				}
			}
			// Check for conflicts
			for _, v := range skipVerbs {
				if v == m {
					return ret, fmt.Errorf("verb %q used both in genclient:skipVerbs and genclient:onlyVerbs", v)
				}
			}
			if skip {
				skipVerbs = append(skipVerbs, m)
			}
		}
		ret.SkipVerbs = skipVerbs
	}
	var err error
	if ret.Extensions, err = parseClientExtensions(values); err != nil {
		return ret, err
	}
	return ret, validateClientGenTags(values)
}
1082072
func (p *parser) indexOfElementInScope(s scope, matchTags ...a.Atom) int {
	for i := len(p.oe) - 1; i >= 0; i-- {
		tagAtom := p.oe[i].DataAtom
		if p.oe[i].Namespace == "" {
			for _, t := range matchTags {
				if t == tagAtom {
					return i
				}
			}
			switch s {
			case defaultScope:
				// No-op.
			case listItemScope:
				if tagAtom == a.Ol || tagAtom == a.Ul {
					return -1
				}
			case buttonScope:
				if tagAtom == a.Button {
					return -1
				}
			case tableScope:
				if tagAtom == a.Html || tagAtom == a.Table {
					return -1
				}
			case selectScope:
				if tagAtom != a.Optgroup && tagAtom != a.Option {
					return -1
				}
			default:
				panic("unreachable")
			}
		}
		switch s {
		case defaultScope, listItemScope, buttonScope:
			for _, t := range defaultScopeStopTags[p.oe[i].Namespace] {
				if t == tagAtom {
					return -1
				}
			}
		}
	}
	return -1
}
1192118
func parseIndex(line string) (collectionName string, newIndex *mgo.Index, err error) {

	// Begin parsing new index from next line of file
	// format: <collection_name>.<index(es)>
	config := strings.SplitN(line, ".", 2)
	if len(config) < 2 {
		// Bad index format
		return "", nil, newParseIndexError(line, "Not of format <collection_name>.<index(es)>")
	}

	collectionName = config[0]
	if len(collectionName) == 0 {
		// No collection name provided
		return "", nil, newParseIndexError(line, "No collection name given")
	}

	indexSpec := config[1]
	if len(indexSpec) == 0 {
		// No index specification provided
		return "", nil, newParseIndexError(line, "No index key(s) given")
	}

	if string(indexSpec[0]) == "(" {
		// this is a compound index spec
		newIndex, err = parseCompoundIndex(indexSpec)
	} else {
		// this is a standard index spec
		newIndex, err = parseStandardIndex(indexSpec)
	}

	if err != nil {
		return "", nil, newParseIndexError(line, err.Error())
	}

	// build the index in the background; do not block other connections
	newIndex.Background = true
	return collectionName, newIndex, nil
}
674280
func parseIncludeOrEmbed(t *Tree) (expr Expr, with Expr, only bool, err error) {
	expr, err = t.parseExpr()
	if err != nil {
		return
	}
	only = false
	switch tok := t.peekNonSpace(); tok.tokenType {
	case tokenEOF:
		err = newUnexpectedEOFError(tok)
		return
	case tokenName:
		if tok.value == "only" { // {% include <expr> only %}
			t.next()
			_, err = t.expect(tokenTagClose)
			if err != nil {
				return
			}
			only = true
			return expr, with, only, nil
		} else if tok.value != "with" {
			err = newUnexpectedTokenError(tok)
			return
		}
		t.next()
		with, err = t.parseExpr()
		if err != nil {
			return
		}
	case tokenTagClose:
	// no op
	default:
		err = newUnexpectedTokenError(tok)
		return
	}
	switch tok := t.nextNonSpace(); tok.tokenType {
	case tokenEOF:
		err = newUnexpectedEOFError(tok)
		return
	case tokenName:
		if tok.value != "only" {
			err = newUnexpectedTokenError(tok)
			return
		}
		_, err = t.expect(tokenTagClose)
		if err != nil {
			return
		}
		only = true
	case tokenTagClose:
	// no op
	default:
		err = newUnexpectedTokenError(tok)
		return
	}
	return
}
922011
func parseTagName(tag string) string {
	if idx := strings.Index(tag, ","); idx != -1 {
		return tag[:idx]
	}
	return tag
}
80477
func ParseIfAddrs(input string, ifAddrs sockaddr.IfAddrs) (string, error) {
	return ParseIfAddrsTemplate(input, ifAddrs, template.New("sockaddr.Parse"))
}
621310
func parseStructTag(tag string) map[string]string {
	re := regexp.MustCompile("^([^:\"]+):\"([^\"]*)\" *(.*)")
	result := map[string]string{}

	if tag[0] != '`' || tag[len(tag)-1] != '`' {
		panic(fmt.Sprintf("Expected tag to begin and end with `, got: \"%s\"", tag))
	}

	parseStructTagInner(re, result, tag[1:len(tag)-1])
	return result
}
702968
func parseImport(t *Tree, start Pos) (Node, error) {
	name, err := t.parseExpr()
	if err != nil {
		return nil, err
	}
	_, err = t.expectValue(tokenName, "as")
	if err != nil {
		return nil, err
	}
	tok, err := t.expect(tokenName)
	if err != nil {
		return nil, err
	}
	_, err = t.expect(tokenTagClose)
	if err != nil {
		return nil, err
	}
	return NewImportNode(name, tok.value, start), nil
}
361866
func ParseTags(line string) Tags {
	ret := Tags{}

	tags := strings.Split(line, ";")
	for _, tag := range tags {
		parts := strings.SplitN(tag, "=", 2)
		if len(parts) < 2 {
			ret[parts[0]] = ""
			continue
		}

		ret[parts[0]] = ParseTagValue(parts[1])
	}

	return ret
}
1097275
func (p *parser) parseIDSelector() (Selector, error) {
	if p.i >= len(p.s) {
		return nil, fmt.Errorf("expected id selector (#id), found EOF instead")
	}
	if p.s[p.i] != '#' {
		return nil, fmt.Errorf("expected id selector (#id), found '%c' instead", p.s[p.i])
	}

	p.i++
	id, err := p.parseName()
	if err != nil {
		return nil, err
	}

	return attributeEqualsSelector("id", id), nil
}
222478
func ParseImage(image string) (Image, error) {
	// Parse the image name and tag.
	named, err := reference.ParseNormalizedNamed(image)
	if err != nil {
		return Image{}, fmt.Errorf("parsing image %q failed: %v", image, err)
	}
	// Add the latest lag if they did not provide one.
	named = reference.TagNameOnly(named)

	i := Image{
		named:  named,
		Domain: reference.Domain(named),
		Path:   reference.Path(named),
	}

	// Add the tag if there was one.
	if tagged, ok := named.(reference.Tagged); ok {
		i.Tag = tagged.Tag()
	}

	// Add the digest if there was one.
	if canonical, ok := named.(reference.Canonical); ok {
		i.Digest = canonical.Digest()
	}

	return i, nil
}
824646
func (z *Tokenizer) readRawEndTag() bool {
	for i := 0; i < len(z.rawTag); i++ {
		c := z.readByte()
		if z.err != nil {
			return false
		}
		if c != z.rawTag[i] && c != z.rawTag[i]-('a'-'A') {
			z.raw.end--
			return false
		}
	}
	c := z.readByte()
	if z.err != nil {
		return false
	}
	switch c {
	case ' ', '\n', '\r', '\t', '\f', '/', '>':
		// The 3 is 2 for the leading "</" plus 1 for the trailing character c.
		z.raw.end -= 3 + len(z.rawTag)
		return true
	}
	z.raw.end--
	return false
}