on master help sign in
Merge pull request #2677 from zgrannan/repl-check-operator

Parse operators as expressions in the REPL

commit5a8536ad1436f7a0f133916db330a041caf81bd3 authorNiklas Larsson <metaniklas@gmail.com> dateFri 23 Oct 2015, 13:51 (11 years ago) parent68c17472c91acc
6 files changed+50−3
CONTRIBUTORS+1 idris.cabal+3 src/Idris/REPLParser.hs+12−3 test/interactive010/expected+22 test/interactive010/input+10 test/interactive010/run+2
CONTRIBUTORS+1
@@ -15,6 +15,7 @@ Jason Dagit
1515Guglielmo Fachini
1616Simon Fowler
1717Google
18+Zack Grannan
1819Cezar Ionescu
1920Heath Johns
2021Irene Knapp
idris.cabal+3
@@ -538,6 +538,9 @@ Extra-source-files:
538538 test/interactive009/input
539539 test/interactive009/*.idr
540540 test/interactive009/expected
541+ test/interactive010/expected
542+ test/interactive010/input
543+ test/interactive010/run
541544
542545 test/io001/run
543546 test/io001/*.idr
src/Idris/REPLParser.hs+12−3
@@ -174,10 +174,9 @@ pCmd :: P.IdrisParser (Either String Command)
174174pCmd = choice [ do c <- cmd names; parser c
175175 | (names, _, _, parser) <- parserCommandsForHelp ++ parserCommands ]
176176 <|> unrecognized
177− <|> nop
177+ <|> nop
178178 <|> eval
179179 where nop = do eof; return (Right NOP)
180− eval = exprArg Eval ""
181180 unrecognized = do
182181 P.lchar ':'
183182 cmd <- many anyChar
@@ -205,16 +204,26 @@ noArgs cmd name = do
205204
206205 emptyArgs <|> failure
207206
207+eval :: P.IdrisParser (Either String Command)
208+eval = do
209+ t <- P.fullExpr defaultSyntax
210+ return $ Right (Eval t)
211+
208212exprArg :: (PTerm -> Command) -> String -> P.IdrisParser (Either String Command)
209213exprArg cmd name = do
210214 let noArg = do
211215 eof
212216 return $ Left ("Usage is :" ++ name ++ " <expression>")
213217
218+ let justOperator = do
219+ (op, fc) <- P.operatorFC
220+ eof
221+ return $ Right $ cmd (PRef fc [] (sUN op))
222+
214223 let properArg = do
215224 t <- P.fullExpr defaultSyntax
216225 return $ Right (cmd t)
217− try noArg <|> properArg
226+ try noArg <|> try justOperator <|> properArg
218227
219228
220229
test/interactive010/expectednew file+22
@@ -0,0 +1,22 @@
1+Prelude.List.(++) : List a -> List a -> List a
2+Prelude.Strings.(++) : String -> String -> String
3+Prelude.Classes./ : (__pi_arg : Float) →
4+ (__pi_arg1 : Float) → Float
5+Usage is :doc <functionname>
6+Usage is :wc <functionname>
7+Usage is :printdef <functionname>
8+prim__divFloat
9+Prelude.Classes./
10+
11+ : Float -> Float -> Float
12+(input):1:1: error: expected: ":",
13+ dependent type signature,
14+ end of input
15+/<EOF>
16+^
17+(input):1:1: error: expected: ":",
18+ dependent type signature,
19+ end of input
20+++<EOF>
21+^
22+prim__divFloat
test/interactive010/inputnew file+10
@@ -0,0 +1,10 @@
1+:type ++
2+:core /
3+:doc +
4+:wc +
5+:printdef -
6+:spec /
7+:patt /
8+/
9+++
10+:whnf /
test/interactive010/runnew file+2
@@ -0,0 +1,2 @@
1+#!/usr/bin/env bash
2+idris --quiet --nobanner --nocolor --consolewidth 80 < input