-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compat with older OCamls (up to 4.00)
- remove 'match with exception' :( - add a dumb preprocessor for string quotations (quicker and easier than other rewriting solutions)
- Loading branch information
Showing
6 changed files
with
89 additions
and
11 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
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
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,50 @@ | ||
#!/usr/bin/env ocaml | ||
|
||
let () = | ||
try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") | ||
with Not_found -> () | ||
;; | ||
#use "topfind";; | ||
#require "re";; | ||
|
||
(** This is a dumb, limited rewriter for the [{xxx| |xxx}] quotations, that | ||
weren't available in OCaml 4.01. Only one beginning/end token is allowed per | ||
line, no error handling, probably escaping bugs... But this is enough | ||
for just allowing to compile on earlier OCaml versions. *) | ||
|
||
let start_quot_re = Re.(compile (seq [char '{'; group (rep alnum); char '|'])) | ||
let end_quot_re name = Re.(compile (seq [char '|'; str name; char '}'])) | ||
|
||
let rec next ic = | ||
let line = input_line ic in | ||
let quot = try Some (Re.exec start_quot_re line) with Not_found -> None in | ||
match quot with | ||
| Some subs -> | ||
let match_start, match_end = Re.get_ofs subs 0 in | ||
print_string (String.sub line 0 match_start); | ||
let end_re = end_quot_re (Re.get subs 1) in | ||
let rec get_s acc = | ||
let line = input_line ic in | ||
try | ||
let subs = Re.exec end_re line in | ||
let match_start, match_end = Re.get_ofs subs 0 in | ||
let ss = List.rev (String.sub line 0 match_start :: acc) in | ||
print_char '\"'; | ||
List.iter (fun s -> | ||
print_string (String.escaped s); | ||
print_string "\\n\\\n") | ||
ss; | ||
print_char '\"'; | ||
print_string | ||
(String.sub line match_end (String.length line - match_end)); | ||
print_char '\n' | ||
with Not_found -> get_s (line::acc) | ||
in | ||
get_s [String.sub line match_end (String.length line - match_end)]; | ||
next ic | ||
| None -> | ||
print_string line; print_char '\n'; next ic | ||
|
||
let () = | ||
let ic = open_in (Sys.argv.(1)) in | ||
try next ic with End_of_file -> close_in ic |