Config-schema example

This page demonstrates the config-value language and the config-schema schema library. The source code for this project is available as config-app. Try editing the configuration file below!

This demonstration is implemented in Haskell and is compiled to JavaScript using GHCJS.

Schema source code

He's an example of a schema used to specify what sorts of configuration files this demo expects and how they will be processed into a Haskell value

Notice that this example is using the ApplicativeDo extension. The SectionsSpec type only supports an Applicative instance.

{-# Language ApplicativeDo, BlockArguments, RecordWildCards #-}

data Demo = Demo {
  numbers :: Maybe [Rational],
  yesOrNo :: Maybe Bool,
  string  :: Maybe Text,
  coords  :: [(Int, Int)]
  } deriving Show

demoSpec :: ValueSpec Demo
demoSpec = sectionsSpec "top-level configuration"
  do numbers <- optSection' "numbers" (oneOrList anySpec)
                "Try out the number syntax"
     yesOrNo <- optSection' "yes-or-no" yesOrNoSpec
                "Using atoms as enumerations"
     string  <- optSection "string"
                "Strings use Haskell syntax"
     coords  <- reqSection' "coordinates" (oneOrList nestedMapSpec)
                "Example required section of a nested map"
     return Demo{..}

nestedMapSpec :: ValueSpecs (Int, Int)
nestedMapSpec = sectionsSpec "coord"
  do x <- reqSection "x" "x coordinate"
     y <- reqSection "y" "y coordinate"
     return (x,y)

Generated documentation

This documentation was generated from the specification above when you loaded the page.

show (generateDocs demoSpec)


Interactive demonstration

Try changing this configuration file to see various error messages. The file format is described in detail in the module documentation.

Clicking parse will either generate a lexer error, parser error, schema error, or successfully extracted Haskell value.

Parser output