-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
393 additions
and
870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ depends: [ | |
"ocaml" | ||
"dune" {>= "3.15"} | ||
"base" | ||
"pprint" | ||
"stdio" | ||
"angstrom" | ||
"ppx_deriving" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
(library | ||
(name LAst) | ||
(public_name NeML.Ast) | ||
(libraries base LMisc) | ||
(libraries base pprint LMisc) | ||
(preprocess | ||
(pps ppx_deriving.show)) | ||
(pps ppx_deriving.show ppx_deriving.enum)) | ||
(instrumentation | ||
(backend bisect_ppx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[@@@ocaml.text "/*"] | ||
|
||
(** Copyright 2024, Andrei, PavlushaSource *) | ||
|
||
(** SPDX-License-Identifier: MIT *) | ||
|
||
[@@@ocaml.text "/*"] | ||
|
||
open! Base | ||
open PPrint | ||
|
||
let parens p = | ||
group @@ align @@ char '(' ^^ align (break 0 ^^ p) ^^ break 0 ^^ char ')' | ||
|
||
let infixl op l r = group @@ l ^^ group (break 1 ^^ op ^^ r) | ||
let infixr op l r = group @@ l ^^ group (break 1) ^^ op ^^ r | ||
|
||
module PrecedencePrinter (Prec : sig | ||
type t | ||
val min : int | ||
val to_enum : t -> int | ||
|
||
val parens : document -> document | ||
end) = | ||
struct | ||
type 'a t = P of (int -> 'a) | ||
|
||
let run' (P f) = f | ||
let run (P f) = f Prec.min | ||
let runf p x = run (p x) | ||
|
||
let ( let* ) p f = P (fun lvl -> run' (f (run' p lvl)) lvl) | ||
|
||
let cur_lvl = P Fn.id | ||
|
||
let pure x = P (fun _ -> x) | ||
|
||
let return' lvl doc = | ||
let* cur = cur_lvl in | ||
pure @@ if cur > lvl then Prec.parens doc else doc | ||
|
||
let return lvl = return' (Prec.to_enum lvl) | ||
|
||
let with_lvl lvl p = pure @@ run' p lvl | ||
|
||
let rprefix lvl op p = | ||
let lvl = Prec.to_enum lvl in | ||
let* doc = with_lvl (lvl + 1) p in | ||
return' lvl (op doc) | ||
|
||
let rinfixl lvl op l r = | ||
let lvl = Prec.to_enum lvl in | ||
let* l = with_lvl lvl l in | ||
let* r = with_lvl (lvl + 1) r in | ||
return' lvl (op l r) | ||
|
||
let rinfixr lvl op l r = | ||
let lvl = Prec.to_enum lvl in | ||
let* l = with_lvl (lvl + 1) l in | ||
let* r = with_lvl lvl r in | ||
return' lvl (op l r) | ||
|
||
let rinfixn lvl op ps = | ||
let lvl = Prec.to_enum lvl in | ||
let* docs = | ||
List.fold_right ps ~init:(pure []) ~f:(fun p acc -> | ||
let* acc = acc in | ||
let* doc = with_lvl (lvl + 1) p in | ||
pure (doc :: acc) ) | ||
in | ||
return' lvl (op docs) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[@@@ocaml.text "/*"] | ||
|
||
(** Copyright 2024, Andrei, PavlushaSource *) | ||
|
||
(** SPDX-License-Identifier: MIT *) | ||
|
||
[@@@ocaml.text "/*"] | ||
|
||
open! Base | ||
open PPrint | ||
|
||
val parens : document -> document | ||
val infixl : document -> document -> document -> document | ||
val infixr : document -> document -> document -> document | ||
|
||
module PrecedencePrinter : functor | ||
(Prec : sig | ||
type t | ||
val min : int | ||
val to_enum : t -> int | ||
|
||
val parens : document -> document | ||
end) | ||
-> sig | ||
type 'a t | ||
|
||
val run : document t -> document | ||
val runf : ('a -> document t) -> 'a -> document | ||
|
||
val return : Prec.t -> document -> document t | ||
|
||
val rprefix : Prec.t -> (document -> document) -> document t -> document t | ||
|
||
val rinfixl : | ||
Prec.t | ||
-> (document -> document -> document) | ||
-> document t | ||
-> document t | ||
-> document t | ||
|
||
val rinfixr : | ||
Prec.t | ||
-> (document -> document -> document) | ||
-> document t | ||
-> document t | ||
-> document t | ||
|
||
val rinfixn : | ||
Prec.t -> (document list -> document) -> document t list -> document t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.