|
1 |
| -let token state lexbuf = |
2 |
| - let open Parser in |
3 |
| - match state with |
4 |
| - | `Structure -> ( |
5 |
| - match Lexer.structure_token lexbuf with |
6 |
| - | QUOTE -> (`Formula, QUOTE (* or supress it?*)) |
7 |
| - | token -> (`Structure, token)) |
8 |
| - | `Formula -> ( |
9 |
| - match Lexer.formula_token lexbuf with |
10 |
| - | QUOTE -> (`Structure, QUOTE) |
11 |
| - | token -> (`Formula, token)) |
12 |
| - |
13 | 1 | (* FIXME: error messages?? *)
|
14 | 2 | let parse entrypoint lexbuf =
|
15 | 3 | let module MI = Parser.MenhirInterpreter in
|
16 |
| - let rec loop lex_state cp = |
| 4 | + let rec loop cp = |
17 | 5 | match cp with
|
18 | 6 | | MI.Accepted a -> Ok a
|
19 | 7 | | MI.InputNeeded _env ->
|
20 |
| - let lex_state, tok = token lex_state lexbuf in |
21 |
| - let spos = Lexing.lexeme_start_p lexbuf in |
22 |
| - let epos = Lexing.lexeme_end_p lexbuf in |
23 |
| - loop lex_state (MI.offer cp (tok, spos, epos)) |
24 |
| - | MI.Shifting _ | MI.AboutToReduce _ -> loop lex_state (MI.resume cp) |
| 8 | + (match Lexer.structure_token lexbuf with |
| 9 | + | Ok tok -> |
| 10 | + let spos = Lexing.lexeme_start_p lexbuf in |
| 11 | + let epos = Lexing.lexeme_end_p lexbuf in |
| 12 | + loop (MI.offer cp (tok, spos, epos)) |
| 13 | + | Error (`Parse e) -> |
| 14 | + let pos = Parser_util.Location.of_lexbuf lexbuf in |
| 15 | + Error (fun fmt -> |
| 16 | + Format.fprintf fmt |
| 17 | + "Error in formula at %a: %s" |
| 18 | + Parser_util.Location.pp_without_filename pos |
| 19 | + (Parser_util.Driver.string_of_error e))) |
| 20 | + | MI.Shifting _ | MI.AboutToReduce _ -> loop (MI.resume cp) |
25 | 21 | | MI.HandlingError _ ->
|
26 | 22 | let pos = Parser_util.Location.of_lexbuf lexbuf in
|
27 | 23 | let lexeme = Lexing.lexeme lexbuf in
|
28 | 24 | Error
|
29 | 25 | (fun fmt ->
|
30 | 26 | Format.fprintf fmt "Error at %a on input '%s'"
|
31 |
| - Parser_util.Location.pp pos lexeme) |
| 27 | + Parser_util.Location.pp_without_filename pos lexeme) |
32 | 28 | | MI.Rejected -> assert false
|
33 | 29 | in
|
34 | 30 | let init_pos = lexbuf.Lexing.lex_curr_p in
|
35 |
| - loop `Structure (entrypoint init_pos) |
| 31 | + loop (entrypoint init_pos) |
36 | 32 |
|
37 | 33 | let parse = parse Parser.Incremental.structure
|
0 commit comments