on master help sign in
Fix parser bug: whitespace now allowed at the top of modules
a12ecc2Edwin Brady
src/Idris/Parser.hs+5−4
@@ -141,22 +141,23 @@ parseTac i = runParser (do t <- pTactic defaultSyntax
141parseImports :: FilePath -> String -> Idris ([String], [String], String, SourcePos)
141parseImports :: FilePath -> String -> Idris ([String], [String], String, SourcePos)
142parseImports fname input
142parseImports fname input
143 = do i <- get
143 = do i <- get
144+ case (runParser (do whiteSpace
144− case (runParser (do mname <- pHeader
145+ mname <- pHeader
145 ps <- many pImport
146 ps <- many pImport
146 rest <- getInput
147 rest <- getInput
147 pos <- getPosition
148 pos <- getPosition
148 return ((mname, ps, rest, pos), i)) i fname input) of
149 return ((mname, ps, rest, pos), i)) i fname input) of
149− Left err -> fail (ishow err)
150+ Left err -> fail (show err)
150 Right (x, i) -> do put i
151 Right (x, i) -> do put i
151 return x
152 return x
152 where ishow err = let ln = sourceLine (errorPos err) in
153 where ishow err = let ln = sourceLine (errorPos err) in
153 fname ++ ":" ++ show ln ++ ":parse error"
154 fname ++ ":" ++ show ln ++ ":parse error"
154−-- show (map messageString (errorMessages err))
155+-- ++ show (map messageString (errorMessages err))
155
156
156pHeader :: IParser [String]
157pHeader :: IParser [String]
157pHeader = try (do reserved "module"; i <- identifier; option ';' (lchar ';')
158pHeader = try (do reserved "module"; i <- identifier; option ';' (lchar ';')
158 return (parseName i))
159 return (parseName i))
159− <|> return []
160+ <|> return []
160 where parseName x = case span (/='.') x of
161 where parseName x = case span (/='.') x of
161 (x, "") -> [x]
162 (x, "") -> [x]
162 (x, '.':y) -> x : parseName y
163 (x, '.':y) -> x : parseName y