2015-02-24 07:22:58 +03:00
|
|
|
module REPL
|
|
|
|
open System
|
|
|
|
|
|
|
|
let read input =
|
2015-03-01 07:07:55 +03:00
|
|
|
try
|
2015-03-01 18:49:55 +03:00
|
|
|
Reader.read_str input
|
2015-03-01 07:07:55 +03:00
|
|
|
with
|
2015-03-12 05:13:31 +03:00
|
|
|
| Types.ReaderError(msg) ->
|
2015-03-05 04:14:07 +03:00
|
|
|
printfn "%s" msg
|
|
|
|
[]
|
2015-02-24 07:22:58 +03:00
|
|
|
|
|
|
|
let eval ast =
|
2015-03-01 07:07:55 +03:00
|
|
|
Some(ast)
|
2015-02-24 07:22:58 +03:00
|
|
|
|
|
|
|
let print v =
|
|
|
|
v
|
2015-03-26 22:05:02 +03:00
|
|
|
|> Seq.singleton
|
2015-02-24 07:22:58 +03:00
|
|
|
|> Printer.pr_str
|
2015-03-01 07:07:55 +03:00
|
|
|
|> printfn "%s"
|
2015-02-24 07:22:58 +03:00
|
|
|
|
|
|
|
let rep input =
|
2015-03-05 04:14:07 +03:00
|
|
|
read input
|
|
|
|
|> Seq.ofList
|
|
|
|
|> Seq.map (fun form -> eval form)
|
|
|
|
|> Seq.filter Option.isSome
|
|
|
|
|> Seq.iter (fun value -> print value.Value)
|
2015-03-01 07:07:55 +03:00
|
|
|
|
|
|
|
let getReadlineMode (args : string array) =
|
|
|
|
if args.Length > 0 && args.[0] = "--raw" then
|
|
|
|
Readline.Mode.Raw
|
|
|
|
else
|
|
|
|
Readline.Mode.Terminal
|
2015-02-24 07:22:58 +03:00
|
|
|
|
|
|
|
[<EntryPoint>]
|
|
|
|
let rec main args =
|
2015-03-01 07:07:55 +03:00
|
|
|
let mode = getReadlineMode args
|
2015-02-24 07:22:58 +03:00
|
|
|
match Readline.read "user> " mode with
|
|
|
|
| null -> 0
|
|
|
|
| input ->
|
|
|
|
rep input
|
|
|
|
main args
|