Skip to content

Commit

Permalink
Fixing some YAML corner cases
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew A Johnson <[email protected]>
  • Loading branch information
matajoh committed Sep 10, 2024
1 parent 467157a commit 373ee94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions parsers/yaml/parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ namespace trieste
m.add(SingleQuote);
},

R"("[^"]*\n\-\-\-[^"]*")" >>
[](auto& m) {
m.error("Invalid document marker in double quoted scalar");
},

// Double-quote. NB this captures absolutely everything at this stage,
// and is cleaned up in the quotes() pass, because the semantics of
// quoted strings are too complex to handle in this parser.
Expand Down
17 changes: 9 additions & 8 deletions parsers/yaml/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ namespace
}

auto view = line->location().view();
if (view.find("---") != std::string::npos)
{
return "Invalid element: ---";
}

for (std::size_t i = 0; i < view.size() - 1; ++i)
{
Expand Down Expand Up @@ -1050,8 +1046,8 @@ namespace
[](Match&) -> Node { return nullptr; },

In(DocumentGroup) * T(DocumentStart)[DocumentStart] * ~T(NewLine) *
~T(Whitespace) * T(Comment) * T(NewLine) >>
[](Match& _) { return _(DocumentStart); },
~T(Whitespace) * T(Comment) * T(NewLine)[NewLine] >>
[](Match& _) { return Seq << _(DocumentStart) << _(NewLine); },

In(StreamGroup) *
(DirectiveToken[Head] * DirectiveToken++[Tail] *
Expand Down Expand Up @@ -1288,10 +1284,15 @@ namespace
return FlowSequenceItem << (FlowGroup << _(Head) << _[Tail]);
},

In(FlowSequence) *
(T(FlowSequenceItem)[FlowSequenceItem] * T(Comment) *
T(Comment)++) >>
[](Match& _) { return _(FlowSequenceItem); },

In(FlowMapping) *
(T(FlowKeyValue)
<< (T(Key) * FlowToken++[Key] * T(Colon) * FlowToken++[Value] *
End)) >>
<< (T(Key) * FlowToken++[Key] * ~T(Comment) * T(Colon) *
FlowToken++[Value] * End)) >>
[](Match& _) {
return FlowMappingItem << (FlowGroup << _[Key])
<< (FlowGroup << _[Value]);
Expand Down

0 comments on commit 373ee94

Please sign in to comment.