aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libfyaml/src/lib/fy-docbuilder.h
blob: aa506d6845005c3219277b3bfef54f03b492305f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * fy-docbuilder.h - YAML document builder internal header file
 *
 * Copyright (c) 2022 Pantelis Antoniou <pantelis.antoniou@konsulko.com>
 *
 * SPDX-License-Identifier: MIT
 */
#ifndef FY_DOCBUILDER_H
#define FY_DOCBUILDER_H

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdarg.h>

#include <libfyaml.h>

#include "fy-doc.h"

enum fy_document_builder_state {
	FYDBS_NODE,
	FYDBS_MAP_KEY,
	FYDBS_MAP_VAL,
	FYDBS_SEQ,
};

struct fy_document_builder_ctx {
	enum fy_document_builder_state s;
	struct fy_node *fyn;
	struct fy_node_pair *fynp;	/* for mapping */
};

struct fy_document_builder_cfg {
	struct fy_parse_cfg parse_cfg;
	void *userdata;
	struct fy_diag *diag;
};

struct fy_document_builder {
	struct fy_document_builder_cfg cfg;
	struct fy_document *fyd;
	bool single_mode;
	bool in_stream;
	bool doc_done;
	unsigned int next;
	unsigned int alloc;
	unsigned int max_depth;
	struct fy_document_builder_ctx *stack;
};

struct fy_document_builder *
fy_document_builder_create(const struct fy_document_builder_cfg *cfg);

void
fy_document_builder_reset(struct fy_document_builder *fydb);

void
fy_document_builder_destroy(struct fy_document_builder *fydb);

struct fy_document *
fy_document_builder_get_document(struct fy_document_builder *fydb);

bool
fy_document_builder_is_in_stream(struct fy_document_builder *fydb);

bool
fy_document_builder_is_in_document(struct fy_document_builder *fydb);

bool
fy_document_builder_is_document_complete(struct fy_document_builder *fydb);

struct fy_document *
fy_document_builder_take_document(struct fy_document_builder *fydb);

struct fy_document *
fy_document_builder_peek_document(struct fy_document_builder *fydb);

void
fy_document_builder_set_in_stream(struct fy_document_builder *fydb);

int
fy_document_builder_set_in_document(struct fy_document_builder *fydb, struct fy_document_state *fyds, bool single);

int
fy_document_builder_process_event(struct fy_document_builder *fydb, struct fy_eventp *fyep);

struct fy_document *
fy_document_builder_load_document(struct fy_document_builder *fydb,
				  struct fy_parser *fyp);

struct fy_document *
fy_parse_load_document_with_builder(struct fy_parser *fyp);

#endif