Skip to content

Commit

Permalink
Add Eq deriving so that we can test the full editor
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 13, 2024
1 parent c1c0eba commit f8fd59e
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 57 deletions.
3 changes: 2 additions & 1 deletion src/haz3lcore/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
js_of_ocaml-ppx
ppx_let
ppx_sexp_conv
ppx_deriving.show)))
ppx_deriving.show
ppx_deriving.eq)))

(env
(dev
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/lang/Precedence.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Util;
/**
* higher precedence means lower int representation
*/
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = int;

let max: t = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/lang/Sort.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Any
| Nul
Expand Down
6 changes: 4 additions & 2 deletions src/haz3lcore/tiles/Base.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Util;
/* The different kinds of projector. New projectors
* types need to be registered here in order to be
* able to create and update their instances */
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type kind =
| Fold
| Info
Expand All @@ -12,7 +12,7 @@ type kind =
| SliderF
| TextArea;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type segment = list(piece)
and piece =
| Tile(tile)
Expand All @@ -25,13 +25,15 @@ and tile = {
// - length(shards) <= length(label)
// - length(shards) == length(children) + 1
// - sort(shards) == shards
[@equal (_, _) => true]
id: Id.t,
label: Label.t,
mold: Mold.t,
shards: list(int),
children: list(segment),
}
and projector = {
[@equal (_, _) => true]
id: Id.t,
kind,
syntax: piece,
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lcore/tiles/Grout.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type shape =
| Convex
| Concave;
Expand All @@ -10,7 +10,7 @@ type t = {
id: Id.t,
shape,
};

let equal = (a: t, b: t) => a.shape == b.shape;
let id = g => g.id;

let shapes = g =>
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Label.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Util;

/* A label is the textual expression of a form's delimiters */
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = list(Token.t);
exception Empty_label;
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Mold.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
out: Sort.t,
in_: list(Sort.t),
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lcore/tiles/Nib.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Util;

module Shape = {
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Convex
| Concave(Precedence.t);
Expand Down Expand Up @@ -45,7 +45,7 @@ module Shape = {
};
};

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
shape: Shape.t,
sort: Sort.t,
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Nibs.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = (Nib.t, Nib.t);

[@deriving show]
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Piece.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include Base;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = piece;

let secondary = w => Secondary(w);
Expand Down
5 changes: 3 additions & 2 deletions src/haz3lcore/tiles/Secondary.re
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type cls =
| Whitespace
| Comment;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type secondary_content =
| Whitespace(string)
| Comment(string);
Expand All @@ -16,6 +16,7 @@ type t = {
content: secondary_content,
};

let equal = (a: t, b: t) => a.content == b.content;
let cls_of = (s: t): cls =>
switch (s.content) {
| Whitespace(_) => Whitespace
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Segment.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Util;

exception Empty_segment;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = Base.segment;

let empty = [];
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/tiles/Token.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Util;

// make an enum
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = string;

module Index = {
Expand Down
5 changes: 3 additions & 2 deletions src/haz3lcore/zipper/Ancestor.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ open Util;

exception Empty_shard_affix;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type step = int;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
[@equal (_, _) => true]
id: Id.t,
label: Label.t,
mold: Mold.t,
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lcore/zipper/Ancestors.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type generation = (Ancestor.t, Siblings.t);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = list(generation);

let empty = [];
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/Backpack.re
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ module ShardInfo = {
};
};

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = list(Selection.t);

let empty = [];
Expand Down
7 changes: 4 additions & 3 deletions src/haz3lcore/zipper/Editor.re
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module State = {
meta: Meta.t,
};

let equal = (a: t, b: t) => Zipper.equal(a.zipper, b.zipper);
let init = (zipper, ~settings: CoreSettings.t) => {
zipper,
meta: Meta.init(zipper, ~settings),
Expand All @@ -148,9 +149,9 @@ module State = {
};

module History = {
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type affix = list((Action.t, State.t));
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = (affix, affix);

let empty = ([], []);
Expand All @@ -161,7 +162,7 @@ module History = {
);
};

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
state: State.t,
history: History.t,
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/Relatives.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
siblings: Siblings.t,
ancestors: Ancestors.t,
Expand Down
6 changes: 3 additions & 3 deletions src/haz3lcore/zipper/Selection.re
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type buffer =
//| Parsed
| Unparsed;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type mode =
| Normal
| Buffer(buffer);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
focus: Direction.t,
content: Segment.t,
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/Siblings.re
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Util;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = (Segment.t, Segment.t);

let empty = Segment.(empty, empty);
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lcore/zipper/Zipper.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ let init: unit => t =

let next_blank = _ => Id.mk();

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type chunkiness =
| ByChar
| MonoByChar
| ByToken;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type planar =
| Up
| Down
Expand Down
4 changes: 2 additions & 2 deletions src/haz3lcore/zipper/ZipperBase.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Util;

module Caret = {
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Outer
| Inner(int, int);
Expand All @@ -19,7 +19,7 @@ module Caret = {
};

// assuming single backpack, shards may appear in selection, backpack, or siblings
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t = {
selection: Selection.t,
backpack: Backpack.t,
Expand Down
36 changes: 18 additions & 18 deletions src/haz3lcore/zipper/action/Action.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Util;

open Zipper;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type piece_goal =
| Grout;

Expand All @@ -14,28 +14,28 @@ let of_piece_goal =
| _ => false
);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type goal =
| Point(Point.t)
| Piece(piece_goal, Direction.t);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type move =
| Extreme(planar)
| Local(planar)
| Goal(goal);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type jump_target =
| TileId(Id.t)
| TileId([@equal (_, _) => true] Id.t)
| BindingSiteOfIndicatedVar;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type rel =
| Current
| Id(Id.t, Direction.t);
| Id([@equal (_, _) => true] Id.t, Direction.t);

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type select =
| All
| Resize(move)
Expand All @@ -47,27 +47,27 @@ type select =
* projectors,as distinguished from external_action,
* which defines the actions available internally to all projectors,
* and from each projector's own internal action type */
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type project =
| SetIndicated(Base.kind) /* Project syntax at caret */
| ToggleIndicated(Base.kind) /* Un/Project syntax at caret */
| Remove(Id.t) /* Remove projector at Id */
| SetSyntax(Id.t, Piece.t) /* Set underlying syntax */
| SetModel(Id.t, string) /* Set serialized projector model */
| Focus(Id.t, option(Util.Direction.t)) /* Pass control to projector */
| Escape(Id.t, Direction.t); /* Pass control to parent editor */
| Remove([@equal (_, _) => true] Id.t) /* Remove projector at Id */
| SetSyntax([@equal (_, _) => true] Id.t, Piece.t) /* Set underlying syntax */
| SetModel([@equal (_, _) => true] Id.t, string) /* Set serialized projector model */
| Focus([@equal (_, _) => true] Id.t, option(Util.Direction.t)) /* Pass control to projector */
| Escape([@equal (_, _) => true] Id.t, Direction.t); /* Pass control to parent editor */

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type agent =
| TyDi;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type buffer =
| Set(agent)
| Clear
| Accept;

[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Reparse
| Buffer(buffer)
Expand All @@ -87,7 +87,7 @@ type t =
| Put_down;

module Failure = {
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Cant_move
| Cant_insert
Expand Down
2 changes: 1 addition & 1 deletion src/util/Direction.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[@deriving (show({with_path: false}), sexp, yojson)]
[@deriving (show({with_path: false}), sexp, yojson, eq)]
type t =
| Left
| Right;
Expand Down
Loading

0 comments on commit f8fd59e

Please sign in to comment.