Skip to content

Consider keeping floats and ints as strings, and not parsing them #135

@nik-rev

Description

@nik-rev

Suggestions:

  • Instead of storing KdlValue::Float as f64, store it as String
  • Instead of storing KdlValue::Integer as i128, store it as { repr: String, radix: u32 } where the radix can only be 2, 8, 10 or 16

This should make the library both simpler implementation-wise, but also more versatile

Since kdl parser can be used for any purpose, it should be up to the user of the crate to decide how to parse the values

This would improve performance because it would remove an unnecessary step in certain situations: The KDL library converts the int/float to a string, but then we have to .to_string() it back.

There is no logical distinction in KDL between real numbers, integers, and floating point numbers. It's up to individual implementations to determine how to represent KDL numbers.
from the spec

Given the above, i should be able to represent an i1024 or f512 in KDL by using the kdl crate - or any sort of number, but this is currently impossible

One difficulty with this approach is: What do we do about #inf, #-inf and #nan?. Personally, I think they could be represented by adding 2 new variants to KdlValue - KdlValue::Inf { is_positive: bool } and KdlValue::NaN.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions