// Returns specifics for parsing a dict field value.
977430
func getDictField(dict reflect.Value, key string) dictField {
	// get valuev as a map value or as a struct field
	switch dict.Kind() {
	case reflect.Map:
		value := reflect.New(dict.Type().Elem()).Elem()
		return dictField{
			Value: value,
			Ok:    true,
			Set: func() {
				if dict.IsNil() {
					dict.Set(reflect.MakeMap(dict.Type()))
				}
				// Assigns the value into the map.
				dict.SetMapIndex(reflect.ValueOf(key).Convert(dict.Type().Key()), value)
			},
		}
	case reflect.Struct:
		sf, ok := getStructFieldForKey(dict.Type(), key)
		if !ok {
			return dictField{}
		}
		if sf.r.PkgPath != "" {
			panic(&UnmarshalFieldError{
				Key:   key,
				Type:  dict.Type(),
				Field: sf.r,
			})
		}
		return dictField{
			Value: dict.FieldByIndex(sf.r.Index),
			Ok:    true,
			Set:   func() {},
			IgnoreUnmarshalTypeError: sf.tag.IgnoreUnmarshalTypeError(),
		}
	default:
		return dictField{}
	}
}
870475
func parseRecursive(parsers Parsers, val reflect.Value) reflect.Value {
	switch val.Kind() {
	case reflect.Ptr:
		o := val.Elem()
		if o.IsValid() {
			res := parseRecursive(parsers, o)
			if res != reflect.ValueOf(nil) {
				return res
			}
		}
	case reflect.Interface:
		res := parseRecursive(parsers, val.Elem())
		if res != reflect.ValueOf(nil) {
			return res
		}
	case reflect.Struct:
		for i := 0; i < val.NumField(); i++ {
			res := parseRecursive(parsers, val.Field(i))
			if res != reflect.ValueOf(nil) {
				val.Field(i).Set(res)
			}
		}
		return val
	case reflect.Slice:
		for i := 0; i < val.Len(); i++ {
			res := parseRecursive(parsers, val.Index(i))
			if res != reflect.ValueOf(nil) {
				val.Index(i).Set(res)
			}
		}
		return val
	case reflect.Map:
		for _, k := range val.MapKeys() {
			mapVal := val.MapIndex(k)
			res := parseRecursive(parsers, mapVal)
			if res != reflect.ValueOf(nil) {
				val.SetMapIndex(k, res)
			}
		}
		return val
	case reflect.String:
		if parsers.StringParser != nil {
			value := parsers.StringParser.ParseString(val.String())
			return reflect.ValueOf(value)
		}
		return val
	case reflect.Int:
		if parsers.IntParser != nil {
			value := parsers.IntParser.ParseInt(val.Int())
			return reflect.ValueOf(value)
		}
		return val
	case reflect.Float64:
		if parsers.FloatParser != nil {
			value := parsers.FloatParser.ParseFloat(val.Float())
			return reflect.ValueOf(value)
		}
		return val
	default:
		return val
	}

	return reflect.ValueOf(nil)
}
1012724
func GetFields(body []byte) ([]string, error) {
	query, err := pql.ParseString(string(body))
	if err != nil {
		return nil, fmt.Errorf("parsing query: %v", err.Error())
	}

	fields := make([]string, len(query.Calls))

	for i, call := range query.Calls {
		if field, ok := call.Args["field"].(string); ok {
			fields[i] = field
		} else if field, ok := call.Args["_field"].(string); ok {
			fields[i] = field
		} else {
			fields[i] = ""
		}
	}
	return fields, nil
}
647794
func (s *SearchService) DocvalueField(docvalueField string) *SearchService {
	s.searchSource = s.searchSource.DocvalueField(docvalueField)
	return s
}
912460
func (p *Parser) parseField() (*Field, error) {
	f := &Field{}

	// Attempt to parse a regex.
	re, err := p.parseRegex()
	if err != nil {
		return nil, err
	} else if re != nil {
		f.Expr = re
	} else {
		_, pos, _ := p.ScanIgnoreWhitespace()
		p.Unscan()
		// Parse the expression first.
		expr, err := p.ParseExpr()
		if err != nil {
			return nil, err
		}
		var c validateField
		Walk(&c, expr)
		if c.foundInvalid {
			return nil, fmt.Errorf("invalid operator %s in SELECT clause at line %d, char %d; operator is intended for WHERE clause", c.badToken, pos.Line+1, pos.Char+1)
		}
		f.Expr = expr
	}

	// Parse the alias if the current and next tokens are "WS AS".
	alias, err := p.parseAlias()
	if err != nil {
		return nil, err
	}
	f.Alias = alias

	// Consume all trailing whitespace.
	p.consumeWhitespace()

	return f, nil
}
358033
func parseField(ctx *context, field *jsongo.JSONNode) (*Field, error) {
	if field.Len() < 2 || field.At(0).GetType() != jsongo.TypeValue || field.At(1).GetType() != jsongo.TypeValue {
		return nil, errors.New("invalid JSON for field specified")
	}

	fieldType, ok := field.At(0).Get().(string)
	if !ok {
		return nil, fmt.Errorf("field type is %T, not a string", field.At(0).Get())
	}
	fieldName, ok := field.At(1).Get().(string)
	if !ok {
		return nil, fmt.Errorf("field name is %T, not a string", field.At(1).Get())
	}
	var fieldLength float64
	if field.Len() >= 3 {
		fieldLength, ok = field.At(2).Get().(float64)
		if !ok {
			return nil, fmt.Errorf("field length is %T, not float64", field.At(2).Get())
		}
	}
	var fieldLengthFrom string
	if field.Len() >= 4 {
		fieldLengthFrom, ok = field.At(3).Get().(string)
		if !ok {
			return nil, fmt.Errorf("field length from is %T, not a string", field.At(3).Get())
		}
	}

	return &Field{
		Name:     fieldName,
		Type:     fieldType,
		Length:   int(fieldLength),
		SizeFrom: fieldLengthFrom,
	}, nil
}
902185
func (s *SearchSource) DocvalueFields(docvalueFields ...string) *SearchSource {
	for _, f := range docvalueFields {
		s.docvalueFields = append(s.docvalueFields, DocvalueField{Field: f})
	}
	return s
}
1004394
func (mr *modelRef) fieldValue(name string) reflect.Value {
	return mr.elemValue().FieldByName(name)
}
654473
func parseArgumentDefs(parser *Parser) ([]*ast.InputValueDefinition, error) {
	inputValueDefinitions := []*ast.InputValueDefinition{}

	if !peek(parser, lexer.PAREN_L) {
		return inputValueDefinitions, nil
	}
	iInputValueDefinitions, err := reverse(parser,
		lexer.PAREN_L, parseInputValueDef, lexer.PAREN_R,
		true,
	)
	if err != nil {
		return inputValueDefinitions, err
	}
	for _, iInputValueDefinition := range iInputValueDefinitions {
		if iInputValueDefinition != nil {
			inputValueDefinitions = append(inputValueDefinitions, iInputValueDefinition.(*ast.InputValueDefinition))
		}
	}
	return inputValueDefinitions, err
}
861279
func (c Context) Dict(key string, dict *Event) Context {
	dict.buf = enc.AppendEndMarker(dict.buf)
	c.l.context = append(enc.AppendKey(c.l.context, key), dict.buf...)
	putEvent(dict)
	return c
}
538383
func (t *Thermometer) parseValue(val string) (*Value, error) {
	var v *Value
	start := strings.Index(val, "t=")
	if start == -1 {
		return v, errors.New("could not parse temp")
	}
	temperatureStr := val[start+2:]
	temperatureStr = strings.Trim(temperatureStr, "\n")
	temperature, err := strconv.ParseFloat(temperatureStr, 64)
	if err != nil {
		return v, err
	}
	value := temperature / 1000.0
	if t.units == "F" || t.units == "f" {
		value = value*1.8 + 32.0
	}
	return &Value{
		Value: value,
		Units: t.units,
	}, nil
}
87093
func (tokenizer *Tokenizer) parseNamespacedValue() string {
	start := tokenizer.scanner.Index()
	tokenizer.scanner.Advance()
	for tokenizer.CanRead() {
		if tokenizer.isNamespacedChar() {
			tokenizer.scanner.Advance()
			continue
		} else {
			break
		}
	}
	return tokenizer.scanner.SubstringFrom(start)
}
433723
func GetField(obj interface{}, name string) (interface{}, error) {
	val := reflect.Indirect(reflect.ValueOf(obj))
	return val.FieldByName(name).Interface(), nil
}
1354603
func getValueFromFields(value reflect.Value, fieldNames []string) (results []interface{}) {
	// If value is a nil pointer, Indirect returns a zero Value!
	// Therefor we need to check for a zero value,
	// as FieldByName could panic
	if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
		for _, fieldName := range fieldNames {
			if fieldValue := reflect.Indirect(indirectValue.FieldByName(fieldName)); fieldValue.IsValid() {
				result := fieldValue.Interface()
				if r, ok := result.(driver.Valuer); ok {
					result, _ = r.Value()
				}
				results = append(results, result)
			}
		}
	}
	return
}
353291
func parse(str string, index int) *Pair {
	var key, value string
	if index > 0 {
		key, value = str[:index], str[index+1:]
	} else if index == 0 {
		key, value = "", str[1:]
	} else if index < 0 {
		key, value = str, ""
	}

	return &Pair{Key: key, Value: value}
}
300458
func (p *Parser) parseValues() (sets.String, error) {
	tok, lit := p.consume(Values)
	if tok != OpenParToken {
		return nil, fmt.Errorf("found '%s' expected: '('", lit)
	}
	tok, lit = p.lookahead(Values)
	switch tok {
	case IdentifierToken, CommaToken:
		s, err := p.parseIdentifiersList() // handles general cases
		if err != nil {
			return s, err
		}
		if tok, _ = p.consume(Values); tok != ClosedParToken {
			return nil, fmt.Errorf("found '%s', expected: ')'", lit)
		}
		return s, nil
	case ClosedParToken: // handles "()"
		p.consume(Values)
		return sets.NewString(""), nil
	default:
		return nil, fmt.Errorf("found '%s', expected: ',', ')' or identifier", lit)
	}
}
607872
func getValue(m map[string]interface{}, keys []string) string {
	node := m[keys[0]]

	for i := 1; i < len(keys); i++ {
		key := keys[i]

		sliceNode, ok := node.([]interface{})
		if ok {
			intKey, err := strconv.Atoi(key)
			if err != nil {
				panic(fmt.Sprintf(
					"Cannot access nested slice element with non-integer key: %s",
					key))
			}
			node = sliceNode[intKey]
			continue
		}

		mapNode, ok := node.(map[string]interface{})
		if ok {
			node = mapNode[key]
			continue
		}

		panic(fmt.Sprintf(
			"Cannot descend into non-map non-slice object with key: %s", key))
	}

	if node == nil {
		return ""
	}

	return fmt.Sprintf("%v", node)
}