Basic.hs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Data.SCargot.Basic
  3. ( basicSpec
  4. , asRich
  5. , asWellFormed
  6. , addReader
  7. , setComment
  8. , withLispComments
  9. , withQuote
  10. ) where
  11. import Data.Char (isAlphaNum)
  12. import Data.Attoparsec.Text (Parser, takeWhile1)
  13. import Data.Text (Text)
  14. import Data.SCargot.Repr.Basic
  15. import Data.SCargot.General
  16. import Data.SCargot.Comments (withLispComments)
  17. isAtomChar :: Char -> Bool
  18. isAtomChar c = isAlphaNum c
  19. || c == '-'
  20. || c == '*'
  21. || c == '/'
  22. || c == '+'
  23. || c == '<'
  24. || c == '>'
  25. || c == '='
  26. || c == '!'
  27. || c == '?'
  28. -- | A 'SExprSpec' that understands atoms to be sequences of
  29. -- alphanumeric characters as well as the punctuation
  30. -- characters @-*/+<>=!?@, and does no processing of them.
  31. -- This is not quite representative of actual lisps, which
  32. -- would (for example) accept various kinds of string
  33. -- literals. This should be sufficient for most ad-hoc
  34. -- storage or configuration formats.
  35. basicSpec :: SExprSpec Text (SExpr Text)
  36. basicSpec = mkSpec (takeWhile1 isAtomChar) id