// parseLit parses literal values (the leaves of the tree).
422257
func (m *GenericParser) parseLit(val reflect.Value) (Object, error) {
	switch k := val.Kind(); k {
	case reflect.Bool:
		return B(val.Bool()), nil
	case reflect.Int:
		return I(val.Int()), nil
	case reflect.Int8:
		return I8(val.Int()), nil
	case reflect.Int16:
		return I16(val.Int()), nil
	case reflect.Int32:
		return I32(val.Int()), nil
	case reflect.Int64:
		return I64(val.Int()), nil
	case reflect.Uint:
		return U(val.Uint()), nil
	case reflect.Uint8:
		return U8(val.Uint()), nil
	case reflect.Uint16:
		return U16(val.Uint()), nil
	case reflect.Uint32:
		return U32(val.Uint()), nil
	case reflect.Uint64:
		return U64(val.Uint()), nil
	case reflect.Float32:
		return F32(val.Float()), nil
	case reflect.Float64:
		return F64(val.Float()), nil
	case reflect.Complex64:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("unsupported kind of literal Complex64")
	case reflect.Complex128:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("unsupported kind of literal Complex128")
	case reflect.Array, reflect.Slice:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.New("nested slices/arrays of literals are not supported - parseLit should not be called with these kinds of values")
	case reflect.String:
		return S(val.String()), nil
	default:
		m.Stats.Count("parser.parseLit."+k.String(), 1, 1)
		return nil, errors.Errorf("kind %v is not supported", val.Kind())
	}
}
127572
func Parse(text string) (t *Tree, err error) {
	t = New()
	t.Text = text
	err = t.Parse(text)
	return
}
1113988
func parseSet(t *Tree, start Pos) (Node, error) {
	tok, err := t.expect(tokenName)
	if err != nil {
		return nil, err
	}
	_, err = t.expectValue(tokenPunctuation, "=")
	if err != nil {
		return nil, err
	}
	expr, err := t.parseExpr()
	if err != nil {
		return nil, err
	}
	_, err = t.expect(tokenTagClose)
	if err != nil {
		return nil, err
	}
	return NewSetNode(tok.value, expr, start), nil
}
1240321
func Parse(buf string) (*Tree, error) {
	t := new(Tree)
	t.scanner = new(scanner)
	return t.Parse(buf)
}
968973
func ParseLevel(level string) (Level, error) {
	level = strings.ToLower(level)
	for _, l := range levels {
		if strings.ToLower(l.String()) == level {
			return l, nil
		}
	}
	return Level(0), fmt.Errorf("unrecognized log level: %s", level)
}
1219190
func (self *Tree) Leaves() []Node {
	if self.Levels == nil {
		return nil
	} else {
		return self.Levels[len(self.Levels)-1]
	}
}
708483
func ParseLevel(level string) (Level, error) {
	switch strings.ToUpper(level) {
	case "MAY":
		fallthrough
	case "OPTIONAL":
		return May, nil
	case "SHOULD":
		fallthrough
	case "SHOULDNOT":
		fallthrough
	case "RECOMMENDED":
		fallthrough
	case "NOTRECOMMENDED":
		return Should, nil
	case "MUST":
		fallthrough
	case "MUSTNOT":
		fallthrough
	case "SHALL":
		fallthrough
	case "SHALLNOT":
		fallthrough
	case "REQUIRED":
		return Must, nil
	}

	var l Level
	return l, fmt.Errorf("%q is not a valid compliance level", level)
}
708
func (t *StringTree) Init(flags byte) *StringTree {
	t.Tree.Init(stringCompare, flags)
	return t
}
1088250
func (c *Client) LInsert(key string, where string, pivot interface{}, value interface{}) (int64, error) {
	var ret int64

	where = strings.ToUpper(where)

	if where != "AFTER" && where != "BEFORE" {
		return 0, errors.New(`The "where" value must be either BEFORE or AFTER.`)
	}

	err := c.command(
		&ret,
		[]byte("LINSERT"),
		[]byte(key),
		[]byte(where),
		to.Bytes(pivot),
		to.Bytes(value),
	)

	return ret, err
}
225797
func (p *Parser) ParseLine(s string) (telegraf.Metric, error) {
	metrics, err := p.Parse([]byte(s))
	if err != nil {
		return nil, err
	}

	if len(metrics) < 1 {
		return nil, ErrNoMetric
	}
	return metrics[0], nil
}
26444
func cmdSetTreeCharset(ctx *cli.Context, config utils.ConfigReader) {
	if ctx.Bool("ascii") {
		treeCharset = treeASCII
	} else if !utils.Isatty(os.Stdout) {
		treeCharset = treeSPACE
	} else if config.BoolVal("TREE_ASCII", false) {
		treeCharset = treeASCII
	}
}
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
}
84472
func (p *parser) parseList() Expr {
	lbrack := p.nextToken()
	if p.tok == RBRACK {
		// empty List
		rbrack := p.nextToken()
		return &ListExpr{Lbrack: lbrack, Rbrack: rbrack}
	}

	x := p.parseTest()

	if p.tok == FOR {
		// list comprehension
		return p.parseComprehensionSuffix(lbrack, x, RBRACK)
	}

	exprs := []Expr{x}
	if p.tok == COMMA {
		// multi-item list literal
		exprs = p.parseExprs(exprs, true) // allow trailing comma
	}

	rbrack := p.consume(RBRACK)
	return &ListExpr{Lbrack: lbrack, List: exprs, Rbrack: rbrack}
}
85133
func ParseLabelSpec(spec string) (map[string]string, error) {
	tokens := []string{}
	var openQuotes = false
	var tokenStart, assignCount int
	var specLen = len(spec)
	// tokenize the label spec:
	for i, ch := range spec {
		endOfToken := false
		// end of line?
		if i+utf8.RuneLen(ch) == specLen {
			i += utf8.RuneLen(ch)
			endOfToken = true
		}
		switch ch {
		case '"':
			openQuotes = !openQuotes
		case '=', ',', ';':
			if !openQuotes {
				endOfToken = true
				if ch == '=' {
					assignCount++
				}
			}
		}
		if endOfToken && i > tokenStart {
			tokens = append(tokens, strings.TrimSpace(strings.Trim(spec[tokenStart:i], `"`)))
			tokenStart = i + 1
		}
	}
	// simple validation of tokenization: must have an even number of tokens (because they're pairs)
	// and the number of such pairs must be equal the number of assignments
	if len(tokens)%2 != 0 || assignCount != len(tokens)/2 {
		return nil, fmt.Errorf("invalid label spec: '%s', should be 'key=value'", spec)
	}
	// break tokens in pairs and put into a map:
	labels := make(map[string]string)
	for i := 0; i < len(tokens); i += 2 {
		labels[tokens[i]] = tokens[i+1]
	}
	return labels, nil
}
1015304
func (t *tree) parseQuotedExpr(str string) ast.Node {
	var tt = &tree{lex: lexExpr("", str)}
	defer tt.lex.drain()
	return tt.parseExpr(0)
}
602226
func ParseLineRegexes(regexStrs []string) ([]*regexp.Regexp, error) {
	regexes := make([]*regexp.Regexp, 0)
	for _, regexStr := range regexStrs {
		regex, err := ParseLineRegex(regexStr)
		if err != nil {
			return regexes, err
		}
		regexes = append(regexes, regex)
	}
	return regexes, nil
}
497031
func (p *GraphiteParser) ParseLine(line string) (telegraf.Metric, error) {
	// Break into 3 fields (name, value, timestamp).
	fields := strings.Fields(line)
	if len(fields) != 2 && len(fields) != 3 {
		return nil, fmt.Errorf("received %q which doesn't have required fields", line)
	}

	// decode the name and tags
	measurement, tags, field, err := p.templateEngine.Apply(fields[0])
	if err != nil {
		return nil, err
	}

	// Could not extract measurement, use the raw value
	if measurement == "" {
		measurement = fields[0]
	}

	// Parse value.
	v, err := strconv.ParseFloat(fields[1], 64)
	if err != nil {
		return nil, fmt.Errorf(`field "%s" value: %s`, fields[0], err)
	}

	if math.IsNaN(v) || math.IsInf(v, 0) {
		return nil, &UnsupposedValueError{Field: fields[0], Value: v}
	}

	fieldValues := map[string]interface{}{}
	if field != "" {
		fieldValues[field] = v
	} else {
		fieldValues["value"] = v
	}

	// If no 3rd field, use now as timestamp
	timestamp := time.Now().UTC()

	if len(fields) == 3 {
		// Parse timestamp.
		unixTime, err := strconv.ParseFloat(fields[2], 64)
		if err != nil {
			return nil, fmt.Errorf(`field "%s" time: %s`, fields[0], err)
		}

		// -1 is a special value that gets converted to current UTC time
		// See https://github.com/graphite-project/carbon/issues/54
		if unixTime != float64(-1) {
			// Check if we have fractional seconds
			timestamp = time.Unix(int64(unixTime), int64((unixTime-math.Floor(unixTime))*float64(time.Second)))
			if timestamp.Before(MinDate) || timestamp.After(MaxDate) {
				return nil, fmt.Errorf("timestamp out of range")
			}
		}
	}
	// Set the default tags on the point if they are not already set
	for k, v := range p.DefaultTags {
		if _, ok := tags[k]; !ok {
			tags[k] = v
		}
	}

	return metric.New(measurement, tags, fieldValues, timestamp)
}