Basic.hs 1.1 KB

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