{- | Fourth assignment for IB016, semester spring 2018.
= Task overview
Your task is to implement the full JSON parser according to the format
specification provided at . Use @Parsec@ for
constructing the parser.
For simplicity, you may assume we are using common @String@ as input,
@()@ as the user state and @Identity@ as the underlying monad -- that is,
you can use the @Parser@ type provided by module @Text.Parsec.String@.
If the provided input holds a valid JSON (a valid object or array
at the top level), the parser should return it as a JSON tree in your own
user-defined data type. If the input is invalid, the parse error should
be returned.
Try to have a reasonable (flexible, modular) design of the module.
Any documentation for your own internal functions is very welcome.
= Implementation notes
* Adhere strictly to the specification from website.
No deviations such as missing quote marks around strings should be accepted.
* For simplicity, you can consider all numbers in the JSON
being of the type @Double@ (even if they do not have the decimal part).
* To parse basic types, you can use the @read@ function or equivalent
(for example @readLitChar@ for constructing Unicode characters).
* You can specify the JSON data type as you see fit.
However, it should not allow for construction of invalid JSON objects.
* If you choose not to implement the bonus, an automatically derived
@Show@ instance for the JSON type is sufficient to use in @main@.
= Bonus: pretty-printer (up to 2 extra points)
As a bonus, try to implement a reasonable pretty-printer for the JSON type
you define. You can use the traditional conventions for displaying
JSON objects on the web (try some JSON pretty-printers online and devise
a style you see as useful).
The pretty-printer should not be the @Show@ instance (this instance should
be derived automatically to retain all information held by the data types).
= Modules and packages
You can use any modules from the
and packages.
If you wish so, you can also use Unicode syntax from
.
We do not explicitly forbid other packages (it's bad practice to reinvent the wheel)
but we don't expect you to need any. If you want to use some, please drop us an email
with short description why you'd like to use it.
-}
-- -------------------------------------------------------------------------------------------
-- Name:
-- UCO:
-- -------------------------------------------------------------------------------------------
module HW04 ( Json, jsonParser, pprintJson ) where
import Text.Parsec
import Text.Parsec.String ( Parser )
-- | the top-level JSON data type
data Json = Undefined
-- | Parser for JSON
jsonParser :: Parser Json
jsonParser = undefined
-- | Pretty print the JSON object.
pprintJson :: Json -> String
pprintJson = undefined