git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge master and fix psci-tests
14557b8Phil Freeman
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 =
119 traverse (const $ getModificationTime path) $ guard exists
119 traverse (const $ getModificationTime path) $ guard exists
120
120
121 readTextFile :: FilePath -> Make String
121 readTextFile :: FilePath -> Make String
122+ readTextFile path = do
123+ verboseErrorsEnabled <- asks P.optionsVerboseErrors
122− readTextFile path = makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ do
124+ makeIO (const (P.SimpleErrorWrapper $ P.CannotReadFile path)) $ do
123− putStrLn $ "Reading " ++ path
125+ when verboseErrorsEnabled $ putStrLn $ "Reading " ++ path
124− readFile path
126+ readFile path
125
127
126 writeTextFile :: FilePath -> String -> Make ()
128 writeTextFile :: FilePath -> String -> Make ()
127 writeTextFile path text = makeIO (const (P.SimpleErrorWrapper $ P.CannotWriteFile path)) $ do
129 writeTextFile path text = makeIO (const (P.SimpleErrorWrapper $ P.CannotWriteFile path)) $ do
psc-publish/ErrorsWarnings.hs+5−4
@@ -256,10 +256,11 @@ renderWarnings =
256 where
256 where
257 collectWarnings patterns warns =
257 collectWarnings patterns warns =
258 let boxes = mapMaybe (collectWarnings' warns) patterns
258 let boxes = mapMaybe (collectWarnings' warns) patterns
259− in vcat
259+ result = vcat
260− [ para "Warnings:"
260+ [ para "Warnings:"
261− , indented (vcat (intersperse spacer boxes))
261+ , indented (vcat (intersperse spacer boxes))
262− ]
262+ ]
263+ in if null boxes then nullBox else result
263
264
264 getResolutionNotVersion (ResolutionNotVersion n) = Just n
265 getResolutionNotVersion (ResolutionNotVersion n) = Just n
265 getResolutionNotVersion _ = Nothing
266 getResolutionNotVersion _ = Nothing
psci/tests/Main.hs+16−7
@@ -1,16 +1,19 @@
1−{-# LANGUAGE RecordWildCards #-}
1+{-# LANGUAGE RecordWildCards, TupleSections #-}
2
2
3module Main where
3module Main where
4
4
5import Control.Monad.Trans.State.Strict (runStateT)
5import 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)
7
10
8−import Data.List (sort)
11+import Data.List (isSuffixOf, sort)
9
12
10import System.Exit (exitFailure)
13import System.Exit (exitFailure)
11import System.Console.Haskeline
14import System.Console.Haskeline
12import System.FilePath ((</>))
15import System.FilePath ((</>))
13−import System.Directory (getCurrentDirectory)
16+import System.Directory (getCurrentDirectory, getDirectoryContents)
14
17
15import Test.HUnit
18import Test.HUnit
16
19
@@ -104,7 +107,8 @@ completionTestData =
104 , ("Control.Monad.ST.new", ["Control.Monad.ST.newSTRef"])
107 , ("Control.Monad.ST.new", ["Control.Monad.ST.newSTRef"])
105 ]
108 ]
106 where
109 where
110+ allModuleNames = [ "Assert"
107− allModuleNames = [ "Control.Monad.Eff"
111+ , "Control.Monad.Eff"
108 , "Control.Monad.ST"
112 , "Control.Monad.ST"
109 , "Data.Function"
113 , "Data.Function"
110 , "Debug.Trace"
114 , "Debug.Trace"
@@ -127,13 +131,18 @@ runCM act = do
127getPSCiState :: IO PSCiState
131getPSCiState :: IO PSCiState
128getPSCiState = do
132getPSCiState = do
129 cwd <- getCurrentDirectory
133 cwd <- getCurrentDirectory
134+ let preludeDir = cwd </> "tests" </> "prelude"
135+ jsDir = preludeDir </> "js"
130− modulesOrFirstError <- loadAllModules [ cwd </> "tests" </> "prelude.purs" ]
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
131 case modulesOrFirstError of
140 case modulesOrFirstError of
132 Left err ->
141 Left err ->
133 print err >> exitFailure
142 print err >> exitFailure
134 Right modules ->
143 Right modules ->
135 let imports = controlMonadSTasST : defaultImports
144 let imports = controlMonadSTasST : defaultImports
136− in return (PSCiState [] imports modules [] [])
145+ in return (PSCiState [] imports modules foreigns [] [])
137
146
138controlMonadSTasST :: ImportedModule
147controlMonadSTasST :: ImportedModule
139controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST"))
148controlMonadSTasST = (s "Control.Monad.ST", P.Implicit, Just (s "ST"))
purescript.cabal+4−2
@@ -159,7 +159,7 @@ executable psc-make
159 main-is: Main.hs
159 main-is: Main.hs
160 buildable: True
160 buildable: True
161 hs-source-dirs: psc-make
161 hs-source-dirs: psc-make
162− other-modules:
162+ other-modules: Make
163 ghc-options: -Wall -O2 -fno-warn-unused-do-bind
163 ghc-options: -Wall -O2 -fno-warn-unused-do-bind
164
164
165executable psci
165executable psci
@@ -176,6 +176,8 @@ executable psci
176 Directive
176 Directive
177 Completion
177 Completion
178 PSCi
178 PSCi
179+ Make
180+ IO
179 ghc-options: -Wall -O2
181 ghc-options: -Wall -O2
180
182
181executable psc-docs
183executable psc-docs
@@ -229,7 +231,7 @@ test-suite psci-tests
229 build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
231 build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
230 mtl -any, optparse-applicative >= 0.10.0, parsec -any,
232 mtl -any, optparse-applicative >= 0.10.0, parsec -any,
231 haskeline >= 0.7.0.0, purescript -any, transformers -any,
233 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
233 type: exitcode-stdio-1.0
235 type: exitcode-stdio-1.0
234 main-is: Main.hs
236 main-is: Main.hs
235 buildable: True
237 buildable: True
src/Language/PureScript/Parser/Lexer.hs+11−4
@@ -240,12 +240,19 @@ parseToken = P.choice
240 parseStringLiteral :: P.Parsec String u String
240 parseStringLiteral :: P.Parsec String u String
241 parseStringLiteral = blockString <|> PT.stringLiteral tokenParser
241 parseStringLiteral = blockString <|> PT.stringLiteral tokenParser
242 where
242 where
243− delimeter = P.try (P.string "\"\"\"")
243+ delimiter = P.try (P.string "\"\"\"")
244− blockString = delimeter >> P.manyTill P.anyChar delimeter
244+ blockString = delimiter >> P.manyTill P.anyChar delimiter
245
245
246 parseNumber :: P.Parsec String u (Either Integer Double)
246 parseNumber :: P.Parsec String u (Either Integer Double)
247+ parseNumber = (consumeLeadingZero >> P.parserZero) <|>
247− parseNumber = (Right <$> P.try (PT.float tokenParser) <|>
248+ (Right <$> P.try (PT.float tokenParser) <|>
248− Left <$> P.try (PT.natural tokenParser)) P.<?> "number"
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"))
249
256
250-- |
257-- |
251-- We use Text.Parsec.Token to implement the string and number lexemes
258-- We use Text.Parsec.Token to implement the string and number lexemes