on master help sign in
Merge pull request #1734 from soimort/fix-repl
1a8f1dbEdwin Brady
src/Idris/REPLParser.hs+7−7
@@ -20,11 +20,11 @@ import Text.Trifecta.Delta
20import Debug.Trace
20import Debug.Trace
21import Data.List
21import Data.List
22import Data.List.Split(splitOn)
22import Data.List.Split(splitOn)
23−import Data.Char(toLower)
23+import Data.Char(isSpace, toLower)
24import qualified Data.ByteString.UTF8 as UTF8
24import qualified Data.ByteString.UTF8 as UTF8
25
25
26parseCmd :: IState -> String -> String -> Result (Either String Command)
26parseCmd :: IState -> String -> String -> Result (Either String Command)
27−parseCmd i inputname = P.runparser pCmd i inputname
27+parseCmd i inputname = P.runparser pCmd i inputname . dropWhile isSpace
28
28
29pCmd :: P.IdrisParser (Either String Command)
29pCmd :: P.IdrisParser (Either String Command)
30pCmd = choice [ do c <- cmd ["q", "quit"]; noArgs c Quit
30pCmd = choice [ do c <- cmd ["q", "quit"]; noArgs c Quit
@@ -95,20 +95,20 @@ pCmd = choice [ do c <- cmd ["q", "quit"]; noArgs c Quit
95 <|> eval
95 <|> eval
96 where nop = do P.whiteSpace; eof; return (Right NOP)
96 where nop = do P.whiteSpace; eof; return (Right NOP)
97 eval = exprArg "" Eval
97 eval = exprArg "" Eval
98− unrecognized = do
98+ unrecognized = do
99− P.lchar ':'
99+ P.lchar ':'
100 cmd <- many anyChar
100 cmd <- many anyChar
101 let cmd' = takeWhile (/=' ') cmd
101 let cmd' = takeWhile (/=' ') cmd
102 return (Left $ "Unrecognized command: " ++ cmd')
102 return (Left $ "Unrecognized command: " ++ cmd')
103
103
104cmd :: [String] -> P.IdrisParser String
104cmd :: [String] -> P.IdrisParser String
105−cmd xs = try $ do
105+cmd xs = try $ do
106 P.lchar ':'
106 P.lchar ':'
107 docmd sorted_xs
107 docmd sorted_xs
108−
108+
109 where docmd [] = fail "Could not parse command"
109 where docmd [] = fail "Could not parse command"
110 docmd (x:xs) = try (P.reserved x >> return x) <|> docmd xs
110 docmd (x:xs) = try (P.reserved x >> return x) <|> docmd xs
111−
111+
112 sorted_xs = sortBy (\x y -> compare (length y) (length x)) xs
112 sorted_xs = sortBy (\x y -> compare (length y) (length x)) xs
113
113
114
114