ValveValueKeyvalue: A Valve Value-keyvalue parser for Haskell made with Parsec.

[ keyvalue, library, mit, parsing, source, valve ] [ Propose Tags ] [ Report a vulnerability ]

This is a package made to parse Valve's value-keyvalue format, common in Source Engine games. Valve value-keyvalue files may take the extensions ".pop" or ".vtf". The main module is Text.ValveVKV. The main function you will be using is parseValveVKV.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0.0, 1.0.1.0, 1.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.14.2.0 && <4.18), parsec (>=3.1.14 && <3.2) [details]
Tested with ghc ==8.10.5 || ==8.10.7
License MIT
Author Bernardo Gomes Negri
Maintainer b.gomes.negri@gmail.com
Revised Revision 1 made by berna at 2022-10-01T00:01:15Z
Category Parsing
Home page https://github.com/BernardoGomesNegri/ValveValueKeyvalue
Bug tracker https://github.com/BernardoGomesNegri/ValveValueKeyvalue/issues
Source repo head: git clone https://github.com/BernardoGomesNegri/ValveValueKeyvalue
Uploaded by berna at 2021-10-18T16:44:33Z
Distributions
Downloads 406 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for ValveValueKeyvalue-1.1.0.0

[back to package description]

ValveValueKeyvalue

A Haskell parser for Valve's value-keyvalue format. The main function is "parseValveVKV" in the module Text.ValveVKV. You can see it only parses to types that are part of the typeclass ValveVKV. For example, if you have this type: data My = My {name :: String, count :: Int} Then the instance looks like this:

instance ValveVKV My where
    fromValveVKV this _ =
        My <$> this ^: "name" <*> this .: "count"

The first parameter is the entry that should be turned into your type, and the 2nd one is the parent of that entry. The ^: operator receives an entry on the left side and a string on the right side. It tries to find the string subentry named the string inside the entry you gave in on the left. The .: operator is similar, but can return any type, not just string.

The entry type ValveKeyValueEntry has 3 constructors. KVObject, which has a Pair of a KeyValueEntry list. KVInt, which has a Pair of Int and KVString, which has a pair of string. The Pair type itself is one constructor of a string and the type parameter.

So you can now run

a :: IO (Either String My)
a = do
    contents <- readFile "file.txt"
    return $ parseValveVKV contents

This will open file "file.txt", read its contents and return the "My" type.

Avaliable on Hackage