Skip to content

Commit

Permalink
Merge pull request #19 from AltGr/no-camlp4
Browse files Browse the repository at this point in the history
Remove uses of Camlp4
  • Loading branch information
Pierrick Couderc committed Jun 1, 2018
2 parents ce0d038 + 35dea12 commit 73eace9
Show file tree
Hide file tree
Showing 26 changed files with 551 additions and 571 deletions.
4 changes: 1 addition & 3 deletions learn-ocaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ depends: [
"ocp-build" {build}
"base64"
"ezjsonm"
"camlp4"
"js_of_ocaml" {= "3.1.0" }
"js_of_ocaml-camlp4"
"js_of_ocaml-ppx"
"js_of_ocaml-toplevel"
"js_of_ocaml-compiler"
"js_of_ocaml-lwt"
Expand All @@ -27,7 +26,6 @@ depends: [
"ocp-indent-nlfork"
"ocp-ocamlres" {= "0.4"}
"ocplib-json-typed" {= "0.6"}
"optcomp"
"pprint"
"ppx_tools"
"react"
Expand Down
4 changes: 1 addition & 3 deletions learn-ocaml.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ depends: [
"cmdliner" {= "1.0.2"}
"yojson" {= "1.4.1"}
"js_of_ocaml-compiler" {= "3.1.0"}
"camlp4" {= "4.05+1"}
"js_of_ocaml" {= "3.1.0"}
"lwt" {= "3.1.0"}
"uutf" {= "1.0.1"}
Expand All @@ -33,15 +32,14 @@ depends: [
"pprint" {= "20171003"}
"cohttp-lwt-unix" {= "1.0.2"}
"ezjsonm" {= "0.5.0"}
"js_of_ocaml-camlp4" {= "3.1.0"}
"js_of_ocaml-ppx" {= "3.1.0"}
"js_of_ocaml-lwt" {= "3.1.0"}
"js_of_ocaml-toplevel" {= "3.1.0"}
"js_of_ocaml-tyxml" {= "3.1.0"}
"ocp-indent-nlfork" {= "dev"}
"ocp-ocamlres" {= "0.4"}
"ocplib-json-typed" {= "0.6"}
"omd" {= "1.3.1"}
"optcomp" {= "1.6"}
"ppx_cstruct" {= "3.2.1"}
"ppx_tools" {= "5.0+4.05.0"}
]
Expand Down
1 change: 0 additions & 1 deletion scripts/install-opam-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ opam pin add --yes --no-action ocp-ocamlres \
"https://github.com/OCamlPro/ocp-ocamlres.git"
opam pin add --yes --no-action ocplib-json-typed 0.6
opam pin add --yes --no-action learn-ocaml-deps src
opam install camlp4 --yes
opam depext learn-ocaml-deps
if opam list --installed learn-ocaml-deps
then opam upgrade learn-ocaml-deps ocp-indent-nlfork ocplib-json-typed ocp-ocamlres
Expand Down
154 changes: 77 additions & 77 deletions src/ace-lib/ace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,72 +31,72 @@ type 'a editor = {
}

let ace : Ace_types.ace Js.t = Js.Unsafe.variable "ace"
let edit el = ace##edit (el)
let edit el = ace##(edit el)

let create_position r c =
let pos : position Js.t = Js.Unsafe.obj [||] in
pos##row <- r;
pos##column <- c;
pos##.row := r;
pos##.column := c;
pos
let greater_position p1 p2 =
p1##row > p2##row ||
(p1##row = p2##row && p1##column > p2##column)
p1##.row > p2##.row ||
(p1##.row = p2##.row && p1##.column > p2##.column)


let create_range s e =
let range : range Js.t = Js.Unsafe.obj [||] in
range##start <- s;
range##end_ <- e;
range##.start := s;
range##.end_ := e;
range

let read_position pos = (pos##row, pos##column)
let read_position pos = (pos##.row, pos##.column)

let read_range range =
((range##start##row, range##start##column),
(range##end_##row, range##end_##column))
((range##.start##.row, range##.start##.column),
(range##.end_##.row, range##.end_##.column))

let get_contents ?range {editor} =
let document = editor##getSession()##getDocument() in
let document = (editor##getSession)##getDocument in
match range with
| None ->
Js.to_string @@ document##getValue()
Js.to_string @@ document##getValue
| Some r ->
Js.to_string @@ document##getTextRange(r)
Js.to_string @@ document##(getTextRange r)

let set_contents {editor} code =
let document = editor##getSession()##getDocument() in
document##setValue (Js.string code)
let document = (editor##getSession)##getDocument in
document##(setValue (Js.string code))

let get_selection_range {editor} = editor##getSelectionRange()
let get_selection_range {editor} = editor##getSelectionRange

let get_selection {editor} =
let document = editor##getSession()##getDocument() in
let range = editor##getSelectionRange() in
Js.to_string @@ document##getTextRange(range)
let document = (editor##getSession)##getDocument in
let range = editor##getSelectionRange in
Js.to_string @@ document##(getTextRange range)

let get_line {editor} line =
let document = editor##getSession()##getDocument() in
Js.to_string @@ document##getLine (line)
let document = (editor##getSession)##getDocument in
Js.to_string @@ document##(getLine line)

let create_editor editor_div =
let editor = edit editor_div in
Js.Unsafe.set editor "$blockScrolling" (Js.Unsafe.variable "Infinity");
let data =
{ editor; editor_div; marks = []; keybinding_menu = false; } in
editor##customData <- (data, None);
editor##.customData := (data, None);
data

let get_custom_data { editor } =
match snd editor##customData with
match snd editor##.customData with
| None -> raise Not_found
| Some x -> x

let set_custom_data { editor } data =
let ed = fst editor##customData in
editor##customData <- (ed, Some data)
let ed = fst editor##.customData in
editor##.customData := (ed, Some data)

let set_mode {editor} name =
editor##getSession()##setMode (Js.string name)
editor##getSession##(setMode (Js.string name))

type mark_type = Error | Warning | Message

Expand All @@ -105,10 +105,10 @@ let string_of_make_type = function
| Warning -> "warning"
| Message -> "message"

let require s = (Js.Unsafe.variable "ace")##require(Js.string s)
let require s = (Js.Unsafe.variable "ace")##(require (Js.string s))

type range = Ace_types.range Js.t
let range_cstr = (require "ace/range")##_Range
let range_cstr = (require "ace/range")##._Range
let range sr sc er ec : range =
Js.Unsafe.new_obj range_cstr
[| Js.Unsafe.inject sr ; Js.Unsafe.inject sc ;
Expand All @@ -120,7 +120,7 @@ type loc = {
}

let set_mark editor ?loc ?(type_ = Message) msg =
let session = editor.editor##getSession() in
let session = (editor.editor)##getSession in
let type_ = string_of_make_type type_ in
let sr, sc, range =
match loc with
Expand All @@ -130,39 +130,39 @@ let set_mark editor ?loc ?(type_ = Message) msg =
let er = er - 1 in
sr, sc, Some (range sr sc er ec) in
let annot : annotation Js.t = Js.Unsafe.obj [||] in
annot##row <- sr;
annot##column <- sc;
annot##text <- Js.string msg;
annot##type_ <- Js.string type_;
annot##.row := sr;
annot##.column := sc;
annot##.text := Js.string msg;
annot##.type_ := Js.string type_;
let annotations =
Array.concat [[| annot |]; Js.to_array (session##getAnnotations ())] in
session##setAnnotations(Js.array @@ annotations);
Array.concat [[| annot |]; Js.to_array (session##getAnnotations)] in
session##(setAnnotations (Js.array @@ annotations));
match range with
| None -> ()
| Some range ->
editor.marks <-
session##addMarker (range, Js.string type_, Js.string "text", Js._false) ::
session##(addMarker range (Js.string type_) (Js.string "text") (Js._false)) ::
editor.marks

let set_background_color editor color =
editor.editor_div##style##backgroundColor <- Js.string color
editor.editor_div##.style##.backgroundColor := Js.string color

let add_class { editor_div } name =
editor_div##classList##add(Js.string name)
editor_div##.classList##(add (Js.string name))
let remove_class { editor_div } name =
editor_div##classList##remove(Js.string name)
editor_div##.classList##(remove (Js.string name))

let clear_marks editor =
let session = editor.editor##getSession() in
List.iter (fun i -> session##removeMarker (i)) editor.marks;
session##clearAnnotations();
let session = (editor.editor)##getSession in
List.iter (fun i -> session##(removeMarker i)) editor.marks;
session##clearAnnotations;
editor.marks <- []

let record_event_handler editor event handler =
editor.editor##on(Js.string event, handler)
editor.editor##(on (Js.string event) handler)

let focus { editor } = editor##focus ()
let resize { editor } force = editor##resize (Js.bool force)
let focus { editor } = editor##focus
let resize { editor } force = editor##(resize (Js.bool force))

let get_keybinding_menu e =
if e.keybinding_menu then
Expand All @@ -179,37 +179,37 @@ let get_keybinding_menu e =
let show_keybindings e =
match get_keybinding_menu e with
| None ->
Firebug.console##log
(Js.string "You should load: 'ext-keybinding_menu.js'")
Firebug.console##(log
(Js.string "You should load: 'ext-keybinding_menu.js'"))
| Some o ->
o##showKeyboardShortcuts()
o##showKeyboardShortcuts

let add_keybinding { editor }
?ro ?scrollIntoView ?multiSelectAction
name key exec =
let command : _ command Js.t = Js.Unsafe.obj [||] in
let binding : binding Js.t = Js.Unsafe.obj [||] in
command##name <- Js.string name;
command##exec <- Js.wrap_callback (fun ed _args -> exec (fst ed##customData));
iter_option (fun ro -> command##readOnly <- Js.bool ro) ro;
command##.name := Js.string name;
command##.exec := Js.wrap_callback (fun ed _args -> exec (fst ed##.customData));
iter_option (fun ro -> command##.readOnly := Js.bool ro) ro;
iter_option
(fun s -> command##scrollIntoView <- Js.string s)
(fun s -> command##.scrollIntoView := Js.string s)
scrollIntoView;
iter_option
(fun s -> command##multiSelectAction <- Js.string s)
(fun s -> command##.multiSelectAction := Js.string s)
multiSelectAction;
binding##win <- Js.string key;
binding##mac <- Js.string key;
command##bindKey <- binding;
editor##commands##addCommand (command)
binding##.win := Js.string key;
binding##.mac := Js.string key;
command##.bindKey := binding;
editor##.commands##(addCommand command)

(** Mode *)

type token = Ace_types.token Js.t
let token ~type_ value =
let obj : Ace_types.token Js.t = Js.Unsafe.obj [||] in
obj##value <- Js.string value;
obj##_type <- Js.string type_;
obj##.value := Js.string value;
obj##._type := Js.string type_;
obj

type doc = Ace_types.document Js.t
Expand All @@ -224,62 +224,62 @@ type 'state helpers = {

let create_js_line_tokens (st, tokens) =
let obj : _ Ace_types.line_tokens Js.t = Js.Unsafe.obj [||] in
obj##state <- st;
obj##tokens <- Js.array (Array.of_list tokens);
obj##.state := st;
obj##.tokens := Js.array (Array.of_list tokens);
obj

let define_mode name helpers =
let js_helpers : _ ace_mode_helpers Js.t = Js.Unsafe.obj [||] in
js_helpers##initialState <- Js.wrap_callback helpers.initial_state;
js_helpers##getNextLineIndent <-
js_helpers##.initialState := Js.wrap_callback helpers.initial_state;
js_helpers##.getNextLineIndent :=
(Js.wrap_callback @@ fun st line tab ->
Js.string @@
helpers.get_next_line_indent
st ~line:(Js.to_string line) ~tab:(Js.to_string tab));
js_helpers##getLineTokens <-
js_helpers##.getLineTokens :=
(Js.wrap_callback @@ fun line st row doc ->
create_js_line_tokens @@
helpers.get_line_tokens (Js.to_string line) st row doc);
begin match helpers.check_outdent with
| None -> ()
| Some check_outdent ->
js_helpers##checkOutdent <-
js_helpers##.checkOutdent :=
(Js.wrap_callback @@ fun st line input ->
Js.bool @@
check_outdent st (Js.to_string line) (Js.to_string input))
end;
begin match helpers.auto_outdent with
| None -> ()
| Some auto_outdent ->
js_helpers##autoOutdent <- Js.wrap_callback auto_outdent
js_helpers##.autoOutdent := Js.wrap_callback auto_outdent
end;
Js.Unsafe.fun_call
(Js.Unsafe.variable "define_ocaml_mode")
[| Js.Unsafe.inject (Js.string ("ace/mode/" ^ name)) ;
Js.Unsafe.inject js_helpers |]

let set_font_size {editor} sz =
editor##setFontSize (sz)
editor##(setFontSize sz)
let set_tab_size {editor} sz =
editor##getSession()##setTabSize (sz)
editor##getSession##(setTabSize sz)

let get_state { editor } row =
editor##getSession()##getState(row)
editor##getSession##(getState row)

let get_last { editor } =
let doc = editor##getSession()##getDocument () in
let lines = doc##getLength() in
let last = doc##getLine(lines - 1) in
create_position (lines - 1) last##length
let doc = (editor##getSession)##getDocument in
let lines = doc##getLength in
let last = doc##(getLine (lines - 1)) in
create_position (lines - 1) last##.length

let document { editor } =
editor##getSession()##getDocument()
(editor##getSession)##getDocument

let replace doc range text =
doc##replace (range, Js.string text)
doc##(replace range (Js.string text))

let delete doc range =
doc##replace (range, Js.string "")
doc##(replace range (Js.string ""))

let remove { editor } dir =
editor##remove(Js.string "left")
editor##(remove (Js.string "left"))
4 changes: 2 additions & 2 deletions src/ace-lib/build.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ begin library "ace"
link += [ "-linkall" ]
files = [
"ace_types.mli"
"ace.ml" ( pp = camlp4_optcomp_js )
"ocaml_mode.ml" ( pp = camlp4_optcomp_js )
"ace.ml" ( comp = ppx_js )
"ocaml_mode.ml"
]
requires = [
"jsutils"
Expand Down
2 changes: 1 addition & 1 deletion src/ace-lib/ocaml_mode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ type config = {

let config =
ref {
indent = IndentConfig.(update_from_string default "match_clause=4");
indent = IndentConfig.({default with i_match_clause = 4});
forced = true;
}

Expand Down

0 comments on commit 73eace9

Please sign in to comment.