Giter Club home page Giter Club logo

cabal-syntax-json's Introduction

Cabal-syntax-json

An experiment to use Cabal-syntax's FieldGrammar to define a JSON syntax for cabal files.

Example

Rendering of template-haskell-2.19.0.0

{
  "bug-reports": "https://gitlab.haskell.org/ghc/ghc/issues/new",
  "build-type": "Simple",
  "cabal-version": ">=1.10",
  "category": "Template Haskell",
  "description": "This package provides modules containing facilities for manipulating\nHaskell source code using Template Haskell.\n\nSee <http://www.haskell.org/haskellwiki/Template_Haskell> for more\ninformation.",
  "extra-source-files": [
    "changelog.md"
  ],
  "flags": {
    "vendor-filepath": {
      "default": false,
      "description": "Vendor the dependency on filepath",
      "manual": true
    }
  },
  "library": {
    "build-depends": [
      {
        "if": {
          "not": {
            "os": "vendor-filepath"
          }
        },
        "then": [
          "filepath"
        ]
      },
      [
        "base >=4.11 && <4.18",
        "ghc-boot-th ==9.4.1",
        "ghc-prim",
        "pretty >=1.1 && <1.2"
      ]
    ],
    "default-extensions": [
      {
        "if": {
          "os": "vendor-filepath"
        },
        "then": [
          "ImplicitPrelude"
        ]
      },
      [
        "NoImplicitPrelude"
      ]
    ],
    "default-language": [
      "Haskell2010"
    ],
    "exposed-modules": [
      [
        "Language.Haskell.TH",
        "Language.Haskell.TH.Lib",
        "Language.Haskell.TH.Ppr",
        "Language.Haskell.TH.PprLib",
        "Language.Haskell.TH.Quote",
        "Language.Haskell.TH.Syntax",
        "Language.Haskell.TH.LanguageExtensions",
        "Language.Haskell.TH.CodeDo",
        "Language.Haskell.TH.Lib.Internal"
      ]
    ],
    "ghc-options": [
      [
        "-Wall",
        "-this-unit-id",
        "template-haskell"
      ]
    ],
    "hs-source-dirs": [
      {
        "if": {
          "not": {
            "os": "vendor-filepath"
          }
        },
        "then": [
          "."
        ]
      },
      {
        "if": {
          "os": "vendor-filepath"
        },
        "then": [
          "./vendored-filepath",
          "."
        ]
      }
    ],
    "other-extensions": [
      [
        "BangPatterns",
        "CPP",
        "DefaultSignatures",
        "DeriveDataTypeable",
        "DeriveGeneric",
        "FlexibleInstances",
        "RankNTypes",
        "RoleAnnotations",
        "ScopedTypeVariables"
      ]
    ],
    "other-modules": [
      {
        "if": {
          "os": "vendor-filepath"
        },
        "then": [
          "System.FilePath",
          "System.FilePath.Posix",
          "System.FilePath.Windows"
        ]
      },
      [
        "Language.Haskell.TH.Lib.Map"
      ]
    ]
  },
  "license": "BSD3",
  "license-file": [
    "LICENSE"
  ],
  "maintainer": "[email protected]",
  "name": "template-haskell",
  "source-repos": [
    {
      "location": "https://gitlab.haskell.org/ghc/ghc.git",
      "subdir": "libraries/template-haskell",
      "type": {
        "contents": "Git",
        "tag": "KnownRepoType"
      }
    }
  ],
  "synopsis": "Support library for Template Haskell",
  "version": "2.19.0.0"
}

Notes

  • Given this uses Cabal-syntax machinery, I don't have to care about the specific fields. The only concern is the structure.
  • I should write the other direction (parsing from json) too, and see if they round-trip.
  • If you notice the example above, I am doing something with the conditionals, pushing them all the way down into the field value. This representation felt more natural in json but it might make parsing more complicated.
  • Of course, I defined a bunch of orphan instances, beware!

Author

Andrea Bedini ([email protected])

cabal-syntax-json's People

Contributors

andreabedini avatar

Watchers

 avatar  avatar  avatar

cabal-syntax-json's Issues

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.