Giter Site home page Giter Site logo

cies / htoml Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 13.0 326 KB

TOML file format parser in Haskell

Home Page: https://hackage.haskell.org/package/htoml

License: Other

Haskell 5.17% HTML 94.77% Shell 0.05%
stackage aeson haskell parsec parser toml ghc hackage json

htoml's People

Contributors

cies avatar erebe avatar gurkenglas avatar huwcampbell avatar seliopou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

htoml's Issues

Suggestion for Node's data constructors

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 Vectors instead of lists. This tends to be more performant, although I don't have any benchmarks to verify this.

Validation

How is one suppose to validate the toml file? Maybe, as recommendation, there is a library that goes well with htoml?

fails to install with stackage lts-3.0 / ghc 7.10

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

fails to build with aeson-2.0

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                          >     |                       ^^^^^^^^^^^^^^

Changes to the Types, and therefor the public API

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:

  • What is a VITable, how is it different from a VTable, and why do we need it?
  • The VArray can now contain anything of type Node; I guess in my old data structure I tried to make sure that VArrays 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!

Bug with nested tables and arrays

[[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'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.