SCargot.hs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. module Data.SCargot
  2. ( -- * SCargot Basics
  3. -- $intro
  4. -- * Parsing and Printing
  5. decode
  6. , decodeOne
  7. , encode
  8. , encodeOne
  9. -- * Parser Construction
  10. -- ** Specifying a Parser
  11. , SExprParser
  12. , Reader
  13. , Comment
  14. , mkParser
  15. , setCarrier
  16. , addReader
  17. , setComment
  18. , asRich
  19. , asWellFormed
  20. , withQuote
  21. -- * Printer Construction
  22. -- * Specifying a Pretty-Printer
  23. , SExprPrinter
  24. , Indent(..)
  25. , basicPrint
  26. , flatPrint
  27. , setFromCarrier
  28. , setMaxWidth
  29. , removeMaxWidth
  30. , setIndentAmount
  31. , setIndentStrategy
  32. ) where
  33. import Data.SCargot.Parse
  34. import Data.SCargot.Print
  35. {- $intro
  36. The S-Cargot library is a library for parsing and emitting
  37. <https://en.wikipedia.org/wiki/S-expression s-expressions>, designed
  38. to be as flexible as possible. Despite some efforts at
  39. <http://people.csail.mit.edu/rivest/Sexp.txt standardization>,
  40. s-expressions are a general approach to describing a data format
  41. that can very often differ in subtle, incompatible ways: the
  42. s-expressions understood by Common Lisp are different from the
  43. s-expressions understood by Scheme, and even the different
  44. revisions of the Scheme language understand s-expressions in a
  45. slightly different way. To accomodate this, the S-Cargot library
  46. provides a toolbox for defining variations on s-expressions,
  47. complete with the ability to select various comment syntaxes, reader
  48. macros, and atom types.
  49. If all you want is to read some s-expressions and don't care about
  50. the edge cases of the format, or all you want is a new configuration
  51. format, try the "Data.SCargot.Language.Basic" or "Data.SCargot.Language.HaskLike"
  52. modules, which define an s-expression language whose atoms are
  53. plain strings and Haskell literals, respectively.
  54. The S-Cargot library works by specifying values which contain all
  55. the information needed to either parse or print an s-expression.
  56. The actual s-expression structure is parsed as a structure of
  57. <https://en.wikipedia.org/wiki/Cons cons cells> as represented
  58. by the 'SExpr' type, but can alternately be exposed as the
  59. isomorphic 'RichSExpr' type or the less expressive but
  60. easier-to-work-with 'WellFormedSExpr' type. Modules devoted
  61. to each representation type (in "Data.SCargot.Repr.Basic",
  62. "Data.SCargot.Repr.Rich", and "Data.SCargot.Repr.WellFormed")
  63. provide helper functions, lenses, and pattern synonyms to make
  64. creating and processing these values easier.
  65. The details of how to parse a given structure are represented
  66. by building up a 'SExprParser' value, which is defined in
  67. "Data.SCargot.Parse" and re-exported here. A minimal
  68. 'SExprParser' defines only how to parse the atoms of the
  69. language; helper functions can define comment syntaxes,
  70. reader macros, and transformations over the parsed structure.
  71. The details of how to print a given structure are represented
  72. by building up a 'SExprPrinter' value, which is defined in
  73. "Data.SCargot.Print" and re-exported here. A minimal
  74. 'SExprPrinter' defines only how to print the atoms of the
  75. language; helper functions help with the layout of the
  76. pretty-printed s-expression in terms of how to indent the
  77. surrounding expression.
  78. Other helper modules define useful primitives for building up
  79. s-expression languages: the "Data.SCargot.Common" module provides
  80. parsers for common literals, while the "Data.SCargot.Comments"
  81. module provides parsers for comment syntaxes borrowed from
  82. various other languages.
  83. -}