Skip to content

Commit

Permalink
fsharp: added some top level exception catching so that the repl woul…
Browse files Browse the repository at this point in the history
…dn't quit to CLI on errors.
  • Loading branch information
pstephens committed Dec 26, 2016
1 parent 3c823be commit df8c925
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 23 deletions.
12 changes: 9 additions & 3 deletions fsharp/step2_eval.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg)
| Error.ReaderError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
12 changes: 9 additions & 3 deletions fsharp/step3_env.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg)
| Error.ReaderError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
12 changes: 9 additions & 3 deletions fsharp/step4_if_fn_do.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg)
| Error.ReaderError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
12 changes: 9 additions & 3 deletions fsharp/step5_tco.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg)
| Error.ReaderError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
12 changes: 9 additions & 3 deletions fsharp/step6_file.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg)
| Error.ReaderError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
11 changes: 9 additions & 2 deletions fsharp/step7_quote.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
11 changes: 9 additions & 2 deletions fsharp/step8_macros.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
11 changes: 9 additions & 2 deletions fsharp/step9_try.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down
11 changes: 9 additions & 2 deletions fsharp/stepA_mal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ module REPL
try
Some(eval env ast)
with
| Error.EvalError(msg) ->
printfn "%s" msg
| Error.EvalError(str)
| Error.ReaderError(str) ->
printfn "%s" str
None
| Error.MalError(node) ->
printfn "%s" (Printer.pr_str [node])
None
| ex ->
printfn "%s" (ex.Message)
None

let PRINT v =
Expand Down

0 comments on commit df8c925

Please sign in to comment.