From 8b18bb0c6c41306278beebcd9b98fe8433661b91 Mon Sep 17 00:00:00 2001 From: Cameron Ross Date: Wed, 27 Sep 2023 00:39:19 -0300 Subject: [PATCH] support : and ? in flow context as per updated YAML spec --- docs/articles/spec_differences.md | 4 ---- source/dyaml/scanner.d | 12 ++---------- test/data/colon-in-flow-context.canonical | 3 +++ test/data/colon-in-flow-context.data | 3 +++ test/data/colon-in-flow-context.loader-error | 1 - test/data/question-mark-in-flow-context.canonical | 3 +++ test/data/question-mark-in-flow-context.data | 3 +++ 7 files changed, 14 insertions(+), 15 deletions(-) create mode 100644 test/data/colon-in-flow-context.canonical create mode 100644 test/data/colon-in-flow-context.data delete mode 100644 test/data/colon-in-flow-context.loader-error create mode 100644 test/data/question-mark-in-flow-context.canonical create mode 100644 test/data/question-mark-in-flow-context.data diff --git a/docs/articles/spec_differences.md b/docs/articles/spec_differences.md index 93cf0385..a6693516 100644 --- a/docs/articles/spec_differences.md +++ b/docs/articles/spec_differences.md @@ -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 - for details. - - The specification does not restrict characters for anchors and aliases. This may lead to problems, for instance, the document: diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index 0a285236..ffd905ba 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -1541,7 +1541,8 @@ 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; } @@ -1549,15 +1550,6 @@ struct Scanner 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; diff --git a/test/data/colon-in-flow-context.canonical b/test/data/colon-in-flow-context.canonical new file mode 100644 index 00000000..6c841574 --- /dev/null +++ b/test/data/colon-in-flow-context.canonical @@ -0,0 +1,3 @@ +%YAML 1.1 +--- +"foo:bar": diff --git a/test/data/colon-in-flow-context.data b/test/data/colon-in-flow-context.data new file mode 100644 index 00000000..95aa36c4 --- /dev/null +++ b/test/data/colon-in-flow-context.data @@ -0,0 +1,3 @@ +%YAML 1.1 +--- +{ foo:bar } diff --git a/test/data/colon-in-flow-context.loader-error b/test/data/colon-in-flow-context.loader-error deleted file mode 100644 index 13d50875..00000000 --- a/test/data/colon-in-flow-context.loader-error +++ /dev/null @@ -1 +0,0 @@ -{ foo:bar } diff --git a/test/data/question-mark-in-flow-context.canonical b/test/data/question-mark-in-flow-context.canonical new file mode 100644 index 00000000..f717239c --- /dev/null +++ b/test/data/question-mark-in-flow-context.canonical @@ -0,0 +1,3 @@ +%YAML 1.1 +--- +"foo?bar": diff --git a/test/data/question-mark-in-flow-context.data b/test/data/question-mark-in-flow-context.data new file mode 100644 index 00000000..d434a302 --- /dev/null +++ b/test/data/question-mark-in-flow-context.data @@ -0,0 +1,3 @@ +%YAML 1.1 +--- +{ foo?bar }