Skip to content

Commit

Permalink
Merge pull request #502 from biojppm/ysfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm authored Feb 26, 2025
2 parents 8c37616 + 3d66090 commit 0bfb286
Show file tree
Hide file tree
Showing 5 changed files with 949 additions and 13 deletions.
24 changes: 24 additions & 0 deletions changelog/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,27 @@
## Fixes

- [PR#501](https://github.com/biojppm/rapidyaml/pull/501): fix missing tag in `- !!seq []`
- [PR#502](https://github.com/biojppm/rapidyaml/pull/502): fix parse errors or missing tags:
- missing tags in empty documents:
```yaml
!yamlscript/v0/bare
--- !code
42
```
- trailing empty keys or vals:
```yaml
a:
:
```
- missing tags in trailing empty keys or vals:
```yaml
a: !tag
!tag : !tag
```
- missing tags in complex maps:
```yaml
? a: !tag
!tag : !tag
:
!tag : !tag
```
40 changes: 33 additions & 7 deletions src/c4/yml/parse_engine.def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,9 +1611,10 @@ void ParseEngine<EventHandler>::_end2_doc()
{
_c4dbgp("doc: end");
_RYML_CB_ASSERT(m_evt_handler->m_stack.m_callbacks, has_any(RDOC));
if(m_doc_empty)
if(m_doc_empty || (m_pending_tags.num_entries || m_pending_anchors.num_entries))
{
_c4dbgp("doc was empty; add empty val");
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain_empty();
}
m_evt_handler->end_doc();
Expand All @@ -1623,9 +1624,10 @@ template<class EventHandler>
void ParseEngine<EventHandler>::_end2_doc_expl()
{
_c4dbgp("doc: end");
if(m_doc_empty)
if(m_doc_empty || (m_pending_tags.num_entries || m_pending_anchors.num_entries))
{
_c4dbgp("doc: no children; add empty val");
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain_empty();
}
m_evt_handler->end_doc_expl();
Expand All @@ -1648,6 +1650,14 @@ void ParseEngine<EventHandler>::_maybe_end_doc()
_c4dbgp("doc must be finished");
_end2_doc();
}
else if(m_doc_empty && (m_pending_tags.num_entries || m_pending_anchors.num_entries))
{
_c4dbgp("no doc to finish, but pending annotations");
m_evt_handler->begin_doc();
_handle_annotations_before_blck_val_scalar();
m_evt_handler->set_val_scalar_plain_empty();
m_evt_handler->end_doc();
}
}

template<class EventHandler>
Expand Down Expand Up @@ -6800,14 +6810,26 @@ void ParseEngine<EventHandler>::_handle_map_block()
m_evt_handler->set_val_scalar_plain_empty();
m_evt_handler->add_sibling();
m_evt_handler->set_key_scalar_plain_empty();
_line_progressed(1);
_maybe_skip_whitespace_tokens();
goto mapblck_again;
}
else if(startindent > m_evt_handler->m_curr->indref)
{
_c4dbgp("mapblck[RVAL]: start val mapblck");
addrem_flags(RNXT, RVAL);
_handle_annotations_before_start_mapblck(startline);
m_evt_handler->begin_map_val_block();
_handle_annotations_and_indentation_after_start_mapblck(startindent, startline);
m_evt_handler->set_key_scalar_plain_empty();
_set_indentation(m_evt_handler->m_curr->line_contents.indentation);
// keep the child state on RVAL
addrem_flags(RVAL, RNXT);
}
else
{
_c4err("parse error");
}
_line_progressed(1);
_maybe_skip_whitespace_tokens();
goto mapblck_again;
}
else if(first == '.')
{
Expand Down Expand Up @@ -7160,6 +7182,7 @@ void ParseEngine<EventHandler>::_handle_map_block()
{
_c4dbgp("mapblck[QMRK]: start child seqblck (!)");
addrem_flags(RKCL, RKEY|QMRK);
_handle_annotations_before_blck_key_scalar();
m_evt_handler->begin_seq_key_block();
addrem_flags(RVAL|RSEQ, RMAP|RKCL|QMRK);
_set_indentation(startindent);
Expand Down Expand Up @@ -7521,13 +7544,16 @@ void ParseEngine<EventHandler>::_handle_unk()
if(m_doc_empty)
{
_c4dbgp("it's a map with an empty key");
const size_t startindent = m_evt_handler->m_curr->line_contents.indentation; // save
const size_t startline = m_evt_handler->m_curr->pos.line; // save
m_evt_handler->check_trailing_doc_token();
_maybe_begin_doc();
_handle_annotations_before_blck_val_scalar();
_handle_annotations_before_start_mapblck(startline);
m_evt_handler->begin_map_val_block();
_handle_annotations_and_indentation_after_start_mapblck(startindent, startline);
m_evt_handler->set_key_scalar_plain_empty();
m_doc_empty = false;
_save_indentation();
_set_indentation(startindent);
}
else
{
Expand Down
Loading

0 comments on commit 0bfb286

Please sign in to comment.