ocaml-toml / To.ml

OCaml library for TOML
https://ocaml-toml.github.io/To.ml
Other
82 stars 20 forks source link

Simplify Key signature #64

Closed seliopou closed 3 years ago

seliopou commented 4 years ago

They signature is currently:

  module Key : sig
    type t
    exception Bad_key of string
    val compare : t -> t -> int
    val bare_key_of_string : string -> t
    val quoted_key_of_string : string -> t
    val to_string : t -> string
  end 

From what I gather the bare key constructor is duplicating validation that the parser has already done. And in fact the quoting of the string only seems to be a concern when serializing the string in order to generate valid TOML.

How would maintainers feel about changing the signature to look like:

  module Key : sig
    type t
    val compare : t -> t -> int
    val of_string : string -> t
    val to_string : t -> string
  end 

Any string is a valid key so of_string will accept it, but on the way out of to_string, the string will have to be quoted and/or escaped.

I can take a crack at this if it's a welcomed change.

seliopou commented 4 years ago

Here's what I had in mind: 88c327c284c529337f222243badc2e76fa408ffb.

zapashcanon commented 3 years ago

Fixed in cbceeff04ce305c233670d7691d02693dc6470aa.