Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emitting styles (and removing extra new lines) #29

Closed
leoetlino opened this issue Jan 22, 2020 · 3 comments
Closed

Emitting styles (and removing extra new lines) #29

leoetlino opened this issue Jan 22, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@leoetlino
Copy link
Contributor

leoetlino commented Jan 22, 2020

Is it possible to configure the emitting style (block/flow and newlines)?

Currently, I have a bunch of existing YAML documents that look like this:

enemy:
- actors:
  - {name: Enemy_Bokoblin_Junior, value: 4.0} 
  - {name: Enemy_Bokoblin_Middle, value: 16.0} 
  - {name: Enemy_Bokoblin_Senior, value: 32.0} 
  - {name: Enemy_Bokoblin_Dark, value: 48.0} 
  species: BokoblinSeries 
# ...

Nice and readable, with the flow (inline) style being used for simple maps that don't contain nested maps (which is the PyYAML default).

Emitting the same document with ryml currently results in the following:

enemy:
  -
    actors:
      -
        name: Enemy_Bokoblin_Junior
        value: 4
      -
        name: Enemy_Bokoblin_Middle
        value: 16
      -
        name: Enemy_Bokoblin_Senior
        value: 32
      -
        name: Enemy_Bokoblin_Dark
        value: 48
    species: BokoblinSeries

which isn't that bad but it's comparatively harder to read and it's also a bit too long.

So to get back to the questions:

  • Is it possible to get rid of the new line that is emitted for maps that are sequence items? For some reason, this only affects maps that are sequence items.

  • Does ryml make it possible to set the flow style (block/inline) for maps and sequences? I was unable to find any such functionality in the API but it's possible I've missed something.

@biojppm
Copy link
Owner

biojppm commented Jan 25, 2020

Does ryml make it possible to set the flow style (block/inline) for maps and sequences? I was unable to find any such functionality in the API but it's possible I've missed something.

Sorry, there's no such functionality.

Is it possible to get rid of the new line that is emitted for maps that are sequence items? For some reason, this only affects maps that are sequence items.

Absolutely, the newline shouldn't be there. So that's a bug indeed. I was under the impression that this was ok, but currently there is no unit test covering formatting, as the focus has been on semantic correctness. I'll have to verify what's going on. I'll start by adding some unit tests for formatting, and looking at the current emitter code (which is admittedly not very nice) to verify how to refactor to make it easier to customize emission.

@biojppm biojppm added the bug Something isn't working label Jan 27, 2020
biojppm added a commit that referenced this issue Feb 7, 2020
Simplified the cyclomatic complexity of the emitter code, which was
needlessly complex.
@biojppm
Copy link
Owner

biojppm commented Feb 7, 2020

@leoetlino The bug causing the newline was fixed. I'm going to open a separate issue to track emit formatting.

@biojppm
Copy link
Owner

biojppm commented Feb 8, 2020

@leoetlino I opened #37 to start work on emit formatting. You seem to have some ideas (or requirements) and I'd be happy to have your input there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants