Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ocamlformat #52

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# git blame master ignore list
#
# This file contains a list of git hashes of revisions to be ignored by git
# blame. These revisions are considered "unimportant" in that they are unlikely
# that they are unlikely to be what you are interested in when blaming.
#
# Instructions:
# - Only large (generally automated) reformatting should be added to this list.
# Do not put things here just because you feel they are trivial or
# unimportant. If in doubt, do not put it on this list.
# - Only put full 40-character hashes on this list (not short hashes or any
# other revision reference).

# First run of dune build @fmt --auto-promote
57dde87123bfb4ca9201e9c903b6e9a060e01760
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@ jobs:
with:
name: sesterl-${{ matrix.os }}
path: sesterl

lint-fmt:
strategy:
matrix:
ocaml-compiler:
- 4.13.x

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: true

- run: opam depext ocamlformat=$(awk -F = 'NR==1 {print $2}' .ocamlformat) --install

- run: opam exec -- make fmt
2 changes: 2 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=0.19.0
profile=conventional
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ clean:
.PHONY: clean-test
clean-test:
rm -f test/_generated/*

.PHONY: fmt
fmt:
dune build @fmt --auto-promote
70 changes: 24 additions & 46 deletions src/address.ml
Original file line number Diff line number Diff line change
@@ -1,74 +1,52 @@

open MyUtil


type element =
| Member of string
| FunctorBody of { arg : string }
type element = Member of string | FunctorBody of { arg : string }
[@@deriving show { with_path = false }]

type t = element Alist.t


let root =
Alist.empty

let root = Alist.empty

let append_member (modnm : string) (address : t) =
Alist.extend address (Member(modnm))

Alist.extend address (Member modnm)

let append_functor_body ~arg:(modnm : string) (address : t) =
Alist.extend address (FunctorBody{ arg = modnm })


let to_list (address : t) =
Alist.to_list address
Alist.extend address (FunctorBody { arg = modnm })

let to_list (address : t) = Alist.to_list address

let subtract ~(long : t) ~(short : t) : t =
let elems_long = Alist.to_list long in
let elems_short = Alist.to_list short in
let rec aux (elems_long : element list) (elems_short : element list) =
match (elems_long, elems_short) with
| ([], _) ->
Alist.empty

| (_ :: _, []) ->
Alist.from_list elems_long

| (elem1 :: tail1, elem2 :: tail2) ->
begin
match (elem1, elem2) with
| (Member(modnm1), Member(modnm2)) ->
if String.equal modnm1 modnm2 then
aux tail1 tail2
else
Alist.from_list elems_long

| (FunctorBody(_), FunctorBody(_)) ->
aux tail1 tail2

| _ ->
Alist.from_list elems_long
end
| [], _ -> Alist.empty
| _ :: _, [] -> Alist.from_list elems_long
| elem1 :: tail1, elem2 :: tail2 -> (
match (elem1, elem2) with
| Member modnm1, Member modnm2 ->
if String.equal modnm1 modnm2 then aux tail1 tail2
else Alist.from_list elems_long
| FunctorBody _, FunctorBody _ -> aux tail1 tail2
| _ -> Alist.from_list elems_long)
in
aux elems_long elems_short


let show (address : t) : string =
let adelems = to_list address in
let ss =
adelems |> List.mapi (fun index adelem ->
match adelem with
| Member(modnm) -> if index = 0 then modnm else Printf.sprintf ".%s" modnm
| FunctorBody(r) -> Printf.sprintf "(%s = ...)" r.arg
)
adelems
|> List.mapi (fun index adelem ->
match adelem with
| Member modnm ->
if index = 0 then modnm else Printf.sprintf ".%s" modnm
| FunctorBody r -> Printf.sprintf "(%s = ...)" r.arg)
in
let s_last = if adelems = [] then "" else "." in
(List.append ss [ s_last ]) |> String.concat ""

List.append ss [ s_last ] |> String.concat ""

let pp (ppf : Format.formatter) (address : t) =
let pp_sep ppf () = Format.fprintf ppf ":" in
Format.fprintf ppf "%a" (Format.pp_print_list ~pp_sep pp_element) (to_list address)
Format.fprintf ppf "%a"
(Format.pp_print_list ~pp_sep pp_element)
(to_list address)
5 changes: 1 addition & 4 deletions src/address.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

type element =
| Member of string
| FunctorBody of { arg : string }
type element = Member of string | FunctorBody of { arg : string }

type t

Expand Down
51 changes: 17 additions & 34 deletions src/assocList.ml
Original file line number Diff line number Diff line change
@@ -1,68 +1,51 @@


module type EQ = sig
type t

val equal : t -> t -> bool
end


module Make(Key : EQ) : sig
module Make (Key : EQ) : sig
type elem

type 'v t

val empty : 'v t
val add_last : elem -> 'v -> 'v t -> ('v t) option

val add_last : elem -> 'v -> 'v t -> 'v t option

val find_opt : elem -> 'v t -> 'v option

val fold_left : ('a -> elem -> 'v -> 'a) -> 'a -> 'v t -> 'a

val values : 'v t -> 'v list

val length : 'v t -> int
end
with type elem = Key.t
= struct

with type elem = Key.t = struct
type elem = Key.t

type 'v t = (elem * 'v) list


let empty = []


let add_last k v assoc =
let rec aux acc xs =
match xs with
| [] ->
Some(List.rev ((k, v) :: acc))

| [] -> Some (List.rev ((k, v) :: acc))
| ((kx, _) as x) :: tail ->
if Key.equal k kx then
None
else
aux (x :: acc) tail
if Key.equal k kx then None else aux (x :: acc) tail
in
aux [] assoc


let rec find_opt k assoc =
match assoc with
| [] ->
None

| (kx, vx) :: tail ->
if Key.equal k kx then
Some(vx)
else
find_opt k tail

| [] -> None
| (kx, vx) :: tail -> if Key.equal k kx then Some vx else find_opt k tail

let fold_left f init assoc =
List.fold_left (fun acc (k, v) -> f acc k v) init assoc

let values assoc = assoc |> List.map snd

let values assoc =
assoc |> List.map snd


let length =
List.length

let length = List.length
end
29 changes: 7 additions & 22 deletions src/boundID.ml
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
type t = { id : int }

type t = {
id : int;
}
let equal bid1 bid2 = bid1.id = bid2.id

let hash bid = bid.id

let equal bid1 bid2 =
bid1.id = bid2.id


let hash bid =
bid.id


let compare bid1 bid2 =
bid2.id - bid1.id

let compare bid1 bid2 = bid2.id - bid1.id

let current_max = ref 0


let initialize () =
current_max := 0

let initialize () = current_max := 0

let fresh () =
incr current_max;
{ id = !current_max; }

{ id = !current_max }

let pp ppf bid =
Format.fprintf ppf "'#%d" bid.id
let pp ppf bid = Format.fprintf ppf "'#%d" bid.id
1 change: 0 additions & 1 deletion src/boundID.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

type t

val initialize : unit -> unit
Expand Down
Loading