// parseField scans a field until a terminator
971272
func (p *Parser) parseField(cur *ListNode) error {
	p.consumeText()
	var r rune
	for {
		r = p.next()
		if isTerminator(r) {
			p.backup()
			break
		}
	}
	value := p.consumeText()
	if value == "*" {
		cur.append(newWildcard())
	} else {
		cur.append(newField(value))
	}
	return p.parseInsideAction(cur)
}
567684
func ParseARFFGetRows(filepath string) (int, error) {

	f, err := os.Open(filepath)
	if err != nil {
		return 0, err
	}
	defer f.Close()

	counting := false
	count := 0
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		line := scanner.Text()
		if len(line) == 0 {
			continue
		}
		if counting {
			if line[0] == '@' {
				continue
			}
			if line[0] == '%' {
				continue
			}
			count++
			continue
		}
		if line[0] == '@' {
			line = strings.ToLower(line)
			if line == "@data" {
				counting = true
			}
		}
	}
	return count, nil
}
999362
func (p *Parser) parseSortFields() (SortFields, error) {
	var fields SortFields

	tok, pos, lit := p.ScanIgnoreWhitespace()

	switch tok {
	// The first field after an order by may not have a field name (e.g. ORDER BY ASC)
	case ASC, DESC:
		fields = append(fields, &SortField{Ascending: (tok == ASC)})
	// If it's a token, parse it as a sort field.  At least one is required.
	case IDENT:
		p.Unscan()
		field, err := p.parseSortField()
		if err != nil {
			return nil, err
		}

		if lit != "time" {
			return nil, errors.New("only ORDER BY time supported at this time")
		}

		fields = append(fields, field)
	// Parse error...
	default:
		return nil, newParseError(tokstr(tok, lit), []string{"identifier", "ASC", "DESC"}, pos)
	}

	// Parse additional fields.
	for {
		tok, _, _ := p.ScanIgnoreWhitespace()

		if tok != COMMA {
			p.Unscan()
			break
		}

		field, err := p.parseSortField()
		if err != nil {
			return nil, err
		}

		fields = append(fields, field)
	}

	if len(fields) > 1 {
		return nil, errors.New("only ORDER BY time supported at this time")
	}

	return fields, nil
}
84981
func DatetimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string) *Field {
	ret := DatetimeField(name)
	// check tags
	if v := formcommon.TagVal(t, fieldNo, "form_min"); v != "" {
		if !validateDatetime(v) {
			panic(errors.New(fmt.Sprintf("Invalid date value (min) for field: %s", name)))
		}
		ret.SetParam("min", v)
	}
	if v := formcommon.TagVal(t, fieldNo, "form_max"); v != "" {
		if !validateDatetime(v) {
			panic(errors.New(fmt.Sprintf("Invalid date value (max) for field: %s", name)))
		}
		ret.SetParam("max", v)
	}
	v := formcommon.TagVal(t, fieldNo, "form_value")
	if vt := val.Field(fieldNo).Interface().(time.Time); !vt.IsZero() {
		v = vt.Format(DATETIME_FORMAT)
	}
	ret.SetValue(v)
	return ret
}
592486
func (p *Parser) parseSortField() (*SortField, error) {
	field := &SortField{}

	// Parse sort field name.
	ident, err := p.ParseIdent()
	if err != nil {
		return nil, err
	}
	field.Name = ident

	// Check for optional ASC or DESC clause. Default is ASC.
	tok, _, _ := p.ScanIgnoreWhitespace()
	if tok != ASC && tok != DESC {
		p.Unscan()
		tok = ASC
	}
	field.Ascending = (tok == ASC)

	return field, nil
}
974939
func TimeFieldFromInstance(val reflect.Value, t reflect.Type, fieldNo int, name string) *Field {
	ret := TimeField(name)
	// check tags
	if v := formcommon.TagVal(t, fieldNo, "form_min"); v != "" {
		if !validateTime(v) {
			panic(errors.New(fmt.Sprintf("Invalid time value (min) for field", name)))
		}
		ret.SetParam("min", v)
	}
	if v := formcommon.TagVal(t, fieldNo, "form_max"); v != "" {
		if !validateTime(v) {
			panic(errors.New(fmt.Sprintf("Invalid time value (max) for field", name)))
		}
		ret.SetParam("max", v)
	}
	if v := val.Field(fieldNo).Interface().(time.Time); !v.IsZero() {
		ret.SetValue(v.Format(TIME_FORMAT))
	} else if v := formcommon.TagVal(t, fieldNo, "form_value"); v != "" {
		ret.SetValue(v)
	}
	return ret
}
1064636
func (ffl *FFLexer) CaptureField(start FFTok) ([]byte, error) {
	return ffl.scanField(start, true)
}
914631
func Field(pointerToAField interface{}, rigthOperand ...Expression) (exp Expression) {
	if len(rigthOperand) == 0 {
		return &FieldExpression{pointerToAField, nil}
	}
	return &FieldExpression{pointerToAField, rigthOperand[0]}
}
73571
func (f *Field) Field(name string) *Field {
	field, ok := f.FieldOk(name)
	if !ok {
		panic("field not found")
	}

	return field
}
709588
func (a *CompositeAggregationTermsValuesSource) Field(field string) *CompositeAggregationTermsValuesSource {
	a.field = field
	return a
}
956481
func (fi *marshalFieldInfo) computeMarshalFieldInfo(f *reflect.StructField) {
	// parse protobuf tag of the field.
	// tag has format of "bytes,49,opt,name=foo,def=hello!"
	tags := strings.Split(f.Tag.Get("protobuf"), ",")
	if tags[0] == "" {
		return
	}
	tag, err := strconv.Atoi(tags[1])
	if err != nil {
		panic("tag is not an integer")
	}
	wt := wiretype(tags[0])
	if tags[2] == "req" {
		fi.required = true
	}
	fi.setTag(f, tag, wt)
	fi.setMarshaler(f, tags)
}
833183
func decodeMapFields(val reflect.Value, body map[string]*json.RawMessage) error {
	mapVal := val
	if mapVal.IsNil() {
		valType := val.Type()
		mapType := reflect.MapOf(valType.Key(), valType.Elem())
		mapVal = reflect.MakeMap(mapType)
	}
	for jsonName, raw := range body {
		var value interface{}
		if raw != nil {
			if err := json.Unmarshal(*raw, &value); err != nil {
				return driver.WithStack(err)
			}
		}
		mapVal.SetMapIndex(reflect.ValueOf(jsonName), reflect.ValueOf(value))
	}
	val.Set(mapVal)
	return nil
}
1072709
func Field(fieldPtr interface{}, rules ...Rule) *FieldRules {
	return &FieldRules{
		fieldPtr: fieldPtr,
		rules:    rules,
	}
}
487478
func (v *Var) Parse(field reflect.StructField) error {
	v.SetName(field.Name)
	v.SetType(field.Type)
	v.SetKey(v.Name)

	tag := field.Tag.Get("env")

	if tag == "" {
		return nil
	}

	tagParams := strings.Split(tag, " ")
	for _, tagParam := range tagParams {
		var key, value string

		option := strings.Split(tagParam, "=")
		key = option[0]
		if len(option) > 1 {
			value = option[1]
		}

		switch key {
		case "key":
			// override the default key if one is specified
			v.SetKey(value)
		case "required":
			// val, _ := strconv.ParseBool(value)
			// if val != false {
			v.SetRequired(true)
			// }
		case "default":
			d, err := convert(v.Type, value)
			if err != nil {
				return err
			}
			v.SetDefault(d)
		case "options":
			in := strings.Split(value, ",")
			// var values []reflect.Value
			values := make([]reflect.Value, len(in))
			for k, val := range in {
				v1, err := convert(v.Type, val)
				if err != nil {
					return err
				}
				values[k] = v1
			}
			v.SetOptions(values)
		}
	}

	return nil
}
1303861
func parseFlags(s reflect.Value) error {
	flagSet := flag.NewFlagSet("conf", flag.ExitOnError)
	flagSet.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		flagSet.PrintDefaults()
	}
	typeOfT := s.Type()
	for i := 0; i < s.NumField(); i++ {
		fieldValue := s.Field(i)
		if fieldValue.CanSet() {
			createFlag(typeOfT.Field(i), fieldValue, flagSet)
		}
	}
	args := os.Args[1:]
	if hasTestFlag(os.Args[1:]) {
		args = []string{}
	}
	err := flagSet.Parse(args)
	if err != nil {
		return err
	}
	return nil
}
328038
func parseMacro(p *parser, input string) (string, error) {
	m := newMacro(input)
	var err error
	for m.state = scanText; m.state != nil; {
		m.state, err = m.state(m, p)
		if err != nil {
			// log error
			return "", err
		}

	}
	return strings.Join(m.output, ""), nil
}
1018449
func parseTagFields(file *os.File) ([]TagField, []error) {
	var errors []error
	re, err := regexp.Compile(`^(\S*\:)?(\s.*)?$`)
	if err != nil {
		errors = append(errors, err)
		return nil, errors
	}

	scanner := bufio.NewScanner(file)
	var fields []TagField
	var field TagField

	// Parse the remaining lines.
	for scanner.Scan() {
		line := scanner.Text()
		// See http://play.golang.org/p/zLqvg2qo1D for some testing on the field match.
		if re.MatchString(line) {
			data := re.FindStringSubmatch(line)
			data[1] = strings.Replace(data[1], ":", "", 1)
			if data[1] != "" {
				if field.Label() != "" {
					fields = append(fields, field)
				}
				field = *NewTagField(data[1], strings.Trim(data[2], " "))
				continue
			}
			value := strings.Trim(data[2], " ")
			field.SetValue(strings.Join([]string{field.Value(), value}, " "))

		} else {
			err := fmt.Errorf("Unable to parse tag data from line: %s", line)
			errors = append(errors, err)
		}
	}
	if field.Label() != "" {
		fields = append(fields, field)
	}

	if scanner.Err() != nil {
		errors = append(errors, scanner.Err())
	}

	// See http://play.golang.org/p/nsw9zsAEPF for some testing on the field match.
	return fields, errors
}