[PATCH] D102590: [YAMLParser] Add multi-line literal folding support

Scott Linder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 20 13:08:04 PDT 2021


scott.linder added a comment.

So, I tried to work out the behavior of the spec parser, and I think my understanding of empty is faulty. Compare http://ben-kiki.org/ypaste/data/26953/index.html (all content is non-space characters) with http://ben-kiki.org/ypaste/data/26954/index.html (the middle line content is a single space).

The single space is still considered content (what I would expect), but somehow prevents the folding from occuring (not what I would expect). I think this lines up with @fodinabor definition of `isLineEmpty`? In that case, I think my suggestion would be:

  if (LineStart != Current) {
    if (LineBreaks && IsFolded) {
      // The folded style "folds" any single line break between content into a single space, except when that
      // content is "empty" (only contains whitespace) in which case the line break is left as-is.
      if (LineBreaks == 1) {
        Str.append(LineBreaks, isLineEmpty(StringRef(LineStart, Current-LineStart)) ? '\n' : ' ');
      }
      // If we saw a single line break, we are completely replacing it and so want `LineBreaks == 0`.
      // Otherwise this decrement accounts for the fact that the first line break is "trimmed", only
      // being used to signal a sequence of line breaks which should not be folded.
      LineBreaks--;
    }
    Str.append(LineBreaks, '\n');
    Str.append(StringRef(LineStart, Current - LineStart));
    LineBreaks = 0;
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102590/new/

https://reviews.llvm.org/D102590



More information about the llvm-commits mailing list