Parse the productions: implicit_document ::= block_node DOCUMENT-END* * explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* *************************
(parser *yaml_parser_t, event *yaml_event_t, implicit bool)
| 253 | // explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* |
| 254 | // ************************* |
| 255 | func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool { |
| 256 | |
| 257 | token := peek_token(parser) |
| 258 | if token == nil { |
| 259 | return false |
| 260 | } |
| 261 | |
| 262 | // Parse extra document end indicators. |
| 263 | if !implicit { |
| 264 | for token.typ == yaml_DOCUMENT_END_TOKEN { |
| 265 | skip_token(parser) |
| 266 | token = peek_token(parser) |
| 267 | if token == nil { |
| 268 | return false |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if implicit && token.typ != yaml_VERSION_DIRECTIVE_TOKEN && |
| 274 | token.typ != yaml_TAG_DIRECTIVE_TOKEN && |
| 275 | token.typ != yaml_DOCUMENT_START_TOKEN && |
| 276 | token.typ != yaml_STREAM_END_TOKEN { |
| 277 | // Parse an implicit document. |
| 278 | if !yaml_parser_process_directives(parser, nil, nil) { |
| 279 | return false |
| 280 | } |
| 281 | parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) |
| 282 | parser.state = yaml_PARSE_BLOCK_NODE_STATE |
| 283 | |
| 284 | var head_comment []byte |
| 285 | if len(parser.head_comment) > 0 { |
| 286 | // [Go] Scan the header comment backwards, and if an empty line is found, break |
| 287 | // the header so the part before the last empty line goes into the |
| 288 | // document header, while the bottom of it goes into a follow up event. |
| 289 | for i := len(parser.head_comment) - 1; i > 0; i-- { |
| 290 | if parser.head_comment[i] == '\n' { |
| 291 | if i == len(parser.head_comment)-1 { |
| 292 | head_comment = parser.head_comment[:i] |
| 293 | parser.head_comment = parser.head_comment[i+1:] |
| 294 | break |
| 295 | } else if parser.head_comment[i-1] == '\n' { |
| 296 | head_comment = parser.head_comment[:i-1] |
| 297 | parser.head_comment = parser.head_comment[i+1:] |
| 298 | break |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | *event = yaml_event_t{ |
| 305 | typ: yaml_DOCUMENT_START_EVENT, |
| 306 | start_mark: token.start_mark, |
| 307 | end_mark: token.end_mark, |
| 308 | |
| 309 | head_comment: head_comment, |
| 310 | } |
| 311 | |
| 312 | } else if token.typ != yaml_STREAM_END_TOKEN { |
no test coverage detected