-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.ml
42 lines (33 loc) · 1.29 KB
/
module.ml
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
39
40
41
42
open Prelude
open Elab
open Expr
type command =
| Nope
| Eval of exp
| Action of string
| Command of string * exp
type decl =
| Def of string * exp option * exp
| Axiom of string * exp
type line =
| Import of string list
| Option of string * string
| Decl of decl
type content = line list
type file = string * content
let moduleSep = '/'
let getPath = String.split_on_char moduleSep >> String.concat Filename.dir_sep
let showDecl : decl -> string = function
| Def (p, Some exp1, exp2) -> Printf.sprintf "def %s : %s := %s" p (showExp exp1) (showExp exp2)
| Def (p, None, exp) -> Printf.sprintf "def %s := %s" p (showExp exp)
| Axiom (p, exp) -> Printf.sprintf "axiom %s : %s" p (showExp exp)
let showLine : line -> string = function
| Import p -> Printf.sprintf "import %s" (String.concat " " p)
| Option (opt, value) -> Printf.sprintf "option %s %s" opt value
| Decl d -> showDecl d
let showContent x = String.concat "\n" (List.map showLine x)
let showFile : file -> string = function | (p, x) -> Printf.sprintf "module %s where\n%s" p (showContent x)
let freshDecl : decl -> decl = function
| Def (p, Some exp1, exp2) -> Def (p, Some (freshExp exp1), freshExp exp2)
| Def (p, None, exp) -> Def (p, None, freshExp exp)
| Axiom (p, exp) -> Axiom (p, freshExp exp)