// parse parses data through an io.Reader.
341465
func (f *File) parse(reader io.Reader) (err error) {
	p := newParser(reader, parserOptions{
		IgnoreContinuation:          f.options.IgnoreContinuation,
		IgnoreInlineComment:         f.options.IgnoreInlineComment,
		AllowPythonMultilineValues:  f.options.AllowPythonMultilineValues,
		SpaceBeforeInlineComment:    f.options.SpaceBeforeInlineComment,
		UnescapeValueDoubleQuotes:   f.options.UnescapeValueDoubleQuotes,
		UnescapeValueCommentSymbols: f.options.UnescapeValueCommentSymbols,
		PreserveSurroundedQuote:     f.options.PreserveSurroundedQuote,
	})
	if err = p.BOM(); err != nil {
		return fmt.Errorf("BOM: %v", err)
	}

	// Ignore error because default section name is never empty string.
	name := DefaultSection
	if f.options.Insensitive {
		name = strings.ToLower(DefaultSection)
	}
	section, _ := f.NewSection(name)

	// This "last" is not strictly equivalent to "previous one" if current key is not the first nested key
	var isLastValueEmpty bool
	var lastRegularKey *Key

	var line []byte
	var inUnparseableSection bool

	// NOTE: Iterate and increase `currentPeekSize` until
	// the size of the parser buffer is found.
	// TODO(unknwon): When Golang 1.10 is the lowest version supported, replace with `parserBufferSize := p.buf.Size()`.
	parserBufferSize := 0
	// NOTE: Peek 1kb at a time.
	currentPeekSize := 1024

	if f.options.AllowPythonMultilineValues {
		for {
			peekBytes, _ := p.buf.Peek(currentPeekSize)
			peekBytesLength := len(peekBytes)

			if parserBufferSize >= peekBytesLength {
				break
			}

			currentPeekSize *= 2
			parserBufferSize = peekBytesLength
		}
	}

	for !p.isEOF {
		line, err = p.readUntil('\n')
		if err != nil {
			return err
		}

		if f.options.AllowNestedValues &&
			isLastValueEmpty && len(line) > 0 {
			if line[0] == ' ' || line[0] == '\t' {
				lastRegularKey.addNestedValue(string(bytes.TrimSpace(line)))
				continue
			}
		}

		line = bytes.TrimLeftFunc(line, unicode.IsSpace)
		if len(line) == 0 {
			continue
		}

		// Comments
		if line[0] == '#' || line[0] == ';' {
			// Note: we do not care ending line break,
			// it is needed for adding second line,
			// so just clean it once at the end when set to value.
			p.comment.Write(line)
			continue
		}

		// Section
		if line[0] == '[' {
			// Read to the next ']' (TODO: support quoted strings)
			closeIdx := bytes.LastIndexByte(line, ']')
			if closeIdx == -1 {
				return fmt.Errorf("unclosed section: %s", line)
			}

			name := string(line[1:closeIdx])
			section, err = f.NewSection(name)
			if err != nil {
				return err
			}

			comment, has := cleanComment(line[closeIdx+1:])
			if has {
				p.comment.Write(comment)
			}

			section.Comment = strings.TrimSpace(p.comment.String())

			// Reset aotu-counter and comments
			p.comment.Reset()
			p.count = 1

			inUnparseableSection = false
			for i := range f.options.UnparseableSections {
				if f.options.UnparseableSections[i] == name ||
					(f.options.Insensitive && strings.ToLower(f.options.UnparseableSections[i]) == strings.ToLower(name)) {
					inUnparseableSection = true
					continue
				}
			}
			continue
		}

		if inUnparseableSection {
			section.isRawSection = true
			section.rawBody += string(line)
			continue
		}

		kname, offset, err := readKeyName(f.options.KeyValueDelimiters, line)
		if err != nil {
			// Treat as boolean key when desired, and whole line is key name.
			if IsErrDelimiterNotFound(err) {
				switch {
				case f.options.AllowBooleanKeys:
					kname, err := p.readValue(line, parserBufferSize)
					if err != nil {
						return err
					}
					key, err := section.NewBooleanKey(kname)
					if err != nil {
						return err
					}
					key.Comment = strings.TrimSpace(p.comment.String())
					p.comment.Reset()
					continue

				case f.options.SkipUnrecognizableLines:
					continue
				}
			}
			return err
		}

		// Auto increment.
		isAutoIncr := false
		if kname == "-" {
			isAutoIncr = true
			kname = "#" + strconv.Itoa(p.count)
			p.count++
		}

		value, err := p.readValue(line[offset:], parserBufferSize)
		if err != nil {
			return err
		}
		isLastValueEmpty = len(value) == 0

		key, err := section.NewKey(kname, value)
		if err != nil {
			return err
		}
		key.isAutoIncrement = isAutoIncr
		key.Comment = strings.TrimSpace(p.comment.String())
		p.comment.Reset()
		lastRegularKey = key
	}
	return nil
}
735299
func Parse(md metadata.MD) interface{} {
	if parser == nil {
		return nil
	}
	return parser.Parse(md)
}
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
}
386139
func Parse(r io.Reader) (*Profile, error) {
	orig, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}

	var p *Profile
	if len(orig) >= 2 && orig[0] == 0x1f && orig[1] == 0x8b {
		gz, err := gzip.NewReader(bytes.NewBuffer(orig))
		if err != nil {
			return nil, fmt.Errorf("decompressing profile: %v", err)
		}
		data, err := ioutil.ReadAll(gz)
		if err != nil {
			return nil, fmt.Errorf("decompressing profile: %v", err)
		}
		orig = data
	}
	if p, err = parseUncompressed(orig); err != nil {
		if p, err = parseLegacy(orig); err != nil {
			return nil, fmt.Errorf("parsing profile: %v", err)
		}
	}

	if err := p.CheckValid(); err != nil {
		return nil, fmt.Errorf("malformed profile: %v", err)
	}
	return p, nil
}
1240321
func Parse(buf string) (*Tree, error) {
	t := new(Tree)
	t.scanner = new(scanner)
	return t.Parse(buf)
}
106997
func (parser *myParser) Parse(s string) error {
	typ := reflect.TypeOf(parser.ptr)
	val := reflect.ValueOf(parser.ptr)
	if typ.Kind() == reflect.Ptr {
		kind := reflect.Indirect(val).Type().Kind()
		if kind == reflect.Struct {
			typElem, valElem := typ.Elem(), val.Elem()
			numField := valElem.NumField()
			for i := 0; i < numField; i++ {
				_, valField := typElem.Field(i), valElem.Field(i)
				if valField.Kind() == reflect.Int &&
					valField.CanSet() {
					valField.SetInt(2)
				}
				if valField.Kind() == reflect.String &&
					valField.CanSet() {
					valField.SetString("B")
				}
			}
		}
	}
	return nil
}
259640
func (ini *INI) Parse(data []byte, lineSep, kvSep string) error {
    return ini.parseINI(data, lineSep, kvSep)
}
1312817
func (p *Parser) Parse() (*ast.File, error) {
	f := &ast.File{}
	var err, scerr error
	p.sc.Error = func(pos token.Pos, msg string) {
		scerr = fmt.Errorf("%s: %s", pos, msg)
	}

	// The root must be an object in JSON
	object, err := p.object()
	if scerr != nil {
		return nil, scerr
	}
	if err != nil {
		return nil, err
	}

	// We make our final node an object list so it is more HCL compatible
	f.Node = object.List

	// Flatten it, which finds patterns and turns them into more HCL-like
	// AST trees.
	flattenObjects(f.Node)

	return f, nil
}
603990
func (p IntParser) Parse(field string) (result interface{}, err error) {
	return strconv.ParseInt(field, 10, 64)
}
202666
func Parse(r io.Reader) (*api.Job, error) {
	// Copy the reader into an in-memory buffer first since HCL requires it.
	var buf bytes.Buffer
	if _, err := io.Copy(&buf, r); err != nil {
		return nil, err
	}

	// Parse the buffer
	root, err := hcl.Parse(buf.String())
	if err != nil {
		return nil, fmt.Errorf("error parsing: %s", err)
	}
	buf.Reset()

	// Top-level item should be a list
	list, ok := root.Node.(*ast.ObjectList)
	if !ok {
		return nil, fmt.Errorf("error parsing: root should be an object")
	}

	// Check for invalid keys
	valid := []string{
		"job",
	}
	if err := helper.CheckHCLKeys(list, valid); err != nil {
		return nil, err
	}

	var job api.Job

	// Parse the job out
	matches := list.Filter("job")
	if len(matches.Items) == 0 {
		return nil, fmt.Errorf("'job' stanza not found")
	}
	if err := parseJob(&job, matches); err != nil {
		return nil, fmt.Errorf("error parsing 'job': %s", err)
	}

	return &job, nil
}
763368
func (j *JSONPath) Parse(text string) error {
	var err error
	j.parser, err = Parse(j.name, text)
	return err
}
1155841
func Parse(reader io.ReadSeeker, c *Chunk, tiFlag bool) (Element, error) {
	var token [1]byte
	var err error
	read, err := reader.Read(token[:])
	if read != 1 || err != nil {
		return EmptyElement{}, err
	}
	_, err = reader.Seek(-1, os.SEEK_CUR)
	if err != nil {
		return EmptyElement{}, err
	}
	switch token[0] {
	case FragmentHeaderToken:
		f := Fragment{}
		err = f.Parse(reader)
		checkFullParsingError(err, reader, &f, c)
		f.BinXMLElement, err = Parse(reader, c, tiFlag)
		checkFullParsingError(err, reader, &f, c)
		if err != nil {
			return &f, err
		}
		// We hack a bit over here creating a fake TemplateInstance to benefit from
		// the further GoEvtxMap convertion of it. Conceptually it makes sense since
		// we just create a template without substitutions.
		if _, ok := f.BinXMLElement.(*ElementStart); ok {
			var e Element
			var ti TemplateInstance
			ti.Definition.Data.Elements = make([]Element, 0)

			ti.Definition.Data.Elements = append(ti.Definition.Data.Elements, f.BinXMLElement.(*ElementStart))
			for e, err = Parse(reader, c, tiFlag); err == nil; e, err = Parse(reader, c, tiFlag) {
				ti.Definition.Data.Elements = append(ti.Definition.Data.Elements, e)
				if _, ok := e.(*BinXMLEOF); ok {
					break
				}
			}
			checkFullParsingError(err, reader, e, c)
			f.BinXMLElement = &ti
		}
		return &f, err
	case TokenOpenStartElementTag1, TokenOpenStartElementTag2:
		es := ElementStart{IsTemplateInstance: tiFlag}
		err = es.Parse(reader)
		checkFullParsingError(err, reader, &es, c)
		return &es, err
	case TokenNormalSubstitution:
		ns := NormalSubstitution{}
		err = ns.Parse(reader)
		checkParsingError(err, reader, &ns)
		return &ns, err
	case TokenOptionalSubstitution:
		os := OptionalSubstitution{}
		err = os.Parse(reader)
		checkParsingError(err, reader, &os)
		return &os, err
	case TokenCharRef1:
		tcr := CharEntityRef{}
		err = tcr.Parse(reader)
		checkParsingError(err, reader, &tcr)
		return &tcr, err
	case TokenTemplateInstance:
		var offset int32
		ti := TemplateInstance{}
		if c != nil {
			// Check if template already parsed
			offset, err = ti.DataOffset(reader)
			if err != nil {
				return nil, err
			}
			if t, ok := c.TemplateTable[offset]; ok {
				// We have now to fix the offset to continue to read
				err = ti.ParseTemplateDefinitionHeader(reader)
				if err != nil {
					return nil, err
				}
				// Only the definition is valid, not the data
				ti.Definition.Data = t
				// We jump over the template definition data if needed
				if int64(offset) == BackupSeeker(reader) {
					// We patch offset to jump off to arrive after definition data size
					RelGoToSeeker(reader, int64(ti.Definition.Data.Size)+24)
				}
				// We parse the data
				err = ti.Data.Parse(reader)
				if err != nil {
					return nil, err
				}
				return &ti, nil
			}
		}
		// We have to parse the template since it cannot be found the template table
		err = ti.Parse(reader)
		if c != nil {
			// Update template table
			c.TemplateTable[ti.Definition.Header.DataOffset] = ti.Definition.Data
		}
		checkParsingError(err, reader, &ti)
		return &ti, err
	case TokenValue1, TokenValue2:
		// ValueText
		vt := ValueText{}
		err = vt.Parse(reader)
		checkParsingError(err, reader, &vt)
		return &vt, err

	case TokenEntityRef1, TokenEntityRef2:
		e := BinXMLEntityReference{}
		err = e.Parse(reader)
		checkParsingError(err, reader, &e)
		return &e, err

	case TokenEndElementTag:
		b := BinXMLEndElementTag{}
		err = b.Parse(reader)
		checkParsingError(err, reader, &b)
		return &b, err
	case TokenCloseStartElementTag:
		t := BinXMLCloseStartElementTag{}
		err = t.Parse(reader)
		checkParsingError(err, reader, &t)
		return &t, err
	case TokenCloseEmptyElementTag:
		t := BinXMLCloseEmptyElementTag{}
		err = t.Parse(reader)
		checkParsingError(err, reader, &t)
		return &t, err
	case TokenEOF:
		b := BinXMLEOF{}
		err = b.Parse(reader)
		checkParsingError(err, reader, &b)
		return &b, nil
	}
	//log.DontPanic(ErrUnknownToken{token[0]})
	log.DebugDontPanic(ErrUnknownToken{token[0]})
	return EmptyElement{}, ErrUnknownToken{token[0]}
}
979397
func (c *ChatPostMessageCall) Parse(parse string) *ChatPostMessageCall {
	c.parse = parse
	return c
}
871432
func Parse(qStr string) (Q, error) {
	b := []byte(qStr)

	qs, _, err := parseExprList(b)
	if err != nil {
		return nil, err
	}

	q, err := parseOperators(qs)
	if err != nil {
		return nil, err
	}

	return Simplify(q), nil
}
641761
func (n *Name) Parse(reader io.ReadSeeker) error {
	err := encoding.Unmarshal(reader, &n.OffsetPrevString, Endianness)
	if err != nil {
		return err
	}
	err = encoding.Unmarshal(reader, &n.Hash, Endianness)
	if err != nil {
		return err
	}
	err = encoding.Unmarshal(reader, &n.Size, Endianness)
	if err != nil {
		return err
	}

	// No need to control size since it is uint16
	n.UTF16String = make([]uint16, n.Size+1)

	err = encoding.UnmarshaInitSlice(reader, &n.UTF16String, Endianness)
	return err
}
212694
func Parse(s string) (map[string]interface{}, error) {
	vals := map[string]interface{}{}
	scanner := bytes.NewBufferString(s)
	t := newParser(scanner, vals, false)
	err := t.parse()
	return vals, err
}
919223
func (p *binParser) parse() *Graph {

	if p == nil || !p.header() {
		return nil
	}

	ev := &SimpleEventHandler{}

	for {
		lev, bin, b := p.line(true)
		if lev == 0 {
			break
		}
		// Store the content in the same format as it was sent (string or []byte)
		if bin {
			ev.AddBytesAt(b, lev-1)
		} else {
			ev.AddAt(string(b), lev-1)
		}
	}
	return ev.Tree()
}