Skip to content

Commit

Permalink
Restore compatibility with OCaml 4.04.x (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
xclerc authored Apr 24, 2018
1 parent 43273dc commit 70c4a6e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ast/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ let keyword_table =
"asr", INFIXOP4("asr")
]

module Buffer = struct (* Imported for compatibility with 4.04.x *)
[@@@warning "-32"]
let add_utf_8_uchar b u = match Uchar.to_int u with
| u when u < 0 -> assert false
| u when u <= 0x007F ->
Buffer.add_char b (Char.unsafe_chr u)
| u when u <= 0x07FF ->
Buffer.add_char b (Char.unsafe_chr (0xC0 lor (u lsr 6)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor (u land 0x3F)));
| u when u <= 0xFFFF ->
Buffer.add_char b (Char.unsafe_chr (0xE0 lor (u lsr 12)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor ((u lsr 6) land 0x3F)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor (u land 0x3F)));
| u when u <= 0x10FFFF ->
Buffer.add_char b (Char.unsafe_chr (0xF0 lor (u lsr 18)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor ((u lsr 12) land 0x3F)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor ((u lsr 6) land 0x3F)));
Buffer.add_char b (Char.unsafe_chr (0x80 lor (u land 0x3F)));
| _ -> assert false
include Buffer
end

(* To buffer string literals *)

let string_buffer = Buffer.create 256
Expand Down

0 comments on commit 70c4a6e

Please sign in to comment.