From a75157f31baa16067375b4324fc023dc31d32e8e Mon Sep 17 00:00:00 2001 From: Andrew Li Date: Mon, 11 Aug 2025 16:43:08 -0500 Subject: [PATCH 1/2] document mli files --- lib/ast.mli | 6 ++++++ lib/entry.mli | 1 + lib/header.mli | 3 +++ lib/import.ml | 1 + lib/import.mli | 4 +++- lib/interpreter.mli | 3 +++ lib/io.mli | 1 + lib/literal.mli | 3 +++ lib/program.mli | 1 + lib/record.mli | 2 ++ lib/spreadsheet.mli | 4 ++++ lib/store.mli | 1 + lib/util.mli | 1 + lib/variable.mli | 3 +++ test/expect_tests/cases/enum_program_test.sexp | 1 + test/expect_tests/end_to_end_program_tests.ml | 2 +- 16 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/ast.mli b/lib/ast.mli index 4fc489c..d3c626b 100644 --- a/lib/ast.mli +++ b/lib/ast.mli @@ -1,3 +1,4 @@ +(* ReadConstant reads a const value, like `export const banana: Fruit = Fruit.Banana` *) module ReadConstant : sig type t = { var : string @@ -9,6 +10,7 @@ module ReadConstant : sig val to_string : t -> string end +(* ReadVariable reads a mutable value, like `export let apple: Fruit = Fruit.Apple` *) module ReadVariable : sig type t = { var : string @@ -20,6 +22,7 @@ module ReadVariable : sig val to_string : t -> string end +(* ReadSpreadsheet reads an interface and rows from a spreadsheet at a given path *) module ReadSpreadsheet : sig type t = { var : string @@ -32,6 +35,7 @@ module ReadSpreadsheet : sig val to_string : t -> string end +(* Import imports modules from external ts files, but does not do any type checking *) module Import : sig type t = { var : Variable.T.t @@ -43,6 +47,7 @@ module Import : sig val to_string : t -> string end +(* Export exports everything to either stdout or some file, or some other source *) module Export : sig type t = | File of string @@ -53,6 +58,7 @@ module Export : sig val to_string : t -> string end +(* Node is a node in the AST tree *) module Node : sig type t = | ReadConstant of ReadConstant.t diff --git a/lib/entry.mli b/lib/entry.mli index 71193ef..758134d 100644 --- a/lib/entry.mli +++ b/lib/entry.mli @@ -1 +1,2 @@ +(* Entry point to the entire program, put into a separate file to avoid dependency cycles *) val entry_point : string -> unit diff --git a/lib/header.mli b/lib/header.mli index 3aa2e46..5df9a11 100644 --- a/lib/header.mli +++ b/lib/header.mli @@ -1,3 +1,4 @@ +(* A header of a CSV column, wrapped with sexp decoding *) module T : sig type t = | Enum of string * string (* (type * name) *) @@ -15,12 +16,14 @@ module T : sig val get_string : t -> string end +(* A header parsing wrapper *) module Parser : sig val parse : string -> T.t val parse_all : string list -> T.t list val check_duplicates : T.t list -> unit end +(* A list of headers for a CSV *) type t = T.t list val t_of_sexp : Sexplib0.Sexp.t -> t diff --git a/lib/import.ml b/lib/import.ml index c2af255..41c36d1 100644 --- a/lib/import.ml +++ b/lib/import.ml @@ -1,3 +1,4 @@ module T = struct + type t = string * Variable.T.t let to_string (var, from) = Printf.sprintf "import { %s } from \"%s\";" var from end diff --git a/lib/import.mli b/lib/import.mli index 707ccbb..fd27ec2 100644 --- a/lib/import.mli +++ b/lib/import.mli @@ -1,3 +1,5 @@ +(* Represents a module imported from some file *) module T : sig - val to_string : string * Variable.T.t -> string + type t = string * Variable.T.t + val to_string : t -> string end diff --git a/lib/interpreter.mli b/lib/interpreter.mli index 3b9ef55..207c9b4 100644 --- a/lib/interpreter.mli +++ b/lib/interpreter.mli @@ -1,3 +1,4 @@ +(* Represents a stateful interpreter that stores everything in hash maps *) module T : sig type state = { variable_store : Literal.T.v Store.T.t @@ -8,5 +9,7 @@ module T : sig val interpret_node : state -> Ast.Node.t -> unit val create_blank_state : unit -> state + + (* Entry point to the module, and interprets nodes using List.iter *) val interpret : Program.T.t -> unit end diff --git a/lib/io.mli b/lib/io.mli index 57f1a2c..734452a 100644 --- a/lib/io.mli +++ b/lib/io.mli @@ -1,3 +1,4 @@ +(* Some useful file system utils *) module Files : sig val get_absolute_file_path : string -> string val is_valid_path : string -> bool diff --git a/lib/literal.mli b/lib/literal.mli index 18fed5e..e3c502f 100644 --- a/lib/literal.mli +++ b/lib/literal.mli @@ -1,4 +1,6 @@ +(* Represents a literal value in const/let statements *) module T : sig + (* The actual value. Enum contains the actual enum type, while everything else only contains value. *) type t = | Enum of string * string | String of string @@ -6,6 +8,7 @@ module T : sig | Float of float | Boolean of bool + (* Represents whether is const or let *) type v = | Constant of t | Mutable of t diff --git a/lib/program.mli b/lib/program.mli index ce00830..ed47bae 100644 --- a/lib/program.mli +++ b/lib/program.mli @@ -1,3 +1,4 @@ +(* Represents a program linked list of AST nodes. Type t can be extended with a program counter, but it doesn't really serve a purpose other than being a wrapper. *) module T : sig type ast = Ast.Node.t list diff --git a/lib/record.mli b/lib/record.mli index 43b4b37..0f8cb0f 100644 --- a/lib/record.mli +++ b/lib/record.mli @@ -1,3 +1,4 @@ +(* A single record in a spreadsheet. For the most part identical to Literal, but by no means the same. *) module Value : sig type record_type = | Enum of string @@ -18,6 +19,7 @@ module Value : sig val to_json : t -> string end +(* A spreadsheet row, i.e a list of Record.Value.t *) module T : sig type t = Value.t list diff --git a/lib/spreadsheet.mli b/lib/spreadsheet.mli index 782cdbc..abd7b4d 100644 --- a/lib/spreadsheet.mli +++ b/lib/spreadsheet.mli @@ -1,3 +1,4 @@ +(* A path to a spreadsheet, typed to support future extension *) module Path : sig type t = Csv of string @@ -5,6 +6,7 @@ module Path : sig val sexp_of_t : t -> Sexplib0.Sexp.t end +(* The CSV spreadsheet module *) module Csv0 : sig type t = { headers : Header.T.t list @@ -22,8 +24,10 @@ module Csv0 : sig val get_interface : string -> t -> string end +(* Variant that can support other spreadsheets too *) type t = Csv of Csv0.u +(* Writes any spreadsheet to string *) module Writer : sig val to_string : string * t -> string end diff --git a/lib/store.mli b/lib/store.mli index 31ee32b..eb894ed 100644 --- a/lib/store.mli +++ b/lib/store.mli @@ -1,3 +1,4 @@ +(* A generalised Hashtbl.t backed store for various types, like variables and spreadsheets *) module T : sig type 'a t = { data : (string, 'a) Hashtbl.t } diff --git a/lib/util.mli b/lib/util.mli index d2588a9..7ef4c97 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -1,3 +1,4 @@ +(* Some generic utils *) module T : sig val is_not_space : char -> bool val quote : string -> string diff --git a/lib/variable.mli b/lib/variable.mli index 65f2085..00dc263 100644 --- a/lib/variable.mli +++ b/lib/variable.mli @@ -1,12 +1,15 @@ +(* Checks if a variable name is a reserved keyword *) module Keywords : sig val keywords_list : string list val is_keyword : string -> bool end +(* Checks if a variable name is a valid variable name *) module ValidName : sig val check : string -> bool end +(* Wraps variables, which are just strings, as sexps and around some useful helpers *) module T : sig type t = string [@@deriving sexp] diff --git a/test/expect_tests/cases/enum_program_test.sexp b/test/expect_tests/cases/enum_program_test.sexp index 29b57a5..e477941 100644 --- a/test/expect_tests/cases/enum_program_test.sexp +++ b/test/expect_tests/cases/enum_program_test.sexp @@ -1,5 +1,6 @@ ( (Import ((var Something) (from some-file.ts))) + (ReadConstant ((var apple) (value (Enum Fruit Apple)))) (ReadSpreadsheet ((var "SOME_SHEET") (interface "Type") (path (Csv "./data/sample_spreadsheet_enums.csv")))) (Export Stdout) ) diff --git a/test/expect_tests/end_to_end_program_tests.ml b/test/expect_tests/end_to_end_program_tests.ml index d891992..10826cb 100644 --- a/test/expect_tests/end_to_end_program_tests.ml +++ b/test/expect_tests/end_to_end_program_tests.ml @@ -33,7 +33,7 @@ let%expect_test "passes enums end to end test" = [%expect {| import { Something } from "some-file.ts"; - + export const apple: Fruit = Apple; export interface Type { a: Something; From f89d3ab40353b78f392d7ae56b507a2071d0f674 Mon Sep 17 00:00:00 2001 From: Andrew Li Date: Mon, 11 Aug 2025 16:43:32 -0500 Subject: [PATCH 2/2] reformat --- lib/import.ml | 1 + lib/import.mli | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/import.ml b/lib/import.ml index 41c36d1..58ac4dc 100644 --- a/lib/import.ml +++ b/lib/import.ml @@ -1,4 +1,5 @@ module T = struct type t = string * Variable.T.t + let to_string (var, from) = Printf.sprintf "import { %s } from \"%s\";" var from end diff --git a/lib/import.mli b/lib/import.mli index fd27ec2..c3581f0 100644 --- a/lib/import.mli +++ b/lib/import.mli @@ -1,5 +1,6 @@ (* Represents a module imported from some file *) module T : sig type t = string * Variable.T.t + val to_string : t -> string end