/*
ParseList validates the HTTP request and returns a resulting list of objects
parsed from the request Body. Use just like ParseObject.
*/
191417
func ParseList(r *http.Request) (List, *Error) {
	document, err := ParseDoc(r, ListMode)
	if err != nil {
		return nil, err
	}

	return document.Data, nil
}
982716
func parseListLine(line string, now time.Time, loc *time.Location) (*Entry, error) {
	for _, f := range listLineParsers {
		e, err := f(line, now, loc)
		if err != errUnsupportedListLine {
			return e, err
		}
	}
	return nil, errUnsupportedListLine
}
215081
func parseSelector(selector string) ([]byte, error) {
	// Define a tiny fake ABI struct for JSON marshalling
	type fakeArg struct {
		Type string `json:"type"`
	}
	type fakeABI struct {
		Name   string    `json:"name"`
		Type   string    `json:"type"`
		Inputs []fakeArg `json:"inputs"`
	}
	// Validate the selector and extract it's components
	groups := selectorRegexp.FindStringSubmatch(selector)
	if len(groups) != 3 {
		return nil, fmt.Errorf("invalid selector %s (%v matches)", selector, len(groups))
	}
	name := groups[1]
	args := groups[2]

	// Reassemble the fake ABI and constuct the JSON
	arguments := make([]fakeArg, 0)
	if len(args) > 0 {
		for _, arg := range strings.Split(args, ",") {
			arguments = append(arguments, fakeArg{arg})
		}
	}
	return json.Marshal([]fakeABI{{name, "function", arguments}})
}
405257
func ParseLevel(levelStr string) (Level, error) {
	switch levelStr {
	case LevelFieldMarshalFunc(DebugLevel):
		return DebugLevel, nil
	case LevelFieldMarshalFunc(InfoLevel):
		return InfoLevel, nil
	case LevelFieldMarshalFunc(WarnLevel):
		return WarnLevel, nil
	case LevelFieldMarshalFunc(ErrorLevel):
		return ErrorLevel, nil
	case LevelFieldMarshalFunc(FatalLevel):
		return FatalLevel, nil
	case LevelFieldMarshalFunc(PanicLevel):
		return PanicLevel, nil
	case LevelFieldMarshalFunc(NoLevel):
		return NoLevel, nil
	}
	return NoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr)
}
390408
func parseBody(resp *http.Response, o interface{}) error {
	err := json.NewDecoder(resp.Body).Decode(&o)
	if err != nil {
		resp.Body.Close()
		return err
	} else {
		return resp.Body.Close()
	}
}
453526
func (p *parser) parseRelationalExpr(n node) node {
	opnd := p.parseAdditiveExpr(n)
Loop:
	for {
		var op string
		switch p.r.typ {
		case itemLt:
			op = "<"
		case itemGt:
			op = ">"
		case itemLe:
			op = "<="
		case itemGe:
			op = ">="
		default:
			break Loop
		}
		p.next()
		opnd = newOperatorNode(op, opnd, p.parseAdditiveExpr(n))
	}
	return opnd
}
1293461
func (p *parser) parseLine(line string) error {
	switch line[0] {
	case 'B':
		return p.parseB(line)
	case 'H':
		return p.parseH(line)
	case 'I':
		return p.parseI(line)
	default:
		return nil
	}
}
914368
func ParseAssertionList(ctx AssertionContext, assertionsStr string) (res []AssertionExpression, err error) {
	expr, err := AssertionParse(ctx, assertionsStr)
	if err != nil {
		return res, err
	}
	return unpackAssertionList(expr)
}
921990
func (m *ArangoLineParser) ParseLine(line string) (_ map[string]interface{}, err error) {
	// Do the actual work here, we look for log lines in the log topic "requests",
	// there are two types, one is a DEBUG line (could be switched off) containing
	// the request body, the other is the INFO line marking the end of the
	// request.
	var v = make(map[string]interface{})
	err = errors.New("Line is not a request log line.")
	var abort bool
	var s string

	v[timestampFieldName], abort = firstWord(&line)
	if abort {
		return
	}

	s, abort = firstWord(&line)
	if abort {
		return
	}
	v[pidFieldName] = removeBrackets(s)

	v[logLevelFieldName], abort = firstWord(&line)
	if abort {
		return
	}

	s, abort = firstWord(&line)
	if abort {
		return
	}
	v[logTopicFieldName] = s

	if s != "{requests}" {
		return
	}

	var fields = strings.Split(line, ",")
	if v[logLevelFieldName] == "DEBUG" {
		if len(fields) != 6 {
			return
		}
		v[idFieldName] = removeQuotes(fields[1])
		v[sourceIPFieldName] = removeQuotes(fields[2])
		v[methodFieldName] = removeQuotes(fields[3])
		v[protocolFieldName] = removeQuotes(fields[4])
		v[fullURLFieldName] = removeQuotes(fields[5])
	} else {
		if len(fields) != 10 {
			return
		}
		v[idFieldName] = removeQuotes(fields[1])
		v[sourceIPFieldName] = removeQuotes(fields[2])
		v[methodFieldName] = removeQuotes(fields[3])
		v[protocolFieldName] = removeQuotes(fields[4])
		v[resCodeFieldName], _ = strconv.ParseInt(fields[5], 10, 32)
		v[reqBodyLenFieldName], _ = strconv.ParseInt(fields[6], 10, 64)
		v[resBodyLenFieldName], _ = strconv.ParseInt(fields[7], 10, 64)
		v[fullURLFieldName] = removeQuotes(fields[8])
		v[totalTimeFieldName], _ = strconv.ParseFloat(fields[9], 64)
	}
	return v, nil
}
1097016
func parseList(r reflect.Value, node *XMLNode, tag reflect.StructTag) error {
	t := r.Type()

	if tag.Get("flattened") == "" { // look at all item entries
		mname := "member"
		if name := tag.Get("locationNameList"); name != "" {
			mname = name
		}

		if Children, ok := node.Children[mname]; ok {
			if r.IsNil() {
				r.Set(reflect.MakeSlice(t, len(Children), len(Children)))
			}

			for i, c := range Children {
				err := parse(r.Index(i), c, "")
				if err != nil {
					return err
				}
			}
		}
	} else { // flattened list means this is a single element
		if r.IsNil() {
			r.Set(reflect.MakeSlice(t, 0, 0))
		}

		childR := reflect.Zero(t.Elem())
		r.Set(reflect.Append(r, childR))
		err := parse(r.Index(r.Len()-1), node, "")
		if err != nil {
			return err
		}
	}

	return nil
}
885331
func (r *httpJSONResponse) ParseBody(field string, result interface{}) error {
	if r.bodyObject == nil {
		bodyMap := make(map[string]*json.RawMessage)
		if err := json.Unmarshal(r.rawResponse, &bodyMap); err != nil {
			return driver.WithStack(err)
		}
		r.bodyObject = bodyMap
	}
	if result != nil {
		if err := parseBody(r.bodyObject, field, result); err != nil {
			return driver.WithStack(err)
		}
	}
	return nil
}
566691
func ParseLevel(lvl string) (Level, error) {
	switch strings.ToUpper(lvl) {
	case "EMERGENCY", "EMERG":
		return EmergLevel, nil
	case "ALERT":
		return AlertLevel, nil
	case "CRITICAL", "CRIT", "CRITI":
		return CritiLevel, nil
	case "ERROR", "ERR":
		return ErrLevel, nil
	case "WARNING", "WARN":
		return WarningLevel, nil
	case "NOTICE":
		return NoticeLevel, nil
	case "INFO":
		return InfoLevel, nil
	case "DEBUG":
		return DebugLevel, nil
	}

	var l Level
	return l, fmt.Errorf("not a valid gear logging Level: %q", lvl)
}
165649
func (p *Paginator) ParseLimit(req *restful.Request) int {
	limit := p.LimitDefault
	if p := req.QueryParameter(p.LimitName); p != "" {
		if val, err := strconv.Atoi(p); err == nil {
			limit = val
		}
	}
	if limit < 0 {
		limit = p.LimitDefault
	}
	if limit > p.LimitMax {
		limit = p.LimitMax
	}
	return limit
}
863479
func evaluateSelector(sel *ast.SelectorExpr, fields []string) ([]string, error) {
	fields = append([]string{sel.Sel.Name}, fields...)
	switch l := sel.X.(type) {
	case *ast.SelectorExpr:
		return evaluateSelector(l, fields)
	case *ast.Ident:
		fields = append([]string{l.Name}, fields...)
		return fields, nil
	default:
		return nil, trace.BadParameter("unsupported selector type: %T", l)
	}
}
416682
func parseList(parser *Parser, isConst bool) (*ast.ListValue, error) {
	start := parser.Token.Start
	var item parseFn = parseValueValue
	if isConst {
		item = parseConstValue
	}
	values := []ast.Value{}
	if iValues, err := reverse(parser,
		lexer.BRACKET_L, item, lexer.BRACKET_R,
		false,
	); err != nil {
		return nil, err
	} else {
		for _, iValue := range iValues {
			values = append(values, iValue.(ast.Value))
		}
	}
	return ast.NewListValue(&ast.ListValue{
		Values: values,
		Loc:    loc(parser, start),
	}), nil
}
109873
func (r *httpJSONResponseElement) ParseBody(field string, result interface{}) error {
	if result != nil {
		if err := parseBody(r.bodyObject, field, result); err != nil {
			return driver.WithStack(err)
		}
	}
	return nil
}
908853
func parseListing(t *thing) ([]*Comment, []*Post, []*Message, error) {
	if t.Kind != listingKind {
		return nil, nil, nil, fmt.Errorf("thing is not listing")
	}

	l := &listing{}
	if err := mapstructure.Decode(t.Data, l); err != nil {
		return nil, nil, nil, mapDecodeError(err, t.Data)
	}

	comments := []*Comment{}
	posts := []*Post{}
	msgs := []*Message{}
	err := error(nil)

	for _, c := range l.Children {
		if err != nil {
			break
		}

		var comment *Comment
		var post *Post
		var msg *Message

		// Reddit sets the "Kind" field of comments in the inbox, which
		// have only Message and not Comment fields, to commentKind. The
		// give away in this case is that comments in message form have
		// a field called "was_comment". Reddit does this because they
		// hate programmers.
		if c.Kind == messageKind || c.Data["was_comment"] != nil {
			msg, err = parseMessage(&c)
			msgs = append(msgs, msg)
		} else if c.Kind == commentKind {
			comment, err = parseComment(&c)
			comments = append(comments, comment)
		} else if c.Kind == postKind {
			post, err = parsePost(&c)
			posts = append(posts, post)
		}
	}

	return comments, posts, msgs, err
}