Skip to content

Commit

Permalink
added basic rust sorts
Browse files Browse the repository at this point in the history
  • Loading branch information
green726 committed May 6, 2024
1 parent 6cc6837 commit a86e8ca
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 169 deletions.
42 changes: 0 additions & 42 deletions src/hazel/Sort.re

This file was deleted.

71 changes: 0 additions & 71 deletions src/prop/Grammar.re

This file was deleted.

24 changes: 0 additions & 24 deletions src/prop/dune

This file was deleted.

33 changes: 18 additions & 15 deletions src/hazel/Grammar.re → src/rust/Grammar.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,42 @@ module Pat = {
let tbl = [];
};

module Stat = {
let sort = Sort.of_str("Stat");
let stat = nt(sort)

let tbl = [];
}

module Item = {
let sort = Sort.of_str("Item");
let item = nt(sort);

let tbl = [
//function declaration will be our item
p(seq([]))
]
}


module Exp = {
let sort = Sort.of_str("Exp");
let exp = nt(sort);

[@warning "-32"]
let comma_sep = seq([exp, Star(seq([c(","), exp]))]);

// let rule = seq([tokc("|"), p, tokc("=>"), e]);

// let statement = seq([e, tokc(";")]);
// let block = Star(statement);

let operand =
alt([
t(Int_lit),
t(Float_lit),
t(Id_lower),
// todo: seq([tokc("("), opt(comma_sep), tokc(")")]),
seq([c("("), exp, c(")")]),
// todo: seq([tokc("["), opt(comma_sep), tokc("]")]),
seq([c("["), exp, c("]")]),
// seq([tokc("case"), e, Star(rule), tokc("end")]),
]);

let tokc_alt = ss => alt(List.map(c, ss));
let add_op = tokc_alt(["+", "+.", "-", "-."]);
let mult_op = tokc_alt(["*", "*.", "/", "/."]);
let neg_op = tokc_alt(["-", "-."]);

let tbl = [
p(~a=L, seq([exp, add_op, exp])),
p(~a=L, seq([exp, mult_op, exp])),
p(seq([neg_op, exp])),
p(operand),
];
};
Expand Down
24 changes: 9 additions & 15 deletions src/prop/Sort.re → src/rust/Sort.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@
type t =
| Exp
| Pat
| Stat
| Item
| Typ;

let root = Exp;
let all = [Exp, Pat, Typ];
// let to_int =
// fun
// | Exp => 0
// | Pat => 1
// | Typ => 2;
// let of_int =
// fun
// | 0 => Exp
// | 1 => Pat
// | 2 => Typ
// | _ => raise(Invalid_argument(""));
// let compare = (s1, s2) => Int.compare(to_int(s1), to_int(s2));
// let lca = (s1, s2) => of_int(Int.min(to_int(s1), to_int(s2)));
let root = Item;
let all = [Exp, Pat, Typ, Item, Stat];


let to_str =
fun
| Typ => "Typ"
| Pat => "Pat"
// | Rul => "Rul"
| Item => "Item"
| Stat => "Stat"
| Exp => "Exp";

let of_str =
fun
| "Typ" => Typ
| "Pat" => Pat
| "Exp" => Exp
| "Stat" => Stat
| "Item" => Item
| _ => raise(Invalid_argument("Sort.of_string: unrecognized sort"));

module Ord = {
Expand Down
2 changes: 1 addition & 1 deletion src/hazel/dune → src/rust/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(include_subdirs unqualified)

(library
(name tylr_hazel)
(name tylr_rust)
(libraries util re sexplib)
(implements tylr_core)
(js_of_ocaml
Expand Down
2 changes: 1 addition & 1 deletion src/web/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(executable
(name main)
(modules Main)
(libraries tylr_web tylr_hazel)
(libraries tylr_web tylr_rust)
(modes js)
(js_of_ocaml
(flags
Expand Down

0 comments on commit a86e8ca

Please sign in to comment.