Skip to content

Instantly share code, notes, and snippets.

@kritzcreek
Created May 23, 2020 22:12
Show Gist options
  • Save kritzcreek/c67ea9cb7ac43dfcb527b05bacf66814 to your computer and use it in GitHub Desktop.
Save kritzcreek/c67ea9cb7ac43dfcb527b05bacf66814 to your computer and use it in GitHub Desktop.
import Prelude
import Control.Monad
import Data.Foldable
import Language.PureScript.CST.Types as CST
import Language.PureScript.CST.Parser as CST
import Language.PureScript.CST.Print as CST
import Data.Text (Text)
import Data.Text.IO as Text
import System.Directory
import System.FilePath
import System.IO (hSetEncoding, stdout, stderr, utf8)
readModule :: FilePath -> IO (Text, Maybe (CST.Module ()))
readModule path = do
contents <- BS.fromStrict . Text.encodeUtf8 path
module_ <- case snd $ CST.parse contents of
Left err -> print (show err) *> pure Nothing
Right module_ -> pure $ Just module_
pure (contents, module_)
roundtripParser :: IO ()
roundtripParser = do
hSetEncoding stdout utf8
hSetEncoding stderr utf8
let dir = "lib/purescript-cst/tests/purs/layout"
-- let dir = "tests/purs/passing"
files <- listDirectory dir
for_ files $ \path -> when (isExtensionOf "purs" path) $ do
print path
(content, module_) <- readModule (dir </> path)
for_ module_ $ \module_ -> if content == CST.printModule module_ then pure () else error path
pure ()
main = roundtripParser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment