blob: 46ce46249b0632d4e3d9bbf2b6a8f0abfc9d6925 [file] [log] [blame]
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +01001package yaml
2
3import (
4 "fmt"
5 "io"
6)
7
8// The version directive data.
9type yaml_version_directive_t struct {
10 major int8 // The major version number.
11 minor int8 // The minor version number.
12}
13
14// The tag directive data.
15type yaml_tag_directive_t struct {
16 handle []byte // The tag handle.
17 prefix []byte // The tag prefix.
18}
19
20type yaml_encoding_t int
21
22// The stream encoding.
23const (
24 // Let the parser choose the encoding.
25 yaml_ANY_ENCODING yaml_encoding_t = iota
26
27 yaml_UTF8_ENCODING // The default UTF-8 encoding.
28 yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM.
29 yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM.
30)
31
32type yaml_break_t int
33
34// Line break types.
35const (
36 // Let the parser choose the break type.
37 yaml_ANY_BREAK yaml_break_t = iota
38
39 yaml_CR_BREAK // Use CR for line breaks (Mac style).
40 yaml_LN_BREAK // Use LN for line breaks (Unix style).
41 yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style).
42)
43
44type yaml_error_type_t int
45
46// Many bad things could happen with the parser and emitter.
47const (
48 // No error is produced.
49 yaml_NO_ERROR yaml_error_type_t = iota
50
51 yaml_MEMORY_ERROR // Cannot allocate or reallocate a block of memory.
52 yaml_READER_ERROR // Cannot read or decode the input stream.
53 yaml_SCANNER_ERROR // Cannot scan the input stream.
54 yaml_PARSER_ERROR // Cannot parse the input stream.
55 yaml_COMPOSER_ERROR // Cannot compose a YAML document.
56 yaml_WRITER_ERROR // Cannot write to the output stream.
57 yaml_EMITTER_ERROR // Cannot emit a YAML stream.
58)
59
60// The pointer position.
61type yaml_mark_t struct {
62 index int // The position index.
63 line int // The position line.
64 column int // The position column.
65}
66
67// Node Styles
68
69type yaml_style_t int8
70
71type yaml_scalar_style_t yaml_style_t
72
73// Scalar styles.
74const (
75 // Let the emitter choose the style.
76 yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = iota
77
78 yaml_PLAIN_SCALAR_STYLE // The plain scalar style.
79 yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style.
80 yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style.
81 yaml_LITERAL_SCALAR_STYLE // The literal scalar style.
82 yaml_FOLDED_SCALAR_STYLE // The folded scalar style.
83)
84
85type yaml_sequence_style_t yaml_style_t
86
87// Sequence styles.
88const (
89 // Let the emitter choose the style.
90 yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota
91
92 yaml_BLOCK_SEQUENCE_STYLE // The block sequence style.
93 yaml_FLOW_SEQUENCE_STYLE // The flow sequence style.
94)
95
96type yaml_mapping_style_t yaml_style_t
97
98// Mapping styles.
99const (
100 // Let the emitter choose the style.
101 yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota
102
103 yaml_BLOCK_MAPPING_STYLE // The block mapping style.
104 yaml_FLOW_MAPPING_STYLE // The flow mapping style.
105)
106
107// Tokens
108
109type yaml_token_type_t int
110
111// Token types.
112const (
113 // An empty token.
114 yaml_NO_TOKEN yaml_token_type_t = iota
115
116 yaml_STREAM_START_TOKEN // A STREAM-START token.
117 yaml_STREAM_END_TOKEN // A STREAM-END token.
118
119 yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token.
120 yaml_TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token.
121 yaml_DOCUMENT_START_TOKEN // A DOCUMENT-START token.
122 yaml_DOCUMENT_END_TOKEN // A DOCUMENT-END token.
123
124 yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token.
125 yaml_BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token.
126 yaml_BLOCK_END_TOKEN // A BLOCK-END token.
127
128 yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token.
129 yaml_FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token.
130 yaml_FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token.
131 yaml_FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token.
132
133 yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token.
134 yaml_FLOW_ENTRY_TOKEN // A FLOW-ENTRY token.
135 yaml_KEY_TOKEN // A KEY token.
136 yaml_VALUE_TOKEN // A VALUE token.
137
138 yaml_ALIAS_TOKEN // An ALIAS token.
139 yaml_ANCHOR_TOKEN // An ANCHOR token.
140 yaml_TAG_TOKEN // A TAG token.
141 yaml_SCALAR_TOKEN // A SCALAR token.
142)
143
144func (tt yaml_token_type_t) String() string {
145 switch tt {
146 case yaml_NO_TOKEN:
147 return "yaml_NO_TOKEN"
148 case yaml_STREAM_START_TOKEN:
149 return "yaml_STREAM_START_TOKEN"
150 case yaml_STREAM_END_TOKEN:
151 return "yaml_STREAM_END_TOKEN"
152 case yaml_VERSION_DIRECTIVE_TOKEN:
153 return "yaml_VERSION_DIRECTIVE_TOKEN"
154 case yaml_TAG_DIRECTIVE_TOKEN:
155 return "yaml_TAG_DIRECTIVE_TOKEN"
156 case yaml_DOCUMENT_START_TOKEN:
157 return "yaml_DOCUMENT_START_TOKEN"
158 case yaml_DOCUMENT_END_TOKEN:
159 return "yaml_DOCUMENT_END_TOKEN"
160 case yaml_BLOCK_SEQUENCE_START_TOKEN:
161 return "yaml_BLOCK_SEQUENCE_START_TOKEN"
162 case yaml_BLOCK_MAPPING_START_TOKEN:
163 return "yaml_BLOCK_MAPPING_START_TOKEN"
164 case yaml_BLOCK_END_TOKEN:
165 return "yaml_BLOCK_END_TOKEN"
166 case yaml_FLOW_SEQUENCE_START_TOKEN:
167 return "yaml_FLOW_SEQUENCE_START_TOKEN"
168 case yaml_FLOW_SEQUENCE_END_TOKEN:
169 return "yaml_FLOW_SEQUENCE_END_TOKEN"
170 case yaml_FLOW_MAPPING_START_TOKEN:
171 return "yaml_FLOW_MAPPING_START_TOKEN"
172 case yaml_FLOW_MAPPING_END_TOKEN:
173 return "yaml_FLOW_MAPPING_END_TOKEN"
174 case yaml_BLOCK_ENTRY_TOKEN:
175 return "yaml_BLOCK_ENTRY_TOKEN"
176 case yaml_FLOW_ENTRY_TOKEN:
177 return "yaml_FLOW_ENTRY_TOKEN"
178 case yaml_KEY_TOKEN:
179 return "yaml_KEY_TOKEN"
180 case yaml_VALUE_TOKEN:
181 return "yaml_VALUE_TOKEN"
182 case yaml_ALIAS_TOKEN:
183 return "yaml_ALIAS_TOKEN"
184 case yaml_ANCHOR_TOKEN:
185 return "yaml_ANCHOR_TOKEN"
186 case yaml_TAG_TOKEN:
187 return "yaml_TAG_TOKEN"
188 case yaml_SCALAR_TOKEN:
189 return "yaml_SCALAR_TOKEN"
190 }
191 return "<unknown token>"
192}
193
194// The token structure.
195type yaml_token_t struct {
196 // The token type.
197 typ yaml_token_type_t
198
199 // The start/end of the token.
200 start_mark, end_mark yaml_mark_t
201
202 // The stream encoding (for yaml_STREAM_START_TOKEN).
203 encoding yaml_encoding_t
204
205 // The alias/anchor/scalar value or tag/tag directive handle
206 // (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN).
207 value []byte
208
209 // The tag suffix (for yaml_TAG_TOKEN).
210 suffix []byte
211
212 // The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN).
213 prefix []byte
214
215 // The scalar style (for yaml_SCALAR_TOKEN).
216 style yaml_scalar_style_t
217
218 // The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN).
219 major, minor int8
220}
221
222// Events
223
224type yaml_event_type_t int8
225
226// Event types.
227const (
228 // An empty event.
229 yaml_NO_EVENT yaml_event_type_t = iota
230
231 yaml_STREAM_START_EVENT // A STREAM-START event.
232 yaml_STREAM_END_EVENT // A STREAM-END event.
233 yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event.
234 yaml_DOCUMENT_END_EVENT // A DOCUMENT-END event.
235 yaml_ALIAS_EVENT // An ALIAS event.
236 yaml_SCALAR_EVENT // A SCALAR event.
237 yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event.
238 yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event.
239 yaml_MAPPING_START_EVENT // A MAPPING-START event.
240 yaml_MAPPING_END_EVENT // A MAPPING-END event.
241)
242
243var eventStrings = []string{
244 yaml_NO_EVENT: "none",
245 yaml_STREAM_START_EVENT: "stream start",
246 yaml_STREAM_END_EVENT: "stream end",
247 yaml_DOCUMENT_START_EVENT: "document start",
248 yaml_DOCUMENT_END_EVENT: "document end",
249 yaml_ALIAS_EVENT: "alias",
250 yaml_SCALAR_EVENT: "scalar",
251 yaml_SEQUENCE_START_EVENT: "sequence start",
252 yaml_SEQUENCE_END_EVENT: "sequence end",
253 yaml_MAPPING_START_EVENT: "mapping start",
254 yaml_MAPPING_END_EVENT: "mapping end",
255}
256
257func (e yaml_event_type_t) String() string {
258 if e < 0 || int(e) >= len(eventStrings) {
259 return fmt.Sprintf("unknown event %d", e)
260 }
261 return eventStrings[e]
262}
263
264// The event structure.
265type yaml_event_t struct {
266
267 // The event type.
268 typ yaml_event_type_t
269
270 // The start and end of the event.
271 start_mark, end_mark yaml_mark_t
272
273 // The document encoding (for yaml_STREAM_START_EVENT).
274 encoding yaml_encoding_t
275
276 // The version directive (for yaml_DOCUMENT_START_EVENT).
277 version_directive *yaml_version_directive_t
278
279 // The list of tag directives (for yaml_DOCUMENT_START_EVENT).
280 tag_directives []yaml_tag_directive_t
281
282 // The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT).
283 anchor []byte
284
285 // The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).
286 tag []byte
287
288 // The scalar value (for yaml_SCALAR_EVENT).
289 value []byte
290
291 // Is the document start/end indicator implicit, or the tag optional?
292 // (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT).
293 implicit bool
294
295 // Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT).
296 quoted_implicit bool
297
298 // The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).
299 style yaml_style_t
300}
301
302func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) }
303func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) }
304func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) }
305
306// Nodes
307
308const (
309 yaml_NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null.
310 yaml_BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false.
311 yaml_STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values.
312 yaml_INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values.
313 yaml_FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values.
314 yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values.
315
316 yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences.
317 yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping.
318
319 // Not in original libyaml.
320 yaml_BINARY_TAG = "tag:yaml.org,2002:binary"
321 yaml_MERGE_TAG = "tag:yaml.org,2002:merge"
322
323 yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG // The default scalar tag is !!str.
324 yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq.
325 yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG // The default mapping tag is !!map.
326)
327
328type yaml_node_type_t int
329
330// Node types.
331const (
332 // An empty node.
333 yaml_NO_NODE yaml_node_type_t = iota
334
335 yaml_SCALAR_NODE // A scalar node.
336 yaml_SEQUENCE_NODE // A sequence node.
337 yaml_MAPPING_NODE // A mapping node.
338)
339
340// An element of a sequence node.
341type yaml_node_item_t int
342
343// An element of a mapping node.
344type yaml_node_pair_t struct {
345 key int // The key of the element.
346 value int // The value of the element.
347}
348
349// The node structure.
350type yaml_node_t struct {
351 typ yaml_node_type_t // The node type.
352 tag []byte // The node tag.
353
354 // The node data.
355
356 // The scalar parameters (for yaml_SCALAR_NODE).
357 scalar struct {
358 value []byte // The scalar value.
359 length int // The length of the scalar value.
360 style yaml_scalar_style_t // The scalar style.
361 }
362
363 // The sequence parameters (for YAML_SEQUENCE_NODE).
364 sequence struct {
365 items_data []yaml_node_item_t // The stack of sequence items.
366 style yaml_sequence_style_t // The sequence style.
367 }
368
369 // The mapping parameters (for yaml_MAPPING_NODE).
370 mapping struct {
371 pairs_data []yaml_node_pair_t // The stack of mapping pairs (key, value).
372 pairs_start *yaml_node_pair_t // The beginning of the stack.
373 pairs_end *yaml_node_pair_t // The end of the stack.
374 pairs_top *yaml_node_pair_t // The top of the stack.
375 style yaml_mapping_style_t // The mapping style.
376 }
377
378 start_mark yaml_mark_t // The beginning of the node.
379 end_mark yaml_mark_t // The end of the node.
380
381}
382
383// The document structure.
384type yaml_document_t struct {
385
386 // The document nodes.
387 nodes []yaml_node_t
388
389 // The version directive.
390 version_directive *yaml_version_directive_t
391
392 // The list of tag directives.
393 tag_directives_data []yaml_tag_directive_t
394 tag_directives_start int // The beginning of the tag directives list.
395 tag_directives_end int // The end of the tag directives list.
396
397 start_implicit int // Is the document start indicator implicit?
398 end_implicit int // Is the document end indicator implicit?
399
400 // The start/end of the document.
401 start_mark, end_mark yaml_mark_t
402}
403
404// The prototype of a read handler.
405//
406// The read handler is called when the parser needs to read more bytes from the
407// source. The handler should write not more than size bytes to the buffer.
408// The number of written bytes should be set to the size_read variable.
409//
410// [in,out] data A pointer to an application data specified by
411// yaml_parser_set_input().
412// [out] buffer The buffer to write the data from the source.
413// [in] size The size of the buffer.
414// [out] size_read The actual number of bytes read from the source.
415//
416// On success, the handler should return 1. If the handler failed,
417// the returned value should be 0. On EOF, the handler should set the
418// size_read to 0 and return 1.
419type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error)
420
421// This structure holds information about a potential simple key.
422type yaml_simple_key_t struct {
423 possible bool // Is a simple key possible?
424 required bool // Is a simple key required?
425 token_number int // The number of the token.
426 mark yaml_mark_t // The position mark.
427}
428
429// The states of the parser.
430type yaml_parser_state_t int
431
432const (
433 yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota
434
435 yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document.
436 yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START.
437 yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document.
438 yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END.
439 yaml_PARSE_BLOCK_NODE_STATE // Expect a block node.
440 yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence.
441 yaml_PARSE_FLOW_NODE_STATE // Expect a flow node.
442 yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence.
443 yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence.
444 yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence.
445 yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.
446 yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key.
447 yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value.
448 yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence.
449 yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence.
450 yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping.
451 yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping.
452 yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry.
453 yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.
454 yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.
455 yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.
456 yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping.
457 yaml_PARSE_END_STATE // Expect nothing.
458)
459
460func (ps yaml_parser_state_t) String() string {
461 switch ps {
462 case yaml_PARSE_STREAM_START_STATE:
463 return "yaml_PARSE_STREAM_START_STATE"
464 case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE:
465 return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE"
466 case yaml_PARSE_DOCUMENT_START_STATE:
467 return "yaml_PARSE_DOCUMENT_START_STATE"
468 case yaml_PARSE_DOCUMENT_CONTENT_STATE:
469 return "yaml_PARSE_DOCUMENT_CONTENT_STATE"
470 case yaml_PARSE_DOCUMENT_END_STATE:
471 return "yaml_PARSE_DOCUMENT_END_STATE"
472 case yaml_PARSE_BLOCK_NODE_STATE:
473 return "yaml_PARSE_BLOCK_NODE_STATE"
474 case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:
475 return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE"
476 case yaml_PARSE_FLOW_NODE_STATE:
477 return "yaml_PARSE_FLOW_NODE_STATE"
478 case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:
479 return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE"
480 case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:
481 return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE"
482 case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:
483 return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE"
484 case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:
485 return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE"
486 case yaml_PARSE_BLOCK_MAPPING_KEY_STATE:
487 return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE"
488 case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE:
489 return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE"
490 case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:
491 return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE"
492 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE:
493 return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE"
494 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:
495 return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE"
496 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:
497 return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE"
498 case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:
499 return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE"
500 case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:
501 return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE"
502 case yaml_PARSE_FLOW_MAPPING_KEY_STATE:
503 return "yaml_PARSE_FLOW_MAPPING_KEY_STATE"
504 case yaml_PARSE_FLOW_MAPPING_VALUE_STATE:
505 return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE"
506 case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:
507 return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE"
508 case yaml_PARSE_END_STATE:
509 return "yaml_PARSE_END_STATE"
510 }
511 return "<unknown parser state>"
512}
513
514// This structure holds aliases data.
515type yaml_alias_data_t struct {
516 anchor []byte // The anchor.
517 index int // The node id.
518 mark yaml_mark_t // The anchor mark.
519}
520
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100521type yaml_comment_t struct {
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100522 mark yaml_mark_t
523 text string
524}
525
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +0100526// The parser structure.
527//
528// All members are internal. Manage the structure using the
529// yaml_parser_ family of functions.
530type yaml_parser_t struct {
531
532 // Error handling
533
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100534 filename string
535
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +0100536 error yaml_error_type_t // Error type.
537
538 problem string // Error description.
539
540 // The byte about which the problem occurred.
541 problem_offset int
542 problem_value int
543 problem_mark yaml_mark_t
544
545 // The error context.
546 context string
547 context_mark yaml_mark_t
548
549 // Reader stuff
550
551 read_handler yaml_read_handler_t // Read handler.
552
553 input_reader io.Reader // File input data.
554 input []byte // String input data.
555 input_pos int
556
557 eof bool // EOF flag
558
559 buffer []byte // The working buffer.
560 buffer_pos int // The current position of the buffer.
561
562 unread int // The number of unread characters in the buffer.
563
564 raw_buffer []byte // The raw buffer.
565 raw_buffer_pos int // The current position of the buffer.
566
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100567 comment_buffer []byte
568
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +0100569 encoding yaml_encoding_t // The input encoding.
570
571 offset int // The offset of the current position (in bytes).
572 mark yaml_mark_t // The mark of the current position.
573
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100574 linesSinceLast int
575 spacesSinceLast int
576
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +0100577 // Scanner stuff
578
579 stream_start_produced bool // Have we started to scan the input stream?
580 stream_end_produced bool // Have we reached the end of the input stream?
581
582 flow_level int // The number of unclosed '[' and '{' indicators.
583
584 tokens []yaml_token_t // The tokens queue.
585 tokens_head int // The head of the tokens queue.
586 tokens_parsed int // The number of tokens fetched from the queue.
587 token_available bool // Does the tokens queue contain a token ready for dequeueing.
588
Marcel van Lohuizen2156c812018-12-10 16:05:07 +0100589 comments []yaml_comment_t
590
Marcel van Lohuizen07ee2ab2018-12-10 15:57:15 +0100591 indent int // The current indentation level.
592 indents []int // The indentation levels stack.
593
594 simple_key_allowed bool // May a simple key occur at the current position?
595 simple_keys []yaml_simple_key_t // The stack of simple keys.
596
597 // Parser stuff
598
599 state yaml_parser_state_t // The current parser state.
600 states []yaml_parser_state_t // The parser states stack.
601 marks []yaml_mark_t // The stack of marks.
602 tag_directives []yaml_tag_directive_t // The list of TAG directives.
603
604 // Dumper stuff
605
606 aliases []yaml_alias_data_t // The alias data.
607
608 document *yaml_document_t // The currently parsed document.
609}
610
611// Emitter Definitions
612
613// The prototype of a write handler.
614//
615// The write handler is called when the emitter needs to flush the accumulated
616// characters to the output. The handler should write @a size bytes of the
617// @a buffer to the output.
618//
619// @param[in,out] data A pointer to an application data specified by
620// yaml_emitter_set_output().
621// @param[in] buffer The buffer with bytes to be written.
622// @param[in] size The size of the buffer.
623//
624// @returns On success, the handler should return @c 1. If the handler failed,
625// the returned value should be @c 0.
626//
627type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error
628
629type yaml_emitter_state_t int
630
631// The emitter states.
632const (
633 // Expect STREAM-START.
634 yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota
635
636 yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END.
637 yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END.
638 yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document.
639 yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END.
640 yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence.
641 yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence.
642 yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.
643 yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.
644 yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping.
645 yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.
646 yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence.
647 yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence.
648 yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.
649 yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping.
650 yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping.
651 yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping.
652 yaml_EMIT_END_STATE // Expect nothing.
653)
654
655// The emitter structure.
656//
657// All members are internal. Manage the structure using the @c yaml_emitter_
658// family of functions.
659type yaml_emitter_t struct {
660
661 // Error handling
662
663 error yaml_error_type_t // Error type.
664 problem string // Error description.
665
666 // Writer stuff
667
668 write_handler yaml_write_handler_t // Write handler.
669
670 output_buffer *[]byte // String output data.
671 output_writer io.Writer // File output data.
672
673 buffer []byte // The working buffer.
674 buffer_pos int // The current position of the buffer.
675
676 raw_buffer []byte // The raw buffer.
677 raw_buffer_pos int // The current position of the buffer.
678
679 encoding yaml_encoding_t // The stream encoding.
680
681 // Emitter stuff
682
683 canonical bool // If the output is in the canonical style?
684 best_indent int // The number of indentation spaces.
685 best_width int // The preferred width of the output lines.
686 unicode bool // Allow unescaped non-ASCII characters?
687 line_break yaml_break_t // The preferred line break.
688
689 state yaml_emitter_state_t // The current emitter state.
690 states []yaml_emitter_state_t // The stack of states.
691
692 events []yaml_event_t // The event queue.
693 events_head int // The head of the event queue.
694
695 indents []int // The stack of indentation levels.
696
697 tag_directives []yaml_tag_directive_t // The list of tag directives.
698
699 indent int // The current indentation level.
700
701 flow_level int // The current flow level.
702
703 root_context bool // Is it the document root context?
704 sequence_context bool // Is it a sequence context?
705 mapping_context bool // Is it a mapping context?
706 simple_key_context bool // Is it a simple mapping key context?
707
708 line int // The current line.
709 column int // The current column.
710 whitespace bool // If the last character was a whitespace?
711 indention bool // If the last character was an indentation character (' ', '-', '?', ':')?
712 open_ended bool // If an explicit document end is required?
713
714 // Anchor analysis.
715 anchor_data struct {
716 anchor []byte // The anchor value.
717 alias bool // Is it an alias?
718 }
719
720 // Tag analysis.
721 tag_data struct {
722 handle []byte // The tag handle.
723 suffix []byte // The tag suffix.
724 }
725
726 // Scalar analysis.
727 scalar_data struct {
728 value []byte // The scalar value.
729 multiline bool // Does the scalar contain line breaks?
730 flow_plain_allowed bool // Can the scalar be expessed in the flow plain style?
731 block_plain_allowed bool // Can the scalar be expressed in the block plain style?
732 single_quoted_allowed bool // Can the scalar be expressed in the single quoted style?
733 block_allowed bool // Can the scalar be expressed in the literal or folded styles?
734 style yaml_scalar_style_t // The output style.
735 }
736
737 // Dumper stuff
738
739 opened bool // If the stream was already opened?
740 closed bool // If the stream was already closed?
741
742 // The information associated with the document nodes.
743 anchors *struct {
744 references int // The number of references.
745 anchor int // The anchor id.
746 serialized bool // If the node has been emitted?
747 }
748
749 last_anchor_id int // The last assigned anchor id.
750
751 document *yaml_document_t // The currently emitted document.
752}