Skip to content

Commit

Permalink
support : and ? in flow context as per updated YAML spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Herringway committed Oct 6, 2023
1 parent d009f15 commit 8b18bb0
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
4 changes: 0 additions & 4 deletions docs/articles/spec_differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ Differences that can cause valid YAML documents not to load:
- No support for byte order marks and multiple Unicode encodings in a
stream.

- Plain scalars in flow context cannot contain `,`, `:` and `?`. This
might change with `:` in the future. See
<http://pyyaml.org/wiki/YAMLColonInFlowContext> for details.

- The specification does not restrict characters for anchors and
aliases. This may lead to problems, for instance, the document:

Expand Down
12 changes: 2 additions & 10 deletions source/dyaml/scanner.d
Original file line number Diff line number Diff line change
Expand Up @@ -1541,23 +1541,15 @@ struct Scanner
const cNext = reader_.peek(length + 1);
if(c.isWhiteSpace ||
(flowLevel_ == 0 && c == ':' && cNext.isWhiteSpace) ||
(flowLevel_ > 0 && c.among!(',', ':', '?', '[', ']', '{', '}')))
(flowLevel_ > 0 && c == ':' && (cNext.isWhiteSpace || cNext.among!(',', '[', ']', '{', '}'))) ||
(flowLevel_ > 0 && c.among!(',', '[', ']', '{', '}')))
{
break;
}
++length;
c = cNext;
}

// It's not clear what we should do with ':' in the flow context.
enforce(flowLevel_ == 0 || c != ':' ||
reader_.peek(length + 1).isWhiteSpace ||
reader_.peek(length + 1).among!(',', '[', ']', '{', '}'),
new ScannerException("While scanning a plain scalar", startMark,
"found unexpected ':' . Please check " ~
"http://pyyaml.org/wiki/YAMLColonInFlowContext for details.",
reader_.mark));

if(length == 0) { break; }

allowSimpleKey_ = false;
Expand Down
3 changes: 3 additions & 0 deletions test/data/colon-in-flow-context.canonical
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%YAML 1.1
---
"foo:bar":
3 changes: 3 additions & 0 deletions test/data/colon-in-flow-context.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%YAML 1.1
---
{ foo:bar }
1 change: 0 additions & 1 deletion test/data/colon-in-flow-context.loader-error

This file was deleted.

3 changes: 3 additions & 0 deletions test/data/question-mark-in-flow-context.canonical
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%YAML 1.1
---
"foo?bar":
3 changes: 3 additions & 0 deletions test/data/question-mark-in-flow-context.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%YAML 1.1
---
{ foo?bar }

0 comments on commit 8b18bb0

Please sign in to comment.