git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' of github.com:purescript/purescript into functor-ops
commit7826d00e5c48ce470f48a6b813378ba3aa3dca80 authorjoneshf <jones3.hardy@gmail.com> dateThu 13 Nov 2014, 11:55 (12 years ago) parent12180b612e296e
12 files changed+68−37
README.md+3−3 examples/passing/ReservedWords.purs+13 psc-docs/Main.hs+2−1 psc-make/Main.hs+4−4 psc/Main.hs+2−1 psci/Main.hs+10−10 purescript.cabal+1−1 src/Language/PureScript.hs+15−5 src/Language/PureScript/Parser/Common.hs+6 src/Language/PureScript/Parser/Declarations.hs+7−7 src/Language/PureScript/Parser/Types.hs+1−1 tests/Main.hs+4−4
README.md+3−3
@@ -6,9 +6,9 @@ PureScript is a small strongly, statically typed programming language with expre
66## Resources
77
88- [PureScript Book](https://leanpub.com/purescript/read)
9−- [Documentation](http://purescript.readthedocs.org/)
10−- [#purescript IRC @ FreeNode](irc://irc.freenode.net/#purescript)
9+- [Wiki](http://wiki.purescript.org)
10+- [#purescript IRC @ FreeNode](http://webchat.freenode.net/?channels=purescript)
1111- [Twitter](http://twitter.com/purescript)
1212- [Try PureScript!](http://try.purescript.org/)
13−- [Release Notes](https://github.com/purescript/purescript/blob/master/RELEASE-0.5.md)
13+- [Release Notes](https://github.com/purescript/purescript/blob/master/RELEASE-0.6.md)
1414- [Contributing to PureScript](https://github.com/purescript/purescript/blob/master/CONTRIBUTING.md)
examples/passing/ReservedWords.pursnew file+13
@@ -0,0 +1,13 @@
1+-- See https://github.com/purescript/purescript/issues/606
2+module Main where
3+
4+ o :: { type :: String }
5+ o = { type: "o" }
6+
7+ p :: { type :: String }
8+ p = o { type = "p" }
9+
10+ f :: forall r. { type :: String | r } -> String
11+ f { type = "p" } = "Done"
12+
13+ main = Debug.Trace.trace $ f { type: p.type, foo: "bar" }
psc-docs/Main.hs+2−1
@@ -20,6 +20,7 @@ import Control.Monad.Writer
2020import Control.Arrow (first)
2121import Data.Function (on)
2222import Data.List
23+import Data.Maybe (fromMaybe)
2324import Data.Version (showVersion)
2425import qualified Language.PureScript as P
2526import qualified Paths_purescript as Paths
@@ -30,7 +31,7 @@ import System.IO (stderr)
3031
3132docgen :: Bool -> [FilePath] -> IO ()
3233docgen showHierarchy input = do
33− e <- P.parseModulesFromFiles <$> mapM (fmap (first Just) . parseFile) (nub input)
34+ e <- P.parseModulesFromFiles (fromMaybe "") <$> mapM (fmap (first Just) . parseFile) (nub input)
3435 case e of
3536 Left err -> do
3637 U.hPutStr stderr $ show err
psc-make/Main.hs+4−4
@@ -38,10 +38,10 @@ data InputOptions = InputOptions
3838 , ioInputFiles :: [FilePath]
3939 }
4040
41−readInput :: InputOptions -> IO [(Maybe FilePath, String)]
41+readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
4242readInput InputOptions{..} = do
43− content <- forM ioInputFiles $ \inputFile -> (Just inputFile, ) <$> U.readFile inputFile
44− return $ bool ((Nothing, P.prelude) :) id ioNoPrelude content
43+ content <- forM ioInputFiles $ \inputFile -> (Right inputFile, ) <$> U.readFile inputFile
44+ return $ bool ((Left P.RebuildNever, P.prelude) :) id ioNoPrelude content
4545
4646newtype Make a = Make { unMake :: ErrorT String IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadError String)
4747
@@ -69,7 +69,7 @@ instance P.MonadMake Make where
6969
7070compile :: [FilePath] -> FilePath -> P.Options P.Make -> Bool -> IO ()
7171compile input outputDir opts usePrefix = do
72− modules <- P.parseModulesFromFiles <$> readInput (InputOptions (P.optionsNoPrelude opts) input)
72+ modules <- P.parseModulesFromFiles (either (const "") id) <$> readInput (InputOptions (P.optionsNoPrelude opts) input)
7373 case modules of
7474 Left err -> do
7575 U.print err
psc/Main.hs+2−1
@@ -20,6 +20,7 @@ import Control.Applicative
2020import Control.Monad.Error
2121
2222import Data.Bool (bool)
23+import Data.Maybe (fromMaybe)
2324import Data.Version (showVersion)
2425
2526import System.Console.CmdTheLine
@@ -46,7 +47,7 @@ readInput InputOptions{..}
4647
4748compile :: P.Options P.Compile -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> Bool -> IO ()
4849compile opts stdin input output externs usePrefix = do
49− modules <- P.parseModulesFromFiles <$> readInput (InputOptions (P.optionsNoPrelude opts) stdin input)
50+ modules <- P.parseModulesFromFiles (fromMaybe "") <$> readInput (InputOptions (P.optionsNoPrelude opts) stdin input)
5051 case modules of
5152 Left err -> do
5253 U.hPutStr stderr $ show err
psci/Main.hs+10−10
@@ -66,7 +66,7 @@ import qualified Language.PureScript.Declarations as D
6666data PSCiState = PSCiState
6767 { psciImportedFilenames :: [FilePath]
6868 , psciImportedModuleNames :: [P.ModuleName]
69− , psciLoadedModules :: [(Maybe FilePath, P.Module)]
69+ , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
7070 , psciLetBindings :: [P.Expr -> P.Expr]
7171 }
7272
@@ -87,7 +87,7 @@ updateImports name st = st { psciImportedModuleNames = name : psciImportedModule
8787-- |
8888-- Updates the state to have more loaded files.
8989--
90−updateModules :: [(Maybe FilePath, P.Module)] -> PSCiState -> PSCiState
90+updateModules :: [(Either P.RebuildPolicy FilePath, P.Module)] -> PSCiState -> PSCiState
9191updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
9292
9393-- |
@@ -130,12 +130,12 @@ loadModule filename = either (Left . show) Right . P.runIndentParser filename P.
130130-- |
131131-- Load all modules, including the Prelude
132132--
133−loadAllModules :: [FilePath] -> IO (Either ParseError [(Maybe FilePath, P.Module)])
133+loadAllModules :: [FilePath] -> IO (Either ParseError [(Either P.RebuildPolicy FilePath, P.Module)])
134134loadAllModules files = do
135135 filesAndContent <- forM files $ \filename -> do
136136 content <- U.readFile filename
137− return (Just filename, content)
138− return $ P.parseModulesFromFiles $ (Nothing, P.prelude) : filesAndContent
137+ return (Right filename, content)
138+ return $ P.parseModulesFromFiles (either (const "") id) $ (Left P.RebuildNever, P.prelude) : filesAndContent
139139
140140
141141-- |
@@ -303,7 +303,7 @@ handleDeclaration :: P.Expr -> PSCI ()
303303handleDeclaration value = do
304304 st <- PSCI $ lift get
305305 let m = createTemporaryModule True st value
306− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
306+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
307307 case e of
308308 Left err -> PSCI $ outputStrLn err
309309 Right _ -> do
@@ -343,7 +343,7 @@ handleImport :: P.ModuleName -> PSCI ()
343343handleImport moduleName = do
344344 st <- updateImports moduleName <$> PSCI (lift get)
345345 let m = createTemporaryModuleForImports st
346− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
346+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
347347 case e of
348348 Left err -> PSCI $ outputStrLn err
349349 Right _ -> do
@@ -357,7 +357,7 @@ handleTypeOf :: P.Expr -> PSCI ()
357357handleTypeOf value = do
358358 st <- PSCI $ lift get
359359 let m = createTemporaryModule False st value
360− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
360+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
361361 case e of
362362 Left err -> PSCI $ outputStrLn err
363363 Right env' ->
@@ -407,7 +407,7 @@ handleKindOf typ = do
407407 st <- PSCI $ lift get
408408 let m = createTemporaryModuleForKind st typ
409409 mName = P.ModuleName [P.ProperName "$PSCI"]
410− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Nothing, m)]) []
410+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st ++ [(Left P.RebuildAlways, m)]) []
411411 case e of
412412 Left err -> PSCI $ outputStrLn err
413413 Right env' ->
@@ -453,7 +453,7 @@ handleCommand (LoadFile filePath) = do
453453 m <- psciIO $ loadModule absPath
454454 case m of
455455 Left err -> PSCI $ outputStrLn err
456− Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Just absPath)) mods))
456+ Right mods -> PSCI . lift $ modify (updateModules (map ((,) (Right absPath)) mods))
457457 else
458458 PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
459459handleCommand Reset = do
purescript.cabal+1−1
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.6.0
2+version: 0.6.0.2
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
src/Language/PureScript.hs+15−5
@@ -15,7 +15,7 @@
1515
1616{-# LANGUAGE DataKinds, QuasiQuotes, TemplateHaskell #-}
1717
18−module Language.PureScript (module P, compile, compile', MonadMake(..), make, prelude) where
18+module Language.PureScript (module P, compile, compile', RebuildPolicy(..), MonadMake(..), make, prelude) where
1919
2020import Language.PureScript.Types as P
2121import Language.PureScript.Kinds as P
@@ -133,13 +133,22 @@ class MonadMake m where
133133 --
134134 progress :: String -> m ()
135135
136+-- |
137+-- Determines when to rebuild a module
138+--
139+data RebuildPolicy
140+ -- | Never rebuild this module
141+ = RebuildNever
142+ -- | Always rebuild this module
143+ | RebuildAlways deriving (Show, Eq, Ord)
144+
136145-- |
137146-- Compiles in "make" mode, compiling each module separately to a js files and an externs file
138147--
139148-- If timestamps have not changed, the externs file can be used to provide the module's types without
140149-- having to typecheck the module again.
141150--
142−make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options Make -> [(Maybe FilePath, Module)] -> [String] -> m Environment
151+make :: (Functor m, Applicative m, Monad m, MonadMake m) => FilePath -> Options Make -> [(Either RebuildPolicy FilePath, Module)] -> [String] -> m Environment
143152make outputDir opts ms prefix = do
144153 let filePathMap = M.fromList (map (\(fp, Module mn _ _) -> (mn, fp)) ms)
145154
@@ -150,14 +159,15 @@ make outputDir opts ms prefix = do
150159
151160 jsFile = outputDir </> filePath </> "index.js"
152161 externsFile = outputDir </> filePath </> "externs.purs"
153− inputFile = join $ M.lookup moduleName' filePathMap
162+ inputFile = fromMaybe (error "Module has no filename in 'make'") $ M.lookup moduleName' filePathMap
154163
155164 jsTimestamp <- getTimestamp jsFile
156165 externsTimestamp <- getTimestamp externsFile
157− inputTimestamp <- join <$> traverse getTimestamp inputFile
166+ inputTimestamp <- traverse getTimestamp inputFile
158167
159168 return $ case (inputTimestamp, jsTimestamp, externsTimestamp) of
160− (Just t1, Just t2, Just t3) | t1 < min t2 t3 -> s
169+ (Right (Just t1), Just t2, Just t3) | t1 < min t2 t3 -> s
170+ (Left RebuildNever, Just _, Just _) -> s
161171 _ -> S.insert moduleName' s) S.empty sorted
162172
163173 marked <- rebuildIfNecessary (reverseDependencies graph) toRebuild sorted
src/Language/PureScript/Parser/Common.hs+6
@@ -133,6 +133,12 @@ lexeme = PT.lexeme tokenParser
133133identifier :: P.Parsec String u String
134134identifier = PT.identifier tokenParser
135135
136+-- |
137+-- Parse an identifier in a more permissive position
138+--
139+identifierName :: P.Parsec String u String
140+identifierName = lexeme $ (:) <$> identStart <*> many identLetter
141+
136142-- |
137143-- Parse a reserved word
138144--
src/Language/PureScript/Parser/Declarations.hs+7−7
@@ -235,10 +235,10 @@ parseModule = do
235235-- |
236236-- Parse a collection of modules
237237--
238−parseModulesFromFiles :: [(Maybe FilePath, String)] -> Either P.ParseError [(Maybe FilePath, Module)]
239−parseModulesFromFiles input =
238+parseModulesFromFiles :: (k -> String) -> [(k, String)] -> Either P.ParseError [(k, Module)]
239+parseModulesFromFiles toFilePath input =
240240 fmap collect . forM input $ \(filename, content) -> do
241− ms <- runIndentParser (fromMaybe "" filename) parseModules content
241+ ms <- runIndentParser (toFilePath filename) parseModules content
242242 return (filename, ms)
243243 where
244244 collect :: [(k, [v])] -> [(k, v)]
@@ -269,7 +269,7 @@ parseObjectLiteral :: P.Parsec String ParseState Expr
269269parseObjectLiteral = ObjectLiteral <$> C.braces (C.commaSep parseIdentifierAndValue)
270270
271271parseIdentifierAndValue :: P.Parsec String ParseState (String, Expr)
272−parseIdentifierAndValue = (,) <$> (C.indented *> (C.identifier <|> C.stringLiteral) <* C.indented <* C.colon)
272+parseIdentifierAndValue = (,) <$> (C.indented *> (C.identifierName <|> C.stringLiteral) <* C.indented <* C.colon)
273273 <*> (C.indented *> parseValue)
274274
275275parseAbs :: P.Parsec String ParseState Expr
@@ -332,14 +332,14 @@ parseValueAtom = P.choice
332332
333333parsePropertyUpdate :: P.Parsec String ParseState (String, Expr)
334334parsePropertyUpdate = do
335− name <- C.lexeme (C.identifier <|> C.stringLiteral)
335+ name <- C.lexeme (C.identifierName <|> C.stringLiteral)
336336 _ <- C.lexeme $ C.indented *> P.char '='
337337 value <- C.indented *> parseValue
338338 return (name, value)
339339
340340parseAccessor :: Expr -> P.Parsec String ParseState Expr
341341parseAccessor (Constructor _) = P.unexpected "constructor"
342−parseAccessor obj = P.try $ Accessor <$> (C.indented *> C.dot *> P.notFollowedBy C.opLetter *> C.indented *> (C.identifier <|> C.stringLiteral)) <*> pure obj
342+parseAccessor obj = P.try $ Accessor <$> (C.indented *> C.dot *> P.notFollowedBy C.opLetter *> C.indented *> (C.identifierName <|> C.stringLiteral)) <*> pure obj
343343
344344parseDo :: P.Parsec String ParseState Expr
345345parseDo = do
@@ -419,7 +419,7 @@ parseNullBinder = C.lexeme (P.char '_' *> P.notFollowedBy C.identLetter) *> retu
419419
420420parseIdentifierAndBinder :: P.Parsec String ParseState (String, Binder)
421421parseIdentifierAndBinder = do
422− name <- C.lexeme (C.identifier <|> C.stringLiteral)
422+ name <- C.lexeme (C.identifierName <|> C.stringLiteral)
423423 _ <- C.lexeme $ C.indented *> P.char '='
424424 binder <- C.indented *> parseBinder
425425 return (name, binder)
src/Language/PureScript/Parser/Types.hs+1−1
@@ -109,7 +109,7 @@ parsePolyType :: P.Parsec String ParseState Type
109109parsePolyType = parseAnyType
110110
111111parseNameAndType :: P.Parsec String ParseState t -> P.Parsec String ParseState (String, t)
112−parseNameAndType p = (,) <$> (indented *> (identifier <|> stringLiteral) <* indented <* lexeme (P.string "::")) <*> p
112+parseNameAndType p = (,) <$> (indented *> (identifierName <|> stringLiteral) <* indented <* lexeme (P.string "::")) <*> p
113113
114114parseRowEnding :: P.Parsec String ParseState Type
115115parseRowEnding = P.option REmpty (TypeVar <$> (lexeme (indented *> P.char '|') *> indented *> identifier))
tests/Main.hs+4−4
@@ -30,20 +30,20 @@ import System.Directory (getCurrentDirectory, getTemporaryDirectory, getDirector
3030import Text.Parsec (ParseError)
3131import qualified System.IO.UTF8 as U
3232
33−readInput :: [FilePath] -> IO [(Maybe FilePath, String)]
33+readInput :: [FilePath] -> IO [(FilePath, String)]
3434readInput inputFiles = forM inputFiles $ \inputFile -> do
3535 text <- U.readFile inputFile
36− return (Just inputFile, text)
36+ return (inputFile, text)
3737
3838loadPrelude :: Either String (String, String, P.Environment)
3939loadPrelude =
40− case P.parseModulesFromFiles [(Nothing, P.prelude)] of
40+ case P.parseModulesFromFiles id [("", P.prelude)] of
4141 Left parseError -> Left (show parseError)
4242 Right ms -> P.compile (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }) (map snd ms) []
4343
4444compile :: P.Options P.Compile -> [FilePath] -> IO (Either String (String, String, P.Environment))
4545compile opts inputFiles = do
46− modules <- P.parseModulesFromFiles <$> readInput inputFiles
46+ modules <- P.parseModulesFromFiles id <$> readInput inputFiles
4747 case modules of
4848 Left parseError ->
4949 return (Left $ show parseError)