Skip to content

Preserving scalar type information when emitting  #30

@leoetlino

Description

@leoetlino

(I hope you'll forgive me for opening three issues in a row...)

Consider the following document:

- actorType: WeaponSmallSword
  actors:
  - {name: Weapon_Sword_031, plus: -1, value: 15.0}
  - {name: Weapon_Sword_031, plus: 0, value: 20.0}
  - {name: Weapon_Sword_031, plus: 1, value: 24.0}
  not_rank_up: false
  series: DragonRoostSeries
# ...

Emitting it with ryml gives the following:

  -
    actorType: WeaponSmallSword
    actors:
      -
        name: Weapon_Sword_031
        plus: '-1'
        value: 15
      -
        name: Weapon_Sword_031
        plus: 0
        value: 20
      -
        name: Weapon_Sword_031
        plus: 1
        value: 24
    not_rank_up: 0
    series: DragonRoostSeries

Ignoring the strange newlines and the different flow styles (#29), something that's problematic for loading ryml-emitted documents with PyYAML -- or any other parser that relies on detecting types -- is that value types don't seem to be preserved.

In particular, -1 (an integer) gets turned into '-1', which would cause any such parser to load the value as a string and not as an integer.

The value that is associated with not_rank_up, which is supposed to be a boolean, seems to have been implicitly converted to an integer (0). Other than looking somewhat worse, this causes parsers to load it as an integer and not as a boolean.

Something similar happens for floats that also happen to be integers; 24.0 is emitted as 24, which causes the value to be loaded as an integer and not as a float.

I've tried overloading the c4::yml::write function for bool, but that doesn't seem to work as it's not called. More generally, do you have any ideas or suggestions for getting output that matches the existing document?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions