htoml icon indicating copy to clipboard operation
htoml copied to clipboard

Implemented serialization using pretty print

Open barreyo opened this issue 8 years ago • 5 comments

Implemented printing of a toml using pretty printing combinators.

Using the printer on the example file produces:

> ppTable toml
[database]
enabled = true
ports = [8001, 8001, 8002]
connection_max = 5000
server = "192.168.1.1"
[servers.alpha]
dc = "eqdc10"
ip = "10.0.0.1"
[servers.beta]
dc = "eqdc10"
country = "中国"
ip = "10.0.0.2"
[owner]
bio = "GitHub Cofounder & CEO
Likes tater tots and beer."
dob = 1979-05-27T07:32:00Z
name = "Tom Preston-Werner"
organization = "GitHub"
[servers1]
[clients]
data = [["gamma", "delta"], [1, 2]]
hosts = ["alpha", "omega"]
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
color = "gray"
name = "Nail"
sku = 284758393
title = "TOML Example"

barreyo avatar Mar 10 '17 07:03 barreyo

The code is a bit messy right now, but we are working on improving it. This fixes bug #17 .

barreyo avatar Mar 10 '17 07:03 barreyo

It looks good. I want to merge it, but still feel it lacks some sort of tests. Maybe not needed for "pretty printing", but some might use it for more then that (like generating TOML files). Would it be possible to add some basic tests for this? (most features of htoml are extensively tested)

cies avatar May 31 '17 09:05 cies

I also wonder if it is not better to ship this as a separate package htoml-pretty. This seems to be a common way to add a pretty printer to a lib, as not everyone needs this functionality.

cies avatar May 31 '17 09:05 cies

I would appreciate having pretty printer for toml data type. I don't think you need to put this into separate library. As for me, having in pretty-printing is very important. Consider next scenario: you have config in TOML format, you parse it, you modify it and then you need to write it back.

chshersh avatar Nov 17 '17 01:11 chshersh

Sorry all involved. I had you wait much longer then should have. And thanks @ChShersh for chiming in. So 3 is a crowd and thus PP is now the most requested feature.

I want to pull the code in, but think it needs at least one test case. Like one complex TOML tile that gets parsed (internal representation A), PPed, that output reparsed (internal representation B). A and B need to be the same.

Bonus points for using QuickCheck to generate the initial internal state :)

TOML is quite heavily tested, and I think all code should be under some test for a library like this.

Final note: if we internally represent whitespace and comments then this feature will be more complete, but I'm ok with pulling the code in without that (it just needs a test).

cies avatar Nov 17 '17 02:11 cies