-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.fs
More file actions
41 lines (32 loc) · 1.07 KB
/
repl.fs
File metadata and controls
41 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Repl
open IncTypes
open Inc
open System
open Utils
let prn v = print v
let prep env =
List.ofSeq >> parse "__REPL__" >> List.head >> (eval id env) >> prn
let rep env =
let eval' e =
try eval id env e
with ex -> Dummy("Exception : " + ex.Message) |> e2v
List.ofSeq >> parse "__REPL__" >> List.head >> eval' >> prn
let rec readFormFromConsole(rem) =
let s = rem + Console.ReadLine()
let mutable i = 0
while i < s.Length && Char.IsWhiteSpace(s.[i]) do i <- i + 1
let ti = i
if s.[i].In( [ '{'; '['; '(' ] ) then
let rec readRest (s : string) =
let j = findBalancer s.[ti] s ti
if j > 0 then
if j = s.Length - 1 then s
else
s.Substring(0,j) |> rep [] |> printf "%s\n"
readFormFromConsole(s.Substring(j+1))
else readRest (s + "\n" + Console.ReadLine())
readRest s
else s
let rec repl output =
printf "%s\n%s=> " output Globals.DefaultNS.Name
readFormFromConsole("") |> rep [] |> repl