Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ast.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(* ReadConstant reads a const value, like `export const banana: Fruit = Fruit.Banana` *)
module ReadConstant : sig
type t =
{ var : string
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/entry.mli
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
(* Entry point to the entire program, put into a separate file to avoid dependency cycles *)
val entry_point : string -> unit
3 changes: 3 additions & 0 deletions lib/header.mli
Original file line number Diff line number Diff line change
@@ -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) *)
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/import.ml
Original file line number Diff line number Diff line change
@@ -1,3 +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
5 changes: 4 additions & 1 deletion lib/import.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
(* 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
3 changes: 3 additions & 0 deletions lib/interpreter.mli
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/io.mli
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/literal.mli
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
(* 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
| Integer of int
| Float of float
| Boolean of bool

(* Represents whether is const or let *)
type v =
| Constant of t
| Mutable of t
Expand Down
1 change: 1 addition & 0 deletions lib/program.mli
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/record.mli
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/spreadsheet.mli
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
(* A path to a spreadsheet, typed to support future extension *)
module Path : sig
type t = Csv of string

val t_of_sexp : Sexplib0.Sexp.t -> t
val sexp_of_t : t -> Sexplib0.Sexp.t
end

(* The CSV spreadsheet module *)
module Csv0 : sig
type t =
{ headers : Header.T.t list
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/store.mli
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down
1 change: 1 addition & 0 deletions lib/util.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(* Some generic utils *)
module T : sig
val is_not_space : char -> bool
val quote : string -> string
Expand Down
3 changes: 3 additions & 0 deletions lib/variable.mli
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
1 change: 1 addition & 0 deletions test/expect_tests/cases/enum_program_test.sexp
Original file line number Diff line number Diff line change
@@ -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)
)
2 changes: 1 addition & 1 deletion test/expect_tests/end_to_end_program_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down