[llvm] [YAMLParser] Improve plain scalar spec compliance (PR #68946)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 19:33:30 PDT 2023


================
@@ -1848,13 +1869,15 @@ bool Scanner::fetchMoreTokens() {
   if (*Current == ',')
     return scanFlowEntry();
 
-  if (*Current == '-' && isBlankOrBreak(Current + 1))
+  if (*Current == '-' && (isBlankOrBreak(Current + 1) || Current + 1 == End))
----------------
akirchhoff-modular wrote:

Sure. This was already partially covered by `YAMLIO.TestScannerNoNullSequenceOfNull`, but that checks only that a parse of the document `-` succeeds, not what it actually parses to. I have added a redundant test `In block sequence hitting EOF` to `YAMLParser.HandlesEndOfFileGracefully` that is equivalent to `YAMLIO.TestScannerNoNullSequenceOfNull`, as well as another test `YAMLParser.BlockSequenceEOF` that checks that the result is a sequence.

As background, prior to this PR, we mis-parsed a document consisting of a single hyphen as a plain literal. After fixing plain literals to be compliant with the spec, neither plain literals nor block entries wanted to claim this character, resulting in "Unrecognized character while tokenizing." This broke the `YAMLIO.TestScannerNoNullSequenceOfNull` test, so I had to fix block entry parsing here to ensure that we still succeed parsing (this time with the right result as well).

https://github.com/llvm/llvm-project/pull/68946


More information about the llvm-commits mailing list