@@ -802,7 +802,7 @@ csubstr ParseEngine<EventHandler>::_scan_tag(csubstr *orig)
802802 if (!t.begins_with (" !<" ))
803803 {
804804 _c4dbgp (" begins with '!'" );
805- _set_first (t, t.first_of (" ,]} \t " ));
805+ _set_first (t, t.first_of (" ,\t " ));
806806 if (C4_UNLIKELY (t.first_of (" [{" ) != npos))
807807 _c4err (" invalid tag" );
808808 _line_progressed (t.len );
@@ -4296,6 +4296,10 @@ void ParseEngine<EventHandler>::_add_annotation(Annotation *C4_RESTRICT dst, csu
42964296{
42974297 _c4dbgpf (" store annotation[{}]: '{}' indentation={} line={}" , dst->num_entries , str.str ? str : csubstr (" (arena full)" ), indentation, line);
42984298 _RYML_ASSERT_PARSE_ (m_evt_handler->m_stack .m_callbacks , dst->num_entries < C4_COUNTOF (dst->annotations ), m_evt_handler->m_curr ->pos ); // NOLINT(bugprone-sizeof-expression)
4299+ if (C4_UNLIKELY (dst->num_entries && dst->annotations [0 ].line == line))
4300+ {
4301+ _c4err (" parse error" );
4302+ }
42994303 dst->annotations [dst->num_entries ].str = str;
43004304 dst->annotations [dst->num_entries ].indentation = indentation;
43014305 dst->annotations [dst->num_entries ].line = line;
@@ -4308,6 +4312,10 @@ void ParseEngine<EventHandler>::_add_annotation(Annotation *C4_RESTRICT dst, csu
43084312{
43094313 _c4dbgpf (" store annotation[{}]: '{}'->'{}' indentation={} line={}" , dst->num_entries , orig, str.str ? str : csubstr (" (arena full)" ), indentation, line);
43104314 _RYML_ASSERT_PARSE_ (m_evt_handler->m_stack .m_callbacks , dst->num_entries < C4_COUNTOF (dst->annotations ), m_evt_handler->m_curr ->pos ); // NOLINT(bugprone-sizeof-expression)
4315+ if (C4_UNLIKELY (dst->num_entries && dst->annotations [0 ].line == line))
4316+ {
4317+ _c4err (" parse error" );
4318+ }
43114319 dst->annotations [dst->num_entries ].str = str;
43124320 dst->annotations [dst->num_entries ].indentation = indentation;
43134321 dst->annotations [dst->num_entries ].line = line;
@@ -4337,7 +4345,7 @@ bool ParseEngine<EventHandler>::_handle_annotations_before_unexpected_flow_token
43374345 }
43384346 else
43394347 {
4340- _c4err (" too many tags" ); // LCOV_EXCL_LINE
4348+ _c4err (" too many tags" );
43414349 }
43424350 }
43434351 if (m_pending_anchors.num_entries )
@@ -4350,7 +4358,7 @@ bool ParseEngine<EventHandler>::_handle_annotations_before_unexpected_flow_token
43504358 }
43514359 else
43524360 {
4353- _c4err (" too many anchors" ); // LCOV_EXCL_LINE
4361+ _c4err (" too many anchors" );
43544362 }
43554363 }
43564364 m_evt_handler->set_key_scalar_plain_empty ();
@@ -8159,8 +8167,7 @@ void ParseEngine<EventHandler>::_handle_unk_get_first_non_pending_token_pos(csub
81598167 _c4assert (second.is_sub (s.sub (pos)));
81608168 csubstr spos = s.sub (pos);
81618169 size_t more = spos.first_not_of (" \t " );
8162- if (more == npos)
8163- more = spos.len ;
8170+ _c4assert (more != npos); // because the annotations are on the same line
81648171 _c4dbgpf (" runk: next nonspace: {}" , pos + more);
81658172 pos += more;
81668173 _c4dbgpf (" runk: after skip annotation whitespace: pos={} {}" , pos, _prs (s.sub (pos), true ));
@@ -8194,12 +8201,11 @@ uint32_t ParseEngine<EventHandler>::_get_annotations_same_line(csubstr token_sou
81948201 total += !!valid_if_same_line (&m_pending_anchors.annotations [i]);
81958202 for (size_t i = 0 ; i < m_pending_tags.num_entries ; ++i)
81968203 total += !!valid_if_same_line (&m_pending_tags.annotations [i]);
8197- if (total == 0 )
8198- {
8199- _c4dbgp (" no annotations on same line" );
8200- return 0 ;
8201- }
82028204 _c4dbgpf (" {} annotations on same line" , total);
8205+ _c4assert (total > 0 ); // because this function is only called
8206+ // while not at the first token. That
8207+ // means we must have same-line
8208+ // annotations.
82038209 auto get_first_on_same_line = [this ](EntryPtr not_this_one){
82048210 for (size_t i = 0 ; i < m_pending_anchors.num_entries ; ++i)
82058211 if (&m_pending_anchors.annotations [i] != not_this_one
@@ -8209,7 +8215,7 @@ uint32_t ParseEngine<EventHandler>::_get_annotations_same_line(csubstr token_sou
82098215 if (&m_pending_tags.annotations [i] != not_this_one
82108216 && m_pending_tags.annotations [i].line == m_evt_handler->m_curr ->pos .line )
82118217 return &m_pending_tags.annotations [i];
8212- return (EntryPtr)nullptr ;
8218+ return (EntryPtr)nullptr ; // LCOV_EXCL_LINE
82138219 };
82148220 _c4assert (total >= 1 );
82158221 // assign to first
@@ -8218,8 +8224,7 @@ uint32_t ParseEngine<EventHandler>::_get_annotations_same_line(csubstr token_sou
82188224 _c4dbgpf (" first annotation: {} indent={} line={}" , first->str , first->indentation , first->line );
82198225 if (total > 1 )
82208226 {
8221- if (C4_UNLIKELY (total > 2 ))
8222- _c4err (" too many anchors/tags" );
8227+ _c4assert (total == 2 );
82238228 // assign to second
82248229 second = get_first_on_same_line (first);
82258230 _c4assert (second);
0 commit comments