rapidyaml icon indicating copy to clipboard operation
rapidyaml copied to clipboard

emit formatting

Open biojppm opened this issue 5 years ago • 4 comments

Eg, #29 or #30 . Some thoughts:

  • implement custom EmitFormatters:
    • block (the current emitter)
    • single-line flow
    • multi-line flow
    • semi-intelligent: use a general emitter, using heuristics such as counting columns and breaking and selecting block/flow styles as appropriate (eg, nested containers)
  • implement per-node format flags? i.e., add flags forcing format selection?
  • add type-based implicit tagging? e.g. implicit tag bools so that they show as "true" rather than "1"

biojppm avatar Feb 07 '20 00:02 biojppm

Sounds good to me. Per-node flags would be very useful, since it would let users override the style and get exactly what they want. I assume there'd be three flags, block/flow/auto, with block being set by default?

Another thing that would be nice to have is the ability to enable wrapping (by setting a maximum line width). With all these additions ryml would be on par with libyaml for formatting options.

add type-based implicit tagging? e.g. implicit tag bools so that they show as "true" rather than "1"

Could this not be achieved just by changing the format overload for bool to give "true"/"false" rather than 0/1, or am I missing something?

leoetlino avatar Feb 08 '20 01:02 leoetlino

I'm using Rapid YAML for merging YAML output from clang-tidy into replacements file.

Now is following input

ReplacementText: "#ifndef E:\\SOURCE\\FINE\\COMMON\\GRAPHICSUTILS_H\n#define E:\\SOURCE\\FINE\\COMMON\\GRAPHICSUTILS_H\n\n"

emitted as

ReplacementText: |+
  #ifndef E:\SOURCE\FINE\COMMON\GRAPHICSUTILS_H
  #define E:\SOURCE\FINE\COMMON\GRAPHICSUTILS_H

It would be great to have option to output value in the original format. I assume it is not possible with current ryml version? (I will probably use some dirty hack for my use case.)

rysavyjan avatar Jan 24 '21 13:01 rysavyjan

@rysavyjan sorry for the late reply, somehow I missed your post.

You are correct; at the moment ryml does not implement this. This issue is meant to track progress in formatting, but I've not been able to do anything since I opened it. I also won't be able to come back to this in the next month or two.

biojppm avatar Feb 21 '21 18:02 biojppm

Feedback and ideas from using _WIP_STYLE_FLOW_SL:

_WIP_STYLE_FLOW_SL = c4bit(14), ///< mark container with single-line flow format (seqs as '[val1,val2], maps as '{key: val, key2: val2}')
_WIP_STYLE_FLOW_ML = c4bit(15), ///< mark container with multi-line flow format (seqs as '[val1,\nval2], maps as '{key: val,\nkey2: val2}')

// sequences should perhaps have a whitespace between each commas to behave like the map.
// ex. [val1, val2]

// Or you could have a default (white-space seperated) and a compact one
_WIP_STYLE_FLOW_SL             // [val1, val2]
_WIP_STYLE_FLOW_SL_COMPACT     // [val1,val2]

captain-yoshi avatar Jul 31 '22 05:07 captain-yoshi