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

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 19:33:29 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))
     return scanBlockEntry();
 
-  if (*Current == '?' && (FlowLevel || isBlankOrBreak(Current + 1)))
+  if (*Current == '?' && (Current + 1 == End || isBlankOrBreak(Current + 1)))
----------------
akirchhoff-modular wrote:

I added `YAMLParser.ParsesComplexMap` to test that this continues to allow valid YAML documents containing maps with complex keys outside of flow. The test `YAMLParser.ParsesPlainScalars` (specifically, `Plain scalar beginning with a question mark in flow sequence: [ ?hello ]`) tests the opposite, that we return `false` in appropriate cases.

I also attempted to add a test case to make sure the scanner tokenized a complex-key inside of flow correctly, but unfortunately I believe this hits a bug in the parsing logic outside of the scanner. I believe this is outside the scope of this PR to fix.

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


More information about the llvm-commits mailing list