Created
January 30, 2018 10:29
-
-
Save alainfrisch/49f9a75db9133f70d8d6f628910c4805 to your computer and use it in GitHub Desktop.
Optimizing "ocamllex -ml"
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
let rec __ocaml_lex_refill_buf lexbuf _buf _len _curr _last = | |
if lexbuf.Lexing.lex_eof_reached then | |
256, _buf, _len, _curr, _last | |
else begin | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
lexbuf.Lexing.refill_buff lexbuf; | |
let _curr = lexbuf.Lexing.lex_curr_pos in | |
let _last = lexbuf.Lexing.lex_last_pos in | |
let _len = lexbuf.Lexing.lex_buffer_len in | |
let _buf = lexbuf.Lexing.lex_buffer in | |
if _curr < _len then | |
Char.code (Bytes.unsafe_get _buf _curr), _buf, _len, (_curr + 1), _last | |
else | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last | |
end | |
let rec __ocaml_lex_state2 lexbuf _last_action _buf _len _curr _last = | |
(* *) | |
let _last = _curr in | |
let _last_action = 1 in | |
let next_char, _buf, _len, _curr, _last = | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last | |
else | |
Char.code (Bytes.unsafe_get _buf _curr), | |
_buf, _len, (_curr + 1), _last | |
in | |
begin match next_char with | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf 1 (* = last_action *) _buf _len _curr _last | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
1 (* = last_action *) | |
end | |
let rec token lexbuf = | |
let __ocaml_lex_result = | |
let _curr = lexbuf.Lexing.lex_curr_pos in | |
let _last = _curr in | |
let _len = lexbuf.Lexing.lex_buffer_len in | |
let _buf = lexbuf.Lexing.lex_buffer in | |
let _last_action = -1 in | |
lexbuf.Lexing.lex_start_pos <- _curr; | |
let next_char, _buf, _len, _curr, _last = | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last | |
else | |
Char.code (Bytes.unsafe_get _buf _curr), | |
_buf, _len, (_curr + 1), _last | |
in | |
begin match next_char with | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf _last_action _buf _len _curr _last | |
(* |'[' *) | |
| 91 -> | |
(* *) | |
let _last = _curr in | |
let _last_action = 2 in | |
let next_char, _buf, _len, _curr, _last = | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last | |
else | |
Char.code (Bytes.unsafe_get _buf _curr), | |
_buf, _len, (_curr + 1), _last | |
in | |
begin match next_char with | |
(* |'|' *) | |
| 124 -> | |
(* *) | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
3 | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
2 (* = last_action *) | |
end | |
(* |eof *) | |
| 256 -> | |
(* *) | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
0 | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
_last_action | |
end | |
in | |
begin | |
let _curr_p = lexbuf.Lexing.lex_curr_p in | |
if _curr_p != Lexing.dummy_pos then begin | |
lexbuf.Lexing.lex_start_p <- _curr_p; | |
lexbuf.Lexing.lex_curr_p <- | |
{_curr_p with Lexing.pos_cnum = | |
lexbuf.Lexing.lex_abs_pos+lexbuf.Lexing.lex_curr_pos} | |
end | |
end; | |
match __ocaml_lex_result with | |
| 0 -> | |
# 2 "demo.mll" | |
( `EOF ) | |
# 113 "after.ml" | |
| 1 -> | |
# 3 "demo.mll" | |
( `INT (Lexing.lexeme lexbuf) ) | |
# 118 "after.ml" | |
| 2 -> | |
# 4 "demo.mll" | |
( `LBRACKET) | |
# 123 "after.ml" | |
| 3 -> | |
# 5 "demo.mll" | |
( `LBRACKETBAR ) | |
# 128 "after.ml" | |
| _ -> raise (Failure "lexing: empty token") | |
;; | |
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
# 1 "demo_handler.mll" | |
let refill_handler k lexbuf = k lexbuf | |
# 6 "after_handler.ml" | |
let __ocaml_lex_refill : (Lexing.lexbuf -> 'a) -> (Lexing.lexbuf -> 'a) = | |
# 5 "demo_handler.mll" | |
(refill_handler) | |
# 10 "after_handler.ml" | |
let rec __ocaml_lex_refill_buf lexbuf _buf _len _curr _last _last_action state k = | |
if lexbuf.Lexing.lex_eof_reached then | |
state lexbuf _last_action _buf _len _curr _last k 256 | |
else begin | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
__ocaml_lex_refill | |
(fun lexbuf -> | |
let _curr = lexbuf.Lexing.lex_curr_pos in | |
let _last = lexbuf.Lexing.lex_last_pos in | |
let _len = lexbuf.Lexing.lex_buffer_len in | |
let _buf = lexbuf.Lexing.lex_buffer in | |
if _curr < _len then | |
state lexbuf _last_action _buf _len (_curr + 1) _last k | |
(Char.code (Bytes.unsafe_get _buf _curr)) | |
else | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last _last_action | |
state k | |
) | |
lexbuf | |
end | |
let rec __ocaml_lex_state2 lexbuf _last_action _buf _len _curr _last k = | |
(* *) | |
let _last = _curr in | |
let _last_action = 1 in | |
let state lexbuf _last_action _buf _len _curr _last k = function | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf 1 (* = last_action *) _buf _len _curr _last k | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
k lexbuf 1 (* = last_action *) | |
in | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last _last_action state k | |
else | |
state lexbuf _last_action _buf _len (_curr + 1) _last k | |
(Char.code (Bytes.unsafe_get _buf _curr)) | |
let rec token lexbuf = | |
let k lexbuf __ocaml_lex_result = | |
begin | |
let _curr_p = lexbuf.Lexing.lex_curr_p in | |
if _curr_p != Lexing.dummy_pos then begin | |
lexbuf.Lexing.lex_start_p <- _curr_p; | |
lexbuf.Lexing.lex_curr_p <- | |
{_curr_p with Lexing.pos_cnum = | |
lexbuf.Lexing.lex_abs_pos+lexbuf.Lexing.lex_curr_pos} | |
end | |
end; | |
match __ocaml_lex_result with | |
| 0 -> | |
# 8 "demo_handler.mll" | |
( `EOF ) | |
# 70 "after_handler.ml" | |
| 1 -> | |
# 9 "demo_handler.mll" | |
( `INT (Lexing.lexeme lexbuf) ) | |
# 75 "after_handler.ml" | |
| 2 -> | |
# 10 "demo_handler.mll" | |
( `LBRACKET) | |
# 80 "after_handler.ml" | |
| 3 -> | |
# 11 "demo_handler.mll" | |
( `LBRACKETBAR ) | |
# 85 "after_handler.ml" | |
| _ -> raise (Failure "lexing: empty token") | |
in | |
let _curr = lexbuf.Lexing.lex_curr_pos in | |
let _last = _curr in | |
let _len = lexbuf.Lexing.lex_buffer_len in | |
let _buf = lexbuf.Lexing.lex_buffer in | |
let _last_action = -1 in | |
lexbuf.Lexing.lex_start_pos <- _curr; | |
let state lexbuf _last_action _buf _len _curr _last k = function | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf _last_action _buf _len _curr _last k | |
(* |'[' *) | |
| 91 -> | |
(* *) | |
let _last = _curr in | |
let _last_action = 2 in | |
let state lexbuf _last_action _buf _len _curr _last k = function | |
(* |'|' *) | |
| 124 -> | |
(* *) | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
k lexbuf 3 | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
k lexbuf 2 (* = last_action *) | |
in | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last _last_action state k | |
else | |
state lexbuf _last_action _buf _len (_curr + 1) _last k | |
(Char.code (Bytes.unsafe_get _buf _curr)) | |
(* |eof *) | |
| 256 -> | |
(* *) | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
k lexbuf 0 | |
| _ -> | |
let _curr = _last in | |
lexbuf.Lexing.lex_curr_pos <- _curr; | |
lexbuf.Lexing.lex_last_pos <- _last; | |
k lexbuf _last_action | |
in | |
if _curr >= _len then | |
__ocaml_lex_refill_buf lexbuf _buf _len _curr _last _last_action state k | |
else | |
state lexbuf _last_action _buf _len (_curr + 1) _last k | |
(Char.code (Bytes.unsafe_get _buf _curr)) | |
;; | |
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
let __ocaml_lex_init_lexbuf lexbuf mem_size = | |
let pos = lexbuf.Lexing.lex_curr_pos in | |
lexbuf.Lexing.lex_mem <- Array.make mem_size (-1) ; | |
lexbuf.Lexing.lex_start_pos <- pos ; | |
lexbuf.Lexing.lex_last_pos <- pos ; | |
lexbuf.Lexing.lex_last_action <- -1 | |
let rec __ocaml_lex_next_char lexbuf = | |
if lexbuf.Lexing.lex_curr_pos >= lexbuf.Lexing.lex_buffer_len then begin | |
if lexbuf.Lexing.lex_eof_reached then | |
256 | |
else begin | |
lexbuf.Lexing.refill_buff lexbuf ; | |
__ocaml_lex_next_char lexbuf | |
end | |
end else begin | |
let i = lexbuf.Lexing.lex_curr_pos in | |
let c = Bytes.get lexbuf.Lexing.lex_buffer i in | |
lexbuf.Lexing.lex_curr_pos <- i+1 ; | |
Char.code c | |
end | |
let rec __ocaml_lex_state0 lexbuf = match __ocaml_lex_next_char lexbuf with | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf | |
(* |'[' *) | |
|91 -> | |
__ocaml_lex_state1 lexbuf | |
(* |eof *) | |
|256 -> | |
__ocaml_lex_state3 lexbuf | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state1 lexbuf = (* *) | |
lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_curr_pos ; | |
lexbuf.Lexing.lex_last_action <- 2 ; | |
match __ocaml_lex_next_char lexbuf with | |
(* |'|' *) | |
|124 -> | |
__ocaml_lex_state4 lexbuf | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state2 lexbuf = (* *) | |
lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_curr_pos ; | |
lexbuf.Lexing.lex_last_action <- 1 ; | |
match __ocaml_lex_next_char lexbuf with | |
(* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state3 lexbuf = (* *) | |
0 | |
and __ocaml_lex_state4 lexbuf = (* *) | |
3 | |
let rec token lexbuf = | |
__ocaml_lex_init_lexbuf lexbuf 0; | |
let __ocaml_lex_result = __ocaml_lex_state0 lexbuf in | |
lexbuf.Lexing.lex_start_p <- lexbuf.Lexing.lex_curr_p; | |
lexbuf.Lexing.lex_curr_p <- {lexbuf.Lexing.lex_curr_p with | |
Lexing.pos_cnum = lexbuf.Lexing.lex_abs_pos+lexbuf.Lexing.lex_curr_pos}; | |
match __ocaml_lex_result with | |
| 0 -> | |
# 2 "demo.mll" | |
( `EOF ) | |
# 76 "before.ml" | |
| 1 -> | |
# 3 "demo.mll" | |
( `INT (Lexing.lexeme lexbuf) ) | |
# 81 "before.ml" | |
| 2 -> | |
# 4 "demo.mll" | |
( `LBRACKET) | |
# 86 "before.ml" | |
| 3 -> | |
# 5 "demo.mll" | |
( `LBRACKETBAR ) | |
# 91 "before.ml" | |
| _ -> raise (Failure "lexing: empty token") | |
;; | |
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
# 1 "demo_handler.mll" | |
let refill_handler k lexbuf = k lexbuf | |
# 6 "before_handler.ml" | |
let __ocaml_lex_refill : (Lexing.lexbuf -> 'a) -> (Lexing.lexbuf -> 'a) = | |
# 5 "demo_handler.mll" | |
(refill_handler) | |
# 10 "before_handler.ml" | |
let __ocaml_lex_init_lexbuf lexbuf mem_size = | |
let pos = lexbuf.Lexing.lex_curr_pos in | |
lexbuf.Lexing.lex_mem <- Array.make mem_size (-1) ; | |
lexbuf.Lexing.lex_start_pos <- pos ; | |
lexbuf.Lexing.lex_last_pos <- pos ; | |
lexbuf.Lexing.lex_last_action <- -1 | |
let rec __ocaml_lex_next_char lexbuf state k = | |
if lexbuf.Lexing.lex_curr_pos >= lexbuf.Lexing.lex_buffer_len then begin | |
if lexbuf.Lexing.lex_eof_reached then | |
state lexbuf k 256 | |
else begin | |
__ocaml_lex_refill (fun lexbuf -> | |
lexbuf.Lexing.refill_buff lexbuf ; | |
__ocaml_lex_next_char lexbuf state k) | |
lexbuf | |
end | |
end else begin | |
let i = lexbuf.Lexing.lex_curr_pos in | |
let c = Bytes.get lexbuf.Lexing.lex_buffer i in | |
lexbuf.Lexing.lex_curr_pos <- i+1 ; | |
state lexbuf k (Char.code c) | |
end | |
let rec __ocaml_lex_state0 lexbuf k = __ocaml_lex_next_char lexbuf __ocaml_lex_state0_next k | |
and __ocaml_lex_state0_next lexbuf k = function (* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf k | |
(* |'[' *) | |
|91 -> | |
__ocaml_lex_state1 lexbuf k | |
(* |eof *) | |
|256 -> | |
__ocaml_lex_state3 lexbuf k | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
k lexbuf lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state1 lexbuf k = (* *) | |
lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_curr_pos ; | |
lexbuf.Lexing.lex_last_action <- 2 ; | |
__ocaml_lex_next_char lexbuf __ocaml_lex_state1_next k | |
and __ocaml_lex_state1_next lexbuf k = function (* |'|' *) | |
|124 -> | |
__ocaml_lex_state4 lexbuf k | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
k lexbuf lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state2 lexbuf k = (* *) | |
lexbuf.Lexing.lex_last_pos <- lexbuf.Lexing.lex_curr_pos ; | |
lexbuf.Lexing.lex_last_action <- 1 ; | |
__ocaml_lex_next_char lexbuf __ocaml_lex_state2_next k | |
and __ocaml_lex_state2_next lexbuf k = function (* |'0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9' *) | |
|48|49|50|51|52|53|54|55|56|57 -> | |
__ocaml_lex_state2 lexbuf k | |
| _ -> | |
lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_last_pos ; | |
k lexbuf lexbuf.Lexing.lex_last_action | |
and __ocaml_lex_state3 lexbuf k = (* *) | |
k lexbuf 0 | |
and __ocaml_lex_state4 lexbuf k = (* *) | |
k lexbuf 3 | |
let rec token lexbuf = | |
__ocaml_lex_init_lexbuf lexbuf 0; | |
__ocaml_lex_state0 lexbuf (fun lexbuf __ocaml_lex_result -> | |
lexbuf.Lexing.lex_start_p <- lexbuf.Lexing.lex_curr_p; | |
lexbuf.Lexing.lex_curr_p <- {lexbuf.Lexing.lex_curr_p with | |
Lexing.pos_cnum = lexbuf.Lexing.lex_abs_pos+lexbuf.Lexing.lex_curr_pos}; | |
match __ocaml_lex_result with | |
| 0 -> | |
# 8 "demo_handler.mll" | |
( `EOF ) | |
# 87 "before_handler.ml" | |
| 1 -> | |
# 9 "demo_handler.mll" | |
( `INT (Lexing.lexeme lexbuf) ) | |
# 92 "before_handler.ml" | |
| 2 -> | |
# 10 "demo_handler.mll" | |
( `LBRACKET) | |
# 97 "before_handler.ml" | |
| 3 -> | |
# 11 "demo_handler.mll" | |
( `LBRACKETBAR ) | |
# 102 "before_handler.ml" | |
| _ -> raise (Failure "lexing: empty token") | |
) | |
;; | |
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
rule token = parse | |
| eof { `EOF } | |
| ['0'-'9']+ { `INT (Lexing.lexeme lexbuf) } | |
| "[" { `LBRACKET} | |
| "[|" { `LBRACKETBAR } |
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
{ | |
let refill_handler k lexbuf = k lexbuf | |
} | |
refill {refill_handler} | |
rule token = parse | |
| eof { `EOF } | |
| ['0'-'9']+ { `INT (Lexing.lexeme lexbuf) } | |
| "[" { `LBRACKET} | |
| "[|" { `LBRACKETBAR } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment