biojppm / rapidyaml

Rapid YAML - a library to parse and emit YAML, and do it fast.
MIT License
569 stars 97 forks source link

emit formatting #37

Open biojppm opened 4 years ago

biojppm commented 4 years ago

Eg, #29 or #30 . Some thoughts:

leoetlino commented 4 years ago

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?

rysavyjan commented 3 years ago

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.)

biojppm commented 3 years ago

@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.

captain-yoshi commented 2 years ago

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]