Eat whitespaces and comments until the next token is found.
(parser *yaml_parser_t)
| 1533 | |
| 1534 | // Eat whitespaces and comments until the next token is found. |
| 1535 | func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { |
| 1536 | |
| 1537 | scan_mark := parser.mark |
| 1538 | |
| 1539 | // Until the next token is not found. |
| 1540 | for { |
| 1541 | // Allow the BOM mark to start a line. |
| 1542 | if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { |
| 1543 | return false |
| 1544 | } |
| 1545 | if parser.mark.column == 0 && is_bom(parser.buffer, parser.buffer_pos) { |
| 1546 | skip(parser) |
| 1547 | } |
| 1548 | |
| 1549 | // Eat whitespaces. |
| 1550 | // Tabs are allowed: |
| 1551 | // - in the flow context |
| 1552 | // - in the block context, but not at the beginning of the line or |
| 1553 | // after '-', '?', or ':' (complex value). |
| 1554 | if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { |
| 1555 | return false |
| 1556 | } |
| 1557 | |
| 1558 | for parser.buffer[parser.buffer_pos] == ' ' || ((parser.flow_level > 0 || !parser.simple_key_allowed) && parser.buffer[parser.buffer_pos] == '\t') { |
| 1559 | skip(parser) |
| 1560 | if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { |
| 1561 | return false |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | // Check if we just had a line comment under a sequence entry that |
| 1566 | // looks more like a header to the following content. Similar to this: |
| 1567 | // |
| 1568 | // - # The comment |
| 1569 | // - Some data |
| 1570 | // |
| 1571 | // If so, transform the line comment to a head comment and reposition. |
| 1572 | if len(parser.comments) > 0 && len(parser.tokens) > 1 { |
| 1573 | tokenA := parser.tokens[len(parser.tokens)-2] |
| 1574 | tokenB := parser.tokens[len(parser.tokens)-1] |
| 1575 | comment := &parser.comments[len(parser.comments)-1] |
| 1576 | if tokenA.typ == yaml_BLOCK_SEQUENCE_START_TOKEN && tokenB.typ == yaml_BLOCK_ENTRY_TOKEN && len(comment.line) > 0 && !is_break(parser.buffer, parser.buffer_pos) { |
| 1577 | // If it was in the prior line, reposition so it becomes a |
| 1578 | // header of the follow up token. Otherwise, keep it in place |
| 1579 | // so it becomes a header of the former. |
| 1580 | comment.head = comment.line |
| 1581 | comment.line = nil |
| 1582 | if comment.start_mark.line == parser.mark.line-1 { |
| 1583 | comment.token_mark = parser.mark |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | // Eat a comment until a line break. |
| 1589 | if parser.buffer[parser.buffer_pos] == '#' { |
| 1590 | if !yaml_parser_scan_comments(parser, scan_mark) { |
| 1591 | return false |
| 1592 | } |
no test coverage detected