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