-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add executable for interactive collider
- Loading branch information
Showing
6 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
(executable | ||
(public_name lsc) | ||
(name lsc) | ||
(libraries lsc)) | ||
(executables | ||
(public_names lsc ilsc) | ||
(names lsc ilsc) | ||
(libraries lsclib base)) | ||
(env | ||
(dev | ||
(flags (:standard -warn-error -A)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
open Base | ||
open Lsclib.Stellar | ||
open Lsclib.Parser | ||
|
||
let welcome () = | ||
Stdlib.print_string "Commands :--------------------------------------\n"; | ||
Stdlib.print_string "<constellation>\t\tMake a new constellation interacts | ||
\t\t\twith the previous interaction space\n\t\t\t({} at beginning)\n"; | ||
Stdlib.print_string "exit|e|q\t\tquit the program\n"; | ||
Stdlib.print_string "clear|c\t\t\tclear interaction space\n"; | ||
Stdlib.print_string "delete|del|d\t\tdelete a star at some index\n"; | ||
Stdlib.print_string "add|a\t\t\tadd stars\n"; | ||
Stdlib.print_string "------------------------------------------------\n" | ||
|
||
let prompt mode = | ||
Stdlib.print_string (mode ^ " >> "); | ||
Stdlib.read_line () | ||
|
||
let rec delete cs = | ||
let input = prompt "Delete star of index" in | ||
try | ||
let n = Int.of_string input in | ||
List.filteri ~f:(fun i _ -> not (equal_int i n)) cs | ||
with Failure _ -> | ||
Stdlib.print_string "This is not a positive integer. Please retry.\n"; | ||
delete cs | ||
|
||
let unmark = function | ||
| Marked s -> s | ||
| Unmarked s -> s | ||
|
||
let rec add cs = | ||
let input = prompt "Add stars" in | ||
try | ||
let lexbuf = Lexing.from_string input in | ||
let mcs = marked_constellation Lsclib.Lexer.read lexbuf in | ||
cs @ (List.map ~f:unmark mcs) | ||
with _ -> | ||
Stdlib.print_string "Error. Please retry.\n"; | ||
add cs | ||
|
||
let rec loop (cs : constellation) = | ||
cs |> string_of_constellation |> Stdlib.print_string; | ||
Stdlib.print_newline (); | ||
let input = prompt "Send" in | ||
if (List.mem ~equal:equal_string ["exit"; "e"; "q"] input) then | ||
Stdlib.exit 0 | ||
else if (List.mem ~equal:equal_string ["clear"; "c"] input) then | ||
loop [] | ||
else if (List.mem ~equal:equal_string ["delete"; "del"; "d"] input) then | ||
loop (delete cs) | ||
else if (List.mem ~equal:equal_string ["add"; "a"] input) then | ||
loop (add cs) | ||
else | ||
begin | ||
let base = List.map ~f:(fun s -> Marked s) cs in | ||
let lexbuf = Lexing.from_string input in | ||
try | ||
let mcs = marked_constellation Lsclib.Lexer.read lexbuf in | ||
let cs = extract_intspace (base @ mcs) in | ||
let result = | ||
exec ~unfincomp:true | ||
~withloops:false | ||
~showtrace:false | ||
~selfint:false | ||
~showsteps:false cs in | ||
loop result | ||
with _ -> | ||
Stdlib.print_string "Error. Please retry.\n"; | ||
loop cs | ||
end | ||
|
||
let _ = | ||
welcome (); | ||
loop []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(library | ||
(name lsc) | ||
(name lsclib) | ||
(libraries base)) | ||
(env | ||
(dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters