//
// Parse the productions:
// flow_sequence_entry  ::= flow_node | KEY flow_node? (VALUE flow_node?)?
//                                      *** *
//
15492
func yaml_parser_parse_flow_sequence_entry_mapping_key(parser *yaml_parser_t, event *yaml_event_t) bool {
	token := peek_token(parser)
	if token == nil {
		return false
	}
	if token.typ != yaml_VALUE_TOKEN &&
		token.typ != yaml_FLOW_ENTRY_TOKEN &&
		token.typ != yaml_FLOW_SEQUENCE_END_TOKEN {
		parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE)
		return yaml_parser_parse_node(parser, event, false, false)
	}
	mark := token.end_mark
	skip_token(parser)
	parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
	return yaml_parser_process_empty_scalar(parser, event, mark)
}
817095
func (p *Parser) Parse() error {
	if p == nil {
		return errors.New("can't calculate the wav duration of a nil pointer")
	}

	if p.Size == 0 {
		id, size, err := p.IDnSize()
		if err != nil {
			return err
		}
		p.ID = id
		if p.ID != RiffID {
			return fmt.Errorf("%s - %s", p.ID, ErrFmtNotSupported)
		}
		p.Size = size
		if err := binary.Read(p.r, binary.BigEndian, &p.Format); err != nil {
			return err
		}
	}

	var chunk *Chunk
	var err error
	for err == nil {
		chunk, err = p.NextChunk()
		if err != nil {
			break
		}

		if chunk.ID == FmtID {
			chunk.DecodeWavHeader(p)
		} else {
			if p.Chan != nil {
				if chunk.Wg == nil {
					chunk.Wg = p.Wg
				}
				chunk.Wg.Add(1)
				p.Chan <- chunk
				// the channel has to release otherwise the goroutine is locked
				chunk.Wg.Wait()
			}
		}

		// BFW: bext chunk described here
		// https://tech.ebu.ch/docs/tech/tech3285.pdf

		if !chunk.IsFullyRead() {
			chunk.Drain()
		}

	}
	if p.Wg != nil {
		p.Wg.Wait()
	}

	if p.Chan != nil {
		close(p.Chan)
	}

	if err == io.EOF {
		return nil
	}
	return err
}
323427
func parseJSON(input []byte) (*logEntry, error) {
	var raw map[string]interface{}
	entry := &logEntry{}

	err := json.Unmarshal(input, &raw)
	if err != nil {
		return nil, err
	}

	// Parse hclog-specific objects
	if v, ok := raw["@message"]; ok {
		entry.Message = v.(string)
		delete(raw, "@message")
	}

	if v, ok := raw["@level"]; ok {
		entry.Level = v.(string)
		delete(raw, "@level")
	}

	if v, ok := raw["@timestamp"]; ok {
		t, err := time.Parse("2006-01-02T15:04:05.000000Z07:00", v.(string))
		if err != nil {
			return nil, err
		}
		entry.Timestamp = t
		delete(raw, "@timestamp")
	}

	// Parse dynamic KV args from the hclog payload.
	for k, v := range raw {
		entry.KVPairs = append(entry.KVPairs, &logEntryKV{
			Key:   k,
			Value: v,
		})
	}

	return entry, nil
}
804295
func yaml_parser_fetch_flow_scalar(parser *yaml_parser_t, single bool) bool {
	// A plain scalar could be a simple key.
	if !yaml_parser_save_simple_key(parser) {
		return false
	}

	// A simple key cannot follow a flow scalar.
	parser.simple_key_allowed = false

	// Create the SCALAR token and append it to the queue.
	var token yaml_token_t
	if !yaml_parser_scan_flow_scalar(parser, &token, single) {
		return false
	}
	yaml_insert_token(parser, -1, &token)
	return true
}
493036
func (t *tree) parse(n *classNode) {
	foundClass := false
	for {
		token := t.next()
		switch token.typ {
		case itemWord:
			if token.val == "class" {
				if foundClass {
					t.unexpected(token, "input")
				}
				foundClass = true
				t.parseClass(n)
				t.expect(itemSemi, "input")
			}
		case itemEOF:
			if foundClass {
				return
			}
			t.unexpected(token, "input")
		default:
			// ignore
		}
	}
}
1099630
func (p *GtidLogEventParser) Parse(raw *RawV4Event) (Event, error) {
	gle := &GtidLogEvent{
		Event: raw,
	}

	if len(raw.VariableLengthData()) > 0 {
		return raw, errors.New("GTID binlog event larger than expected size")
	}

	data := raw.FixedLengthData()

	var commitData uint8
	data, err := readLittleEndian(data, &commitData)
	if err != nil {
		return raw, errors.Wrap(err, "Failed to read commit flag")
	}
	if commitData == 0 {
		gle.commit = false
	} else if commitData == 1 {
		gle.commit = true
	} else {
		return raw, errors.Newf("Commit data is not 0 or 1: %d", commitData)
	}

	data, err = readLittleEndian(data, &gle.sid)
	if err != nil {
		return raw, errors.Wrap(err, "Failed to read sid")
	}

	data, err = readLittleEndian(data, &gle.gno)
	if err != nil {
		return raw, errors.Wrap(err, "Failed to read GNO")
	}

	return gle, nil
}
682065
func (p StringParser) Parse(field string) (result interface{}, err error) {
	return field, nil
}
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)
}
1102249
func (s *HTTPServer) parse(resp http.ResponseWriter, req *http.Request, r *string, b *structs.QueryOptions) bool {
	s.parseRegion(req, r)
	s.parseToken(req, &b.AuthToken)
	parseConsistency(req, b)
	parsePrefix(req, b)
	parseNamespace(req, &b.Namespace)
	return parseWait(resp, req, b)
}
952492
func (p *Parser) Parse() (*parser.Node, error) {
	sdata := string(p.data)
	rn := parser.Node{P: p, Name: p.l.ScopeName}
	defer rn.UpdateRange()
	defer func() {
		if r := recover(); r != nil {
			log.Error("Panic during parse: %v\n", r)
			log.Debug("%v", rn)
		}
	}()
	iter := maxiter
	for i := 0; i < len(sdata) && iter > 0; iter-- {
		pat, ret := p.l.RootPattern.Cache(sdata, i)
		if ret == nil {
			break
		}
		nl := strings.IndexAny(sdata[i:], "\n\r")
		// if the match object is not in this line we will move the
		// position to beginning of the next line then we will look for
		// a match again
		if nl += i; nl != i-1 && nl <= ret[0] {
			i = nl
			for i < len(sdata) && (sdata[i] == '\n' || sdata[i] == '\r') {
				i++
			}
			continue
		}
		n := pat.CreateNode(sdata, i, p, ret)
		rn.Append(n)
		i = n.Range.B
	}
	// handling unicode characters different length
	if len(sdata) != 0 {
		lut := make([]int, len(sdata)+1)
		j := 0
		for i := range sdata {
			lut[i] = j
			j++
		}
		lut[len(sdata)] = len(p.data)
		p.patch(lut, &rn)
	}
	if iter == 0 {
		panic("reached maximum number of iterations")
	}
	return &rn, nil
}
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
}
921887
func (p *Parser) parseKey() (string, error) {
	tok, literal := p.consume()
	if tok != IdentifierToken {
		err := fmt.Errorf("found '%s', expected: identifier", literal)
		return "", err
	}
	if err := validateLabelKey(literal); err != nil {
		return "", err
	}
	return literal, nil
}
359511
func (p *parser) parseSequence(n node) (opnd node) {
	p.skipItem(itemLParens)
	opnd = p.parseStep(n)
	for {
		if p.r.typ != itemComma {
			break
		}
		p.next()
		opnd2 := p.parseStep(n)
		opnd = newOperatorNode("|", opnd, opnd2)
	}
	p.skipItem(itemRParens)
	return opnd
}
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()
}
1125562
func Parse(in string) (*Entry, error) {
	fields := strings.Split(in, "\t")
	e := Entry{}

	if len(fields) < 3 {
		return nil, fmt.Errorf("too few fields: %q", in)
	}

	e.Sym = fields[0]
	e.Path = fields[1]

	lstr := fields[2]
	if len(lstr) < 2 {
		return nil, fmt.Errorf("got %q for linenum field", lstr)
	}

	l, err := strconv.ParseInt(lstr[:len(lstr)-2], 10, 64)
	if err != nil {
		return nil, err
	}
	e.Line = int(l)
	e.Kind = fields[3]

field:
	for _, f := range fields[3:] {
		if string(f) == "file:" {
			e.FileLimited = true
		}
		for _, p := range []string{"class", "enum"} {
			if strings.HasPrefix(f, p+":") {
				e.Parent = strings.TrimPrefix(f, p+":")
				e.ParentType = p
				continue field
			}
		}
	}
	return &e, nil
}
243915
func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
	return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc)
}
592367
func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
	// Reset the simple key on the next level.
	parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{})

	// Increase the flow level.
	parser.flow_level++
	return true
}