CommonLisp.hs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. -- | Contains the type of atoms that Common Lisp understands, as
  2. -- well as the built-in reader macros that Common Lisp provides.
  3. -- Given a Common Lisp source file that contains no extra reader
  4. -- macro definitions, this module should successfully parse and
  5. -- desugar even quoted lists and vector literals.
  6. module Data.SCargot.CommonLisp where
  7. data CLAtom
  8. = CLSymbol Text
  9. | CLString Text
  10. | CLInteger Integer
  11. | CLRatio Integer Integer
  12. | CLFloat Double
  13. deriving (Eq, Show, Read)
  14. type CommonLispSpec carrier = SExprSpec CLAtom carrier
  15. withComments :: CommonLispSpec c -> CommonLispSpec c
  16. withComments = addCommentType (const () <$> (char ';' *> restOfLine))
  17. withQuote :: CommonLispSpec (SCons CLAtom) -> CommonLispSpec (SCons CLAtom)
  18. withQuote = addReader '\'' (go <$> parse)
  19. where go v = SCons q (SCons v SNil)
  20. -- | Adds support for the '#(...)' sugar for vectors. (This will be
  21. -- parsed as '(vector ...)', and
  22. withVectors :: CommonLispSpec c -> CommonLispSpec c
  23. withVectors = addReader '#' (go <$> parse)
  24. parse :: CommonLispSpec c -> Text -> Either String c
  25. serialize :: CommonLispSpec c -> c -> Text