git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge master and fix psci-tests
commit14557b87aac463da8b429569847a7a88dd26bbef authorPhil Freeman <paf31@cantab.net> dateTue 2 Jun 2015, 21:46 (11 years ago) parent5a4b2124942fe9
7 files changed+47−20
examples/failing/LeadingZeros1.purs+3 examples/failing/LeadingZeros2.purs+3 psc-make/Make.hs+5−3 psc-publish/ErrorsWarnings.hs+5−4 psci/tests/Main.hs+16−7 purescript.cabal+4−2 src/Language/PureScript/Parser/Lexer.hs+11−4
examples/failing/LeadingZeros1.pursnew file+3
@@ -0,0 +1,3 @@
1+module Main where
2+
3+x = 01
examples/failing/LeadingZeros2.pursnew file+3
@@ -0,0 +1,3 @@
1+module Main where
2+
3+x = 00.1
psc-make/Make.hs+5−3
@@ -119,9 +119,11 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
119119 traverse (const $ getModificationTime path) $ guard exists
120120
121121 readTextFile :: FilePath -> Make String
122− readTextFile path = makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ do
123− putStrLn $ "Reading " ++ path
124− readFile path
122+ readTextFile path = do
123+ verboseErrorsEnabled <- asks P.optionsVerboseErrors
124+ makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ do
125+ when verboseErrorsEnabled $ putStrLn $ "Reading " ++ path
126+ readFile path
125127
126128 writeTextFile :: FilePath -> String -> Make ()
127129 writeTextFile path text = makeIO (const (P.SimpleErrorWrapper $ P.CannotWriteFile path)) $ do
psc-publish/ErrorsWarnings.hs+5−4
@@ -256,10 +256,11 @@ renderWarnings =
256256 where
257257 collectWarnings patterns warns =
258258 let boxes = mapMaybe (collectWarnings' warns) patterns
259− in vcat
260− [ para "Warnings:"
261− , indented (vcat (intersperse spacer boxes))
262− ]
259+ result = vcat
260+ [ para "Warnings:"
261+ , indented (vcat (intersperse spacer boxes))
262+ ]
263+ in if null boxes then nullBox else result
263264
264265 getResolutionNotVersion (ResolutionNotVersion n) = Just n
265266 getResolutionNotVersion _ = Nothing
psci/tests/Main.hs+16−7
@@ -1,16 +1,19 @@
1−{-# LANGUAGE RecordWildCards #-}
1+{-# LANGUAGE RecordWildCards, TupleSections #-}
22
33module Main where
44
55import Control.Monad.Trans.State.Strict (runStateT)
6−import Control.Monad (when)
6+import Control.Monad (when, forM)
7+import Control.Applicative
8+import Control.Monad.Writer (runWriterT)
9+import Control.Monad.Except (runExceptT)
710
8−import Data.List (sort)
11+import Data.List (isSuffixOf, sort)
912
1013import System.Exit (exitFailure)
1114import System.Console.Haskeline
1215import System.FilePath ((</>))
13−import System.Directory (getCurrentDirectory)
16+import System.Directory (getCurrentDirectory, getDirectoryContents)
1417
1518import Test.HUnit
1619
@@ -104,7 +107,8 @@ completionTestData =
104107 , ("Control.Monad.ST.new", ["Control.Monad.ST.newSTRef"])
105108 ]
106109 where
107− allModuleNames = [ "Control.Monad.Eff"
110+ allModuleNames = [ "Assert"
111+ , "Control.Monad.Eff"
108112 , "Control.Monad.ST"
109113 , "Data.Function"
110114 , "Debug.Trace"
@@ -127,13 +131,18 @@ runCM act = do
127131getPSCiState :: IO PSCiState
128132getPSCiState = do
129133 cwd <- getCurrentDirectory
130− modulesOrFirstError <- loadAllModules [ cwd </> "tests" </> "prelude.purs" ]
134+ let preludeDir = cwd </> "tests" </> "prelude"
135+ jsDir = preludeDir </> "js"
136+ modulesOrFirstError <- loadAllModules [ preludeDir </> "prelude.purs" ]
137+ jsFiles <- map (jsDir </>) . filter (".js" `isSuffixOf`) <$> getDirectoryContents jsDir
138+ foreignFiles <- forM jsFiles (\f -> (f,) <$> readFile f)
139+ Right (foreigns, _) <- runExceptT $ runWriterT $ P.parseForeignModulesFromFiles foreignFiles
131140 case modulesOrFirstError of
132141 Left err ->
133142 print err >> exitFailure
134143 Right modules ->
135144 let imports = controlMonadSTasST : defaultImports
136− in return (PSCiState [] imports modules [] [])
145+ in return (PSCiState [] imports modules foreigns [] [])
137146
138147controlMonadSTasST :: ImportedModule
139148controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST"))
purescript.cabal+4−2
@@ -159,7 +159,7 @@ executable psc-make
159159 main-is: Main.hs
160160 buildable: True
161161 hs-source-dirs: psc-make
162− other-modules:
162+ other-modules: Make
163163 ghc-options: -Wall -O2 -fno-warn-unused-do-bind
164164
165165executable psci
@@ -176,6 +176,8 @@ executable psci
176176 Directive
177177 Completion
178178 PSCi
179+ Make
180+ IO
179181 ghc-options: -Wall -O2
180182
181183executable psc-docs
@@ -229,7 +231,7 @@ test-suite psci-tests
229231 build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
230232 mtl -any, optparse-applicative >= 0.10.0, parsec -any,
231233 haskeline >= 0.7.0.0, purescript -any, transformers -any,
232− transformers-compat -any, process -any, HUnit -any
234+ transformers-compat -any, process -any, HUnit -any, time -any
233235 type: exitcode-stdio-1.0
234236 main-is: Main.hs
235237 buildable: True
src/Language/PureScript/Parser/Lexer.hs+11−4
@@ -240,12 +240,19 @@ parseToken = P.choice
240240 parseStringLiteral :: P.Parsec String u String
241241 parseStringLiteral = blockString <|> PT.stringLiteral tokenParser
242242 where
243− delimeter = P.try (P.string "\"\"\"")
244− blockString = delimeter >> P.manyTill P.anyChar delimeter
243+ delimiter = P.try (P.string "\"\"\"")
244+ blockString = delimiter >> P.manyTill P.anyChar delimiter
245245
246246 parseNumber :: P.Parsec String u (Either Integer Double)
247− parseNumber = (Right <$> P.try (PT.float tokenParser) <|>
248− Left <$> P.try (PT.natural tokenParser)) P.<?> "number"
247+ parseNumber = (consumeLeadingZero >> P.parserZero) <|>
248+ (Right <$> P.try (PT.float tokenParser) <|>
249+ Left <$> P.try (PT.natural tokenParser))
250+ P.<?> "number"
251+ where
252+ -- lookAhead doesn't consume any input if its parser succeeds
253+ -- if notFollowedBy fails though, the consumed '0' will break the choice chain
254+ consumeLeadingZero = P.lookAhead (P.char '0' >>
255+ (P.notFollowedBy P.digit P.<?> "no leading zero in number literal"))
249256
250257-- |
251258-- We use Text.Parsec.Token to implement the string and number lexemes