All Projects → esmolanka → sexp-grammar

esmolanka / sexp-grammar

Licence: other
Invertible parsing for S-expressions

Programming Languages

haskell
3896 projects
Lex
420 projects
Yacc
648 projects
shell
77523 projects
Nix
1067 projects

Projects that are alternatives of or similar to sexp-grammar

dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (+42.86%)
Mutual labels:  serialization, parsing, deserialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+642.86%)
Mutual labels:  serialization, deserialization
Dart Json Mapper
Serialize / Deserialize Dart Objects to / from JSON
Stars: ✭ 206 (+635.71%)
Mutual labels:  serialization, deserialization
sexpresso
An s-expression library for C++
Stars: ✭ 41 (+46.43%)
Mutual labels:  serialization, s-expression
Orjson
Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Stars: ✭ 2,595 (+9167.86%)
Mutual labels:  serialization, deserialization
Aspjson
A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
Stars: ✭ 165 (+489.29%)
Mutual labels:  serialization, deserialization
Jsonapi Rb
Efficiently produce and consume JSON API documents.
Stars: ✭ 219 (+682.14%)
Mutual labels:  serialization, deserialization
Pyjson tricks
Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Stars: ✭ 131 (+367.86%)
Mutual labels:  serialization, deserialization
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (+53.57%)
Mutual labels:  serialization, deserialization
sqlathanor
Serialization / De-serialization support for the SQLAlchemy Declarative ORM
Stars: ✭ 105 (+275%)
Mutual labels:  serialization, deserialization
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-14.29%)
Mutual labels:  serialization, deserialization
Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (+392.86%)
Mutual labels:  serialization, deserialization
Deku
Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Stars: ✭ 136 (+385.71%)
Mutual labels:  serialization, deserialization
Marshmallow Jsonapi
JSON API 1.0 (https://jsonapi.org/) formatting with marshmallow
Stars: ✭ 203 (+625%)
Mutual labels:  serialization, deserialization
Flatsharp
Fast, idiomatic C# implementation of Flatbuffers
Stars: ✭ 133 (+375%)
Mutual labels:  serialization, deserialization
Schematics
Project documentation: https://schematics.readthedocs.io/en/latest/
Stars: ✭ 2,461 (+8689.29%)
Mutual labels:  serialization, deserialization
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (+175%)
Mutual labels:  serialization, deserialization
Yaxlib
Yet Another XML Serialization Library for the .NET Framework and .NET Core
Stars: ✭ 124 (+342.86%)
Mutual labels:  serialization, deserialization
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (+367.86%)
Mutual labels:  serialization, deserialization
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+764.29%)
Mutual labels:  serialization, deserialization

Build

sexp-grammar

Library of invertible parsing combinators for S-expressions. The combinators define primitive grammars and ways to compose them. A grammar constructed with these combinators can be run in two directions: parsing from S-expressions direction (forward) and serialising to S-expressions direction (backward).

The approach used in sexp-grammar is inspired by the paper Invertible syntax descriptions: Unifying parsing and pretty printing and a similar implementation of invertible grammar approach for JSON, library by Martijn van Steenbergen called JsonGrammar2.

Let's have a look at sexp-grammar at work:

{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators     #-}

import GHC.Generics
import Data.Text (Text)
import Language.SexpGrammar
import Language.SexpGrammar.Generic

data Person = Person
  { pName    :: Text
  , pAddress :: Text
  , pAge     :: Maybe Int
  } deriving (Show, Generic)

instance SexpIso Person where
  sexpIso = with $ \person ->  -- Person is isomorphic to:
    list (                           -- a list with
      el (sym "person") >>>          -- a symbol "person",
      el string         >>>          -- a string, and
      props (                        -- a property-list with
        "address" .:  string >>>     -- a keyword :address and a string value, and
        "age"     .:? int))  >>>     -- an optional keyword :age with int value.
    person

We've just defined an isomorphism between S-expression representation and Haskell data record representation of the same information.

ghci> :set -XTypeApplications
ghci> import Language.SexpGrammar
ghci> import Data.ByteString.Lazy.Char8 (pack, unpack)
ghci> person <- either error return . decode @Person . pack =<< getLine
(person "John Doe" :address "42 Whatever str." :age 25)
ghci> person
Person {pName = "John Doe", pAddress = "42 Whatever str.", pAge = Just 25}
ghci> putStrLn (either id unpack (encode person))
(person "John Doe" :address "42 Whatever str." :age 25)

See more examples in the repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].