SCargot.hs 3.3 KB

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