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 SectionSpecs type only supports an Applicative instance.

demoSpec :: ValueSpecs (Maybe [Rational], Maybe Bool, Maybe T.Text, [(Int,Int)])
demoSpec = sectionsSpec "top-level configuration" $
  do nums <- optSection' "numbers" (oneOrList valuesSpec)
             "Try out the number syntax"
     bool <- optSection' "yes-or-no" yesOrNoSpec
             "Using atoms as enumerations"
     str  <- optSection "string"
             "Strings use Haskell syntax"
     xs   <- reqSection' "coordinates" (oneOrList nestedMapSpec)
             "Example required section of a nested map"
     return (nums,bool,str,xs)

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
Parse