yamlh.go (26177B)
1 package yaml 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 // The version directive data. 9 type 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. 15 type yaml_tag_directive_t struct { 16 handle []byte // The tag handle. 17 prefix []byte // The tag prefix. 18 } 19 20 type yaml_encoding_t int 21 22 // The stream encoding. 23 const ( 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 32 type yaml_break_t int 33 34 // Line break types. 35 const ( 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 44 type yaml_error_type_t int 45 46 // Many bad things could happen with the parser and emitter. 47 const ( 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. 61 type 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 69 type yaml_style_t int8 70 71 type yaml_scalar_style_t yaml_style_t 72 73 // Scalar styles. 74 const ( 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 85 type yaml_sequence_style_t yaml_style_t 86 87 // Sequence styles. 88 const ( 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 96 type yaml_mapping_style_t yaml_style_t 97 98 // Mapping styles. 99 const ( 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 109 type yaml_token_type_t int 110 111 // Token types. 112 const ( 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 144 func (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. 195 type 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 224 type yaml_event_type_t int8 225 226 // Event types. 227 const ( 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 243 var 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 257 func (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. 265 type 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 302 func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) } 303 func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) } 304 func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) } 305 306 // Nodes 307 308 const ( 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 328 type yaml_node_type_t int 329 330 // Node types. 331 const ( 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. 341 type yaml_node_item_t int 342 343 // An element of a mapping node. 344 type 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. 350 type 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. 384 type 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. 419 type 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. 422 type 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. 430 type yaml_parser_state_t int 431 432 const ( 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 460 func (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. 515 type 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 521 // The parser structure. 522 // 523 // All members are internal. Manage the structure using the 524 // yaml_parser_ family of functions. 525 type yaml_parser_t struct { 526 527 // Error handling 528 529 error yaml_error_type_t // Error type. 530 531 problem string // Error description. 532 533 // The byte about which the problem occurred. 534 problem_offset int 535 problem_value int 536 problem_mark yaml_mark_t 537 538 // The error context. 539 context string 540 context_mark yaml_mark_t 541 542 // Reader stuff 543 544 read_handler yaml_read_handler_t // Read handler. 545 546 input_reader io.Reader // File input data. 547 input []byte // String input data. 548 input_pos int 549 550 eof bool // EOF flag 551 552 buffer []byte // The working buffer. 553 buffer_pos int // The current position of the buffer. 554 555 unread int // The number of unread characters in the buffer. 556 557 raw_buffer []byte // The raw buffer. 558 raw_buffer_pos int // The current position of the buffer. 559 560 encoding yaml_encoding_t // The input encoding. 561 562 offset int // The offset of the current position (in bytes). 563 mark yaml_mark_t // The mark of the current position. 564 565 // Scanner stuff 566 567 stream_start_produced bool // Have we started to scan the input stream? 568 stream_end_produced bool // Have we reached the end of the input stream? 569 570 flow_level int // The number of unclosed '[' and '{' indicators. 571 572 tokens []yaml_token_t // The tokens queue. 573 tokens_head int // The head of the tokens queue. 574 tokens_parsed int // The number of tokens fetched from the queue. 575 token_available bool // Does the tokens queue contain a token ready for dequeueing. 576 577 indent int // The current indentation level. 578 indents []int // The indentation levels stack. 579 580 simple_key_allowed bool // May a simple key occur at the current position? 581 simple_keys []yaml_simple_key_t // The stack of simple keys. 582 simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number 583 584 // Parser stuff 585 586 state yaml_parser_state_t // The current parser state. 587 states []yaml_parser_state_t // The parser states stack. 588 marks []yaml_mark_t // The stack of marks. 589 tag_directives []yaml_tag_directive_t // The list of TAG directives. 590 591 // Dumper stuff 592 593 aliases []yaml_alias_data_t // The alias data. 594 595 document *yaml_document_t // The currently parsed document. 596 } 597 598 // Emitter Definitions 599 600 // The prototype of a write handler. 601 // 602 // The write handler is called when the emitter needs to flush the accumulated 603 // characters to the output. The handler should write @a size bytes of the 604 // @a buffer to the output. 605 // 606 // @param[in,out] data A pointer to an application data specified by 607 // yaml_emitter_set_output(). 608 // @param[in] buffer The buffer with bytes to be written. 609 // @param[in] size The size of the buffer. 610 // 611 // @returns On success, the handler should return @c 1. If the handler failed, 612 // the returned value should be @c 0. 613 // 614 type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error 615 616 type yaml_emitter_state_t int 617 618 // The emitter states. 619 const ( 620 // Expect STREAM-START. 621 yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota 622 623 yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END. 624 yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END. 625 yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document. 626 yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END. 627 yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence. 628 yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence. 629 yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. 630 yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. 631 yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping. 632 yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. 633 yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence. 634 yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence. 635 yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. 636 yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping. 637 yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping. 638 yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping. 639 yaml_EMIT_END_STATE // Expect nothing. 640 ) 641 642 // The emitter structure. 643 // 644 // All members are internal. Manage the structure using the @c yaml_emitter_ 645 // family of functions. 646 type yaml_emitter_t struct { 647 648 // Error handling 649 650 error yaml_error_type_t // Error type. 651 problem string // Error description. 652 653 // Writer stuff 654 655 write_handler yaml_write_handler_t // Write handler. 656 657 output_buffer *[]byte // String output data. 658 output_writer io.Writer // File output data. 659 660 buffer []byte // The working buffer. 661 buffer_pos int // The current position of the buffer. 662 663 raw_buffer []byte // The raw buffer. 664 raw_buffer_pos int // The current position of the buffer. 665 666 encoding yaml_encoding_t // The stream encoding. 667 668 // Emitter stuff 669 670 canonical bool // If the output is in the canonical style? 671 best_indent int // The number of indentation spaces. 672 best_width int // The preferred width of the output lines. 673 unicode bool // Allow unescaped non-ASCII characters? 674 line_break yaml_break_t // The preferred line break. 675 676 state yaml_emitter_state_t // The current emitter state. 677 states []yaml_emitter_state_t // The stack of states. 678 679 events []yaml_event_t // The event queue. 680 events_head int // The head of the event queue. 681 682 indents []int // The stack of indentation levels. 683 684 tag_directives []yaml_tag_directive_t // The list of tag directives. 685 686 indent int // The current indentation level. 687 688 flow_level int // The current flow level. 689 690 root_context bool // Is it the document root context? 691 sequence_context bool // Is it a sequence context? 692 mapping_context bool // Is it a mapping context? 693 simple_key_context bool // Is it a simple mapping key context? 694 695 line int // The current line. 696 column int // The current column. 697 whitespace bool // If the last character was a whitespace? 698 indention bool // If the last character was an indentation character (' ', '-', '?', ':')? 699 open_ended bool // If an explicit document end is required? 700 701 // Anchor analysis. 702 anchor_data struct { 703 anchor []byte // The anchor value. 704 alias bool // Is it an alias? 705 } 706 707 // Tag analysis. 708 tag_data struct { 709 handle []byte // The tag handle. 710 suffix []byte // The tag suffix. 711 } 712 713 // Scalar analysis. 714 scalar_data struct { 715 value []byte // The scalar value. 716 multiline bool // Does the scalar contain line breaks? 717 flow_plain_allowed bool // Can the scalar be expessed in the flow plain style? 718 block_plain_allowed bool // Can the scalar be expressed in the block plain style? 719 single_quoted_allowed bool // Can the scalar be expressed in the single quoted style? 720 block_allowed bool // Can the scalar be expressed in the literal or folded styles? 721 style yaml_scalar_style_t // The output style. 722 } 723 724 // Dumper stuff 725 726 opened bool // If the stream was already opened? 727 closed bool // If the stream was already closed? 728 729 // The information associated with the document nodes. 730 anchors *struct { 731 references int // The number of references. 732 anchor int // The anchor id. 733 serialized bool // If the node has been emitted? 734 } 735 736 last_anchor_id int // The last assigned anchor id. 737 738 document *yaml_document_t // The currently emitted document. 739 }