cies / htoml Goto Github PK
View Code? Open in Web Editor NEWTOML file format parser in Haskell
Home Page: https://hackage.haskell.org/package/htoml
License: Other
TOML file format parser in Haskell
Home Page: https://hackage.haskell.org/package/htoml
License: Other
Because of that depending on htoml brings test-related libraries like hspec and tasty into clients' dependency trees.
Also plain cabal/stack install htoml
populates your path with a confusing tests
executable.
This package looks useful, thanks. stack install failed for me:
$ stack install htoml
unbounded-delays-0.1.0.9: configure
logict-0.6.0.2: download
regex-tdfa-rc-1.1.8.3: download
unbounded-delays-0.1.0.9: build
logict-0.6.0.2: configure
logict-0.6.0.2: build
regex-tdfa-rc-1.1.8.3: configure
unbounded-delays-0.1.0.9: install
regex-tdfa-rc-1.1.8.3: build
logict-0.6.0.2: install
smallcheck-1.1.1: download
smallcheck-1.1.1: configure
smallcheck-1.1.1: build
smallcheck-1.1.1: install
regex-tdfa-rc-1.1.8.3: install
tasty-0.10.1.2: download
tasty-0.10.1.2: configure
tasty-0.10.1.2: build
tasty-0.10.1.2: install
tasty-hunit-0.9.2: download
tasty-hunit-0.9.2: configure
tasty-quickcheck-0.8.3.2: download
tasty-smallcheck-0.8.0.1: download
tasty-hunit-0.9.2: build
tasty-quickcheck-0.8.3.2: configure
tasty-hunit-0.9.2: install
tasty-quickcheck-0.8.3.2: build
tasty-smallcheck-0.8.0.1: configure
tasty-smallcheck-0.8.0.1: build
tasty-quickcheck-0.8.3.2: install
tasty-smallcheck-0.8.0.1: install
tasty-hspec-1.1: download
tasty-hspec-1.1: configure
tasty-hspec-1.1: build
tasty-hspec-1.1: install
htoml-0.1.0.2: download
htoml-0.1.0.2: configure
htoml-0.1.0.2: build
Completed all 10 actions.
-- While building package htoml-0.1.0.2 using:
/Users/simon/.stack/setup-exe-cache/setup-Simple-Cabal-1.22.4.0-x86_64-osx-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/ build --ghc-options -ddump-hi -ddump-to-file
Process exited with code: ExitFailure 1
Logs have been written to: /Users/simon/src/hledger/.stack-work/logs/htoml-0.1.0.2.log
Configuring htoml-0.1.0.2...
Building htoml-0.1.0.2...
Preprocessing library htoml-0.1.0.2...
[1 of 3] Compiling Text.Toml.Types ( src/Text/Toml/Types.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/Text/Toml/Types.o )
[2 of 3] Compiling Text.Toml.Parser ( src/Text/Toml/Parser.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/Text/Toml/Parser.o )
src/Text/Toml/Parser.hs:83:5:
Non type-variable argument in the constraint: Stream s m Char
(Use FlexibleContexts to permit this)
When checking that ‘twoChar’ has the inferred type
twoChar :: forall s u (m :: * -> *).
Stream s m Char =>
Char -> ParsecT s u m [Char]
In an equation for ‘tableArrayHeader’:
tableArrayHeader
= between (twoChar '[') (twoChar ']') headerValue
where
twoChar c = count 2 (char c)
src/Text/Toml/Parser.hs:177:25:
Couldn't match expected type ‘time-1.5.0.1:Data.Time.Format.Locale.TimeLocale’
with actual type ‘System.Locale.TimeLocale’
NB: ‘time-1.5.0.1:Data.Time.Format.Locale.TimeLocale’
is defined in ‘Data.Time.Format.Locale’ in package ‘time-1.5.0.1’
‘System.Locale.TimeLocale’
is defined in ‘System.Locale’ in package ‘old-locale-1.0.0.7’
In the first argument of ‘parseTime’, namely ‘defaultTimeLocale’
In the expression:
parseTime defaultTimeLocale (iso8601DateFormat $ Just "%X") d
The latest version of TOML is now 4.0, not 3.1 as the README states.
[[fruit.blah]]
name = "apple"
[fruit.blah.physical]
color = "red"
shape = "round"
[[fruit.blah]]
name = "banana"
[fruit.blah.physical]
color = "yellow"
shape = "bent"
From my reading of the toml spec, that should work, and give rise to the following JSON:
{
"fruit":{
"blah":[
{
"name":"apple",
"physical":{
"color":"red",
"shape":"round"
}
},
{
"name":"banana",
"physical":{
"color":"yellow",
"shape":"bent"
}
}
]
}
}
And tomlv
accepts it:
$ tomlv -types fruit.toml ~
fruit.blah ArrayHash
fruit.blah.name String
fruit.blah.physical Hash
fruit.blah.physical.color String
fruit.blah.physical.shape String
fruit.blah ArrayHash
fruit.blah.name String
fruit.blah.physical Hash
fruit.blah.physical.color String
fruit.blah.physical.shape String
However attempting to parse with htoml gives Cannot redefine table ('fruit, blah, physical'
.
htoml > Building library for htoml-1.0.0.3..
htoml > [1 of 3] Compiling Text.Toml.Types
htoml >
htoml > /tmp/stack-89f3a8327c6d452d/htoml-1.0.0.3/src/Text/Toml/Types.hs:193:23: error:
htoml > • Couldn't match type: HashMap Text Value
htoml > with: Data.Aeson.KeyMap.KeyMap Value
htoml > Expected: HashMap Text v -> Object
htoml > Actual: HashMap Text v -> HashMap Text Value
htoml > • In the second argument of ‘(.)’, namely ‘M.map toBsJSON’
htoml > In the expression: Object . M.map toBsJSON
htoml > In an equation for ‘toBsJSON’: toBsJSON = Object . M.map toBsJSON
htoml > |
htoml > 193 | toBsJSON = Object . M.map toBsJSON
htoml > | ^^^^^^^^^^^^^^
How is one suppose to validate the toml file? Maybe, as recommendation, there is a library that goes well with htoml?
Just looking at the code, your floats require a decimal point ( . character), while TOML accepts 3e9 as a valid float.
The Value
data type is currently defined:
data Node = VTable Table
| VTArray [Table]
| VString !Text
| VInteger !Int64
| VFloat !Double
| VBoolean !Bool
| VDatetime !UTCTime
| VArray [Node]
The bangs are inconsistent. I would recommend putting them on all of them, as aeson
does. Also, like in aeson, I would recommend changing VArray
and VTArray
to use Vector
s instead of lists. This tends to be more performant, although I don't have any benchmarks to verify this.
The new Node data structure as by @HuwCampbell's PR looks like this:
data Node = VTable Table
| VITable Table
| VTArray [Table]
| VString Text
| VInteger Int64
| VFloat Double
| VBoolean Bool
| VDatetime UTCTime
| VArray [Node]
While the old data struct that I came up with, is actually a combination of two data types, and looks like:
data Node = NTValue TValue
| NTable Table
| NTArray [Table]
-- [...]
data TValue = VString Text
| VInteger Int64
| VFloat Double
| VBoolean Bool
| VDatetime UTCTime
| VArray [TValue]
Now my main questions regarding the new data structure are:
VITable
, how is it different from a VTable
, and why do we need it?VArray
can now contain anything of type Node
; I guess in my old data structure I tried to make sure that VArray
s can only contain values (TValue
). I do not know if missing this bit of type safety is a real issue (I guess not). And I also wonder why we still need a difference between VTArray
and VArray
; but imagining how had it will be for modify the code in that direction hints that it is probably better this way.Please know that this is one of my first proper Haskell project, so any feedback is welcome.
If you (any reader, but @HuwCampbell in particular) have any ideas on what could be improved to get this lib to higher standard please let me know (I'd like to push for inclusion in Stackage after I got some more feedback).
Cheers!
It would be handy to have a way to serialize an existing Table.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.