Basic.hs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Control.Applicative ((<$>))
  12. import Data.Char (isAlphaNum)
  13. import Text.Parsec (many1, satisfy)
  14. import Data.Text (Text, pack)
  15. import Data.SCargot.Repr.Basic (SExpr)
  16. import Data.SCargot.General ( SExprSpec
  17. , mkSpec
  18. , asRich
  19. , asWellFormed
  20. , addReader
  21. , setComment
  22. , withQuote
  23. )
  24. import Data.SCargot.Comments (withLispComments)
  25. isAtomChar :: Char -> Bool
  26. isAtomChar c = isAlphaNum c
  27. || c == '-' || c == '*' || c == '/'
  28. || c == '+' || c == '<' || c == '>'
  29. || c == '=' || c == '!' || c == '?'
  30. -- | A 'SExprSpec' that understands atoms to be sequences of
  31. -- alphanumeric characters as well as the punctuation
  32. -- characters @[-*/+<>=!?]@, and does no processing of them.
  33. -- This is not quite representative of actual lisps, which
  34. -- would, for example, accept various kinds of string
  35. -- and numeric literals.
  36. basicSpec :: SExprSpec Text (SExpr Text)
  37. basicSpec = mkSpec pToken id
  38. where pToken = pack <$> many1 (satisfy isAtomChar)