// Parse performs Graphite parsing of a single line.
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)
}
799769
func Parse(r io.Reader) (*Program, error) {
	program := &Program{}
	err := basicParser.Parse(r, program)
	if err != nil {
		return nil, err
	}
	program.init()
	return program, nil
}
1167653
func (p *Parser) Parse() error {
	for {
		t, err := p.decoder.Token()
		if err == io.EOF {
			break
		} else if serr, ok := err.(*json.SyntaxError); ok {
			return WithStack(&ParseError{msg: err.Error(), Offset: serr.Offset})
		} else if err != nil {
			return WithStack(&ParseError{msg: err.Error()})
		}
		switch x := t.(type) {
		case nil:
			if err := p.builder.AddValue(NewNullValue()); err != nil {
				return WithStack(err)
			}
		case bool:
			if err := p.builder.AddValue(NewBoolValue(x)); err != nil {
				return WithStack(err)
			}
		case json.Number:
			if xu, err := strconv.ParseUint(string(x), 10, 64); err == nil {
				if err := p.builder.AddValue(NewUIntValue(xu)); err != nil {
					return WithStack(err)
				}
			} else if xi, err := x.Int64(); err == nil {
				if err := p.builder.AddValue(NewIntValue(xi)); err != nil {
					return WithStack(err)
				}
			} else {
				if xf, err := x.Float64(); err == nil {
					if err := p.builder.AddValue(NewDoubleValue(xf)); err != nil {
						return WithStack(err)
					}
				} else {
					return WithStack(&ParseError{msg: err.Error()})
				}
			}
		case string:
			if err := p.builder.AddValue(NewStringValue(x)); err != nil {
				return WithStack(err)
			}
		case json.Delim:
			switch x {
			case '[':
				if err := p.builder.OpenArray(p.options.BuildUnindexedArrays); err != nil {
					return WithStack(err)
				}
			case '{':
				if err := p.builder.OpenObject(p.options.BuildUnindexedObjects); err != nil {
					return WithStack(err)
				}
			case ']', '}':
				if err := p.builder.Close(); err != nil {
					return WithStack(err)
				}
			}
		}
	}
	return nil
}
215070
func (p *parser) Parse(r io.Reader) (err error) {
	cr := newChecksumReader(r)

	if err = readMagicString(cr); err != nil {
		return err
	}

	var rdbVersion int
	if rdbVersion, err = readVersionNumber(cr); err != nil {
		return err
	}

	for {
		if err = p.readDatabase(cr); err != nil && err != errNoMoreDatabases {
			return err
		} else if err != nil && err == errNoMoreDatabases {
			break
		}

		for {
			if err = p.readKeyValuePair(cr); err != nil && err != errNoMoreKeyValuePair {
				return err
			} else if err != nil && err == errNoMoreKeyValuePair {
				break
			}
		}

		if p.scratch[0] == 0xFF {
			break
		}
	}

	// Read the CRC64 checksum with RDB version >= 5
	if rdbVersion >= 5 {
		sum := cr.checksum

		var checksum uint64
		if err := binary.Read(cr, binary.LittleEndian, &checksum); err != nil {
			return err
		}

		if sum != checksum {
			return ErrInvalidChecksum
		}
	}

	p.ctx.closeChannels()

	return nil
}
1267327
func (c *Compiler) Parse(input string) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = errors.New(r.(string))
		}
	}()

	parser, err := parser.StringParser(input)
    parser.FileName(c.filename)

	if err != nil {
		return
	}

	c.node = parser.Parse()
	return
}
1336764
func (c Config) Parse(s string) error {
	c.file = "<string>"
	c.input = s
	return c.parse()
}
683891
func parse(expr string) node {
	r := &scanner{text: expr}
	r.nextChar()
	r.nextItem()
	p := &parser{r: r}
	return p.parseExpression(nil)
}
1201755
func (d *DateString) Parse(value string) (time.Time, error) {
	return time.Parse(d.Layout, value)
}
891109
func (s *FileSource) Parse() (tree.RawPolicy, error) {
	file, err := ioutil.ReadFile(s.Filename)
	if err != nil {
		return tree.RawPolicy{}, err
	}
	return parseLines(s.Filename, strings.Split(string(file), "\n"))
}
777377
func (t *ParseTree) Parse(p *Parser) (Statement, error) {
	for {
		tok, pos, lit := p.ScanIgnoreWhitespace()
		if subtree := t.Tokens[tok]; subtree != nil {
			t = subtree
			continue
		}

		if stmt := t.Handlers[tok]; stmt != nil {
			return stmt(p)
		}

		// There were no registered handlers. Return the valid tokens in the order they were added.
		return nil, newParseError(tokstr(tok, lit), t.Keys, pos)
	}
}
256911
func (f *Parser) Parse(feed io.Reader) (*Feed, error) {
	// Wrap the feed io.Reader in a io.TeeReader
	// so we can capture all the bytes read by the
	// DetectFeedType function and construct a new
	// reader with those bytes intact for when we
	// attempt to parse the feeds.
	var buf bytes.Buffer
	tee := io.TeeReader(feed, &buf)
	feedType := DetectFeedType(tee)

	// Glue the read bytes from the detect function
	// back into a new reader
	r := io.MultiReader(&buf, feed)

	switch feedType {
	case FeedTypeAtom:
		return f.parseAtomFeed(r)
	case FeedTypeRSS:
		return f.parseRSSFeed(r)
	}

	return nil, ErrFeedTypeNotDetected
}
943675
func (p *parser) Parse() []Pattern {
	// keep parsing until there's no more patterns
	_patterns := make([]Pattern, 0)
	for {
		_pattern := p.Next()
		if _pattern == nil {
			return _patterns
		}
		_patterns = append(_patterns, _pattern)
	}
}
371778
func (t *Tree) parse() (Node, error) {
	tok := t.nextNonSpace()
	switch tok.tokenType {
	case tokenText:
		return NewTextNode(tok.value, tok.Pos), nil

	case tokenPrintOpen:
		name, err := t.parseExpr()
		if err != nil {
			return nil, err
		}
		_, err = t.expect(tokenPrintClose)
		if err != nil {
			return nil, err
		}
		return NewPrintNode(name, tok.Pos), nil

	case tokenTagOpen:
		return t.parseTag()

	case tokenCommentOpen:
		tok, err := t.expect(tokenText)
		if err != nil {
			return nil, err
		}
		_, err = t.expect(tokenCommentClose)
		if err != nil {
			return nil, err
		}
		return NewCommentNode(tok.value, tok.Pos), nil

	case tokenEOF:
		// expected end of input
		return nil, nil
	}
	return nil, newUnexpectedTokenError(tok)
}
495912
func (s *State) Parse(args []string) error {
	pc := matcher.NewParseContext()
	ok := s.apply(args, pc)
	if !ok {
		return fmt.Errorf("incorrect usage")
	}

	if err := fillContainers(pc.Opts); err != nil {
		return err
	}

	return fillContainers(pc.Args)
}
996649
func (parser *Parser) Parse() error {
	err := parser.parse()
	if err != nil {
		return err
	}

	if len(parser.previous) > 0 {
		return parser.syntaxError("expected end of section, instead found EOF")
	}

	return nil
}
1005229
func (p *parser) parse(pf *ProtoFile) error {
	for {
		// read any documentation if found...
		documentation, err := p.readDocumentationIfFound()
		if err != nil {
			return err
		}
		if p.eofReached {
			break
		}

		// skip any intervening whitespace if present...
		p.skipWhitespace()
		if p.eofReached {
			break
		}

		// read any declaration...
		err = p.readDeclaration(pf, documentation, parseCtx{ctxType: fileCtx})
		if err != nil {
			return err
		}
		if p.eofReached {
			break
		}
	}
	return nil
}
763368
func (j *JSONPath) Parse(text string) error {
	var err error
	j.parser, err = Parse(j.name, text)
	return err
}