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 #21

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions spectec/.ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
profile = default
break-infix = wrap-or-vertical
break-string-literals = never
cases-exp-indent=2
dock-collection-brackets = false
exp-grouping = preserve
if-then-else = fit-or-vertical
indicate-multiline-delimiters = closing-on-separate-line
leading-nested-match-parens = true
space-around-arrays = false
space-around-lists = false
space-around-records = false
space-around-variants = false
36 changes: 15 additions & 21 deletions spectec/src/backend-latex/config.ml
Original file line number Diff line number Diff line change
@@ -1,48 +1,42 @@
type anchor =
{
token : string; (* anchor token *)
prefix : string; (* prefix generated for splice *)
suffix : string; (* suffix generated for splice *)
indent : string; (* inserted after generated newlines *)
{ token : string; (* anchor token *)
prefix : string; (* prefix generated for splice *)
suffix : string; (* suffix generated for splice *)
indent : string (* inserted after generated newlines *)
}

type config =
{
(* Anchor token for splices (default: "@@"/"@@@") *)
{ (* Anchor token for splices (default: "@@"/"@@@") *)
anchors : anchor list;

(* Generate id's as macro calls `\id` instead of `\mathit{id}` *)
macros_for_ids : bool;

(* Generate vdash's as macro calls `\vdashRelid` instead of `\vdash` *)
macros_for_vdash : bool;

(* Decorate grammars with l.h.s. description like "(instruction) instr ::= ..." *)
include_grammar_desc : bool;
include_grammar_desc : bool
}

type t = config


let default =
{ anchors = [];
macros_for_ids = false;
macros_for_vdash = false;
include_grammar_desc = false;
include_grammar_desc = false
}

let latex =
{ default with
anchors = [
{token = "@@"; prefix = "$"; suffix ="$"; indent = ""};
{token = "@@@"; prefix = "$$\n"; suffix = "\n$$"; indent = ""};
]
anchors =
[ {token = "@@"; prefix = "$"; suffix = "$"; indent = ""};
{token = "@@@"; prefix = "$$\n"; suffix = "\n$$"; indent = ""}
]
}

let sphinx =
{ default with
anchors = [
{token = "$"; prefix = ":math:`"; suffix ="`"; indent = ""};
{token = "$$"; prefix = ".. math::\n "; suffix = ""; indent = " "};
]
anchors =
[ {token = "$"; prefix = ":math:`"; suffix = "`"; indent = ""};
{token = "$$"; prefix = ".. math::\n "; suffix = ""; indent = " "}
]
}
7 changes: 3 additions & 4 deletions spectec/src/backend-latex/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(library
(name backend_latex)
(libraries util el frontend str)
(modules config render gen splice)
)
(name backend_latex)
(libraries util el frontend str)
(modules config render gen splice))
9 changes: 6 additions & 3 deletions spectec/src/backend-latex/gen.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
let gen_string ?(decorated = true) el =
let env = Render.env Config.latex el
let env =
Render.env Config.latex el
|> Render.with_syntax_decoration decorated
|> Render.with_rule_decoration decorated
in Render.render_script env el
in
Render.render_script env el

let gen_file ?(decorated = true) file el =
let latex = gen_string ~decorated el in
let oc = Out_channel.open_text file in
Fun.protect (fun () -> Out_channel.output_string oc latex)
Fun.protect
(fun () -> Out_channel.output_string oc latex)
~finally:(fun () -> Out_channel.close oc)
Loading