Skip to content

Commit a76bb8f

Browse files
committed
Simplify hack
1 parent b1fe0ee commit a76bb8f

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

interpreter/text/parse.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ let wrap_lexbuf lexbuf =
2424
Annot.extend_source (Bytes.sub_string lexbuf.lex_buffer lexbuf.lex_start_pos n);
2525
{lexbuf with refill_buff}
2626

27-
let provider lexbuf () =
28-
let tok = Lexer.token lexbuf in
29-
let start = Lexing.lexeme_start_p lexbuf in
30-
let stop = Lexing.lexeme_end_p lexbuf in
31-
tok, start, stop
32-
3327
let convert_pos lexbuf =
3428
{ Source.left = Lexer.convert_pos lexbuf.Lexing.lex_start_p;
3529
Source.right = Lexer.convert_pos lexbuf.Lexing.lex_curr_p
@@ -43,10 +37,8 @@ let make (type a) (start : _ -> _ -> a) : (module S with type t = a) =
4337
Annot.reset ();
4438
Lexing.set_filename lexbuf name;
4539
let lexbuf = wrap_lexbuf lexbuf in
46-
let prov = provider lexbuf in
4740
let result =
48-
try MenhirLib.Convert.Simplified.traditional2revised start prov
49-
with Parser.Error ->
41+
try start Lexer.token lexbuf with Parser.Error ->
5042
raise (Syntax (convert_pos lexbuf, "unexpected token"))
5143
in
5244
let annots = Annot.get_all () in

interpreter/text/parser.mly

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,21 +1009,17 @@ module_ :
10091009
$3, Textual (m, parse_annots m) @@ $sloc }
10101010

10111011
inline_module : /* Sugar */
1012-
| module_fields EOF
1012+
| module_fields
10131013
{ let m = $1 (empty_context ()) () @@ $sloc in
10141014
(* Hack to handle annotations before first and after last token *)
1015-
(* Note: need EOF token here, since Menhir delivers a location
1016-
* with empty filename for $1 in case module_fields is empty! *)
1017-
let all = all_region (at $loc($2)).left.file in
1015+
let all = all_region (at $sloc).left.file in
10181016
Textual (m, parse_annots Source.(m.it @@ all)) @@ $sloc }
10191017

10201018
inline_module1 : /* Sugar */
1021-
| module_fields1 EOF
1019+
| module_fields1
10221020
{ let m = $1 (empty_context ()) () @@ $sloc in
10231021
(* Hack to handle annotations before first and after last token *)
1024-
(* Note: need EOF token here, since Menhir delivers a location
1025-
* with empty filename for $1 in case module_fields is empty! *)
1026-
let all = all_region (at $loc($2)).left.file in
1022+
let all = all_region (at $sloc).left.file in
10271023
Textual (m, parse_annots Source.(m.it @@ all)) @@ $sloc }
10281024

10291025

@@ -1110,12 +1106,12 @@ result :
11101106

11111107
script :
11121108
| list(cmd) EOF { $1 }
1113-
| inline_module1 { [Module (None, $1) @@ $sloc] } /* Sugar */
1109+
| inline_module1 EOF { [Module (None, $1) @@ $sloc] } /* Sugar */
11141110

11151111
script1 :
11161112
| cmd { [$1] }
11171113

11181114
module1 :
11191115
| module_ EOF { $1 }
1120-
| inline_module { None, $1 } /* Sugar */
1116+
| inline_module EOF { None, $1 } /* Sugar */
11211117
%%

0 commit comments

Comments
 (0)