Basic.hs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Data.SCargot.Basic
  3. ( -- * Spec
  4. -- $descr
  5. basicSpec
  6. ) where
  7. import Control.Applicative ((<$>))
  8. import Data.Char (isAlphaNum)
  9. import Text.Parsec (many1, satisfy)
  10. import Data.Text (Text, pack)
  11. import Data.SCargot.Repr.Basic (SExpr)
  12. import Data.SCargot.General ( SExprSpec
  13. , mkSpec
  14. )
  15. import Data.SCargot.Comments (withLispComments)
  16. isAtomChar :: Char -> Bool
  17. isAtomChar c = isAlphaNum c
  18. || c == '-' || c == '*' || c == '/'
  19. || c == '+' || c == '<' || c == '>'
  20. || c == '=' || c == '!' || c == '?'
  21. -- $descr
  22. -- The 'basicSpec' describes S-expressions whose atoms are simply
  23. -- text strings that contain alphanumeric characters and a small
  24. -- set of punctuation. It does no parsing of numbers or other data
  25. -- types, and will accept tokens that typical Lisp implementations
  26. -- would find nonsensical (like @77foo@).
  27. --
  28. -- Atoms recognized by the 'basicSpec' are any string matching the
  29. -- regular expression @[A-Za-z0-9+*<>/=!?-]+@.
  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. basicSpec :: SExprSpec Text (SExpr Text)
  34. basicSpec = mkSpec pToken id
  35. where pToken = pack <$> many1 (satisfy isAtomChar)