Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor IRJ parser for Menhir new error handling #240

Merged
merged 31 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b933509
Split parser errors in 3 types.
mdurero Jun 13, 2024
a689fd9
Add the new error types to the interpreter
mdurero Jun 13, 2024
5ec0fc5
New IRJ parse_file entry point using MenhirLib and new exceptions
mdurero Jun 13, 2024
0154798
Add specialized incremental parser for error handling
mdurero Jun 13, 2024
44d202b
Remove error token in IRJ parser, add generated .message file
mdurero Jun 13, 2024
f77cdd4
Squash forgot a line in last commit
mdurero Jun 13, 2024
ec1be6e
Squash format for partially commited file
mdurero Jun 13, 2024
390f907
Squash no parse success possible with the 2nd call
mdurero Jun 13, 2024
5f961f0
Squash add parserMessages.ml generation
mdurero Jun 13, 2024
47b5cb7
Remove nonterminals now useless
mdurero Jun 13, 2024
76d3883
Remove now useless macos build
denismerigoux Jun 17, 2024
4c4428b
Use Cmdliner for irj_checker
denismerigoux Jun 17, 2024
71e2731
Simplify parser error handling and passes
denismerigoux Jun 17, 2024
29d3791
Two error formats
denismerigoux Jun 17, 2024
06497b9
Correct formatting to please the CI
denismerigoux Jun 17, 2024
0f6d9d1
Fix uncaught error and formatting bug
denismerigoux Jun 17, 2024
87737e5
Add WIP module to generate API PAS-CALC JSON format
mdurero Jun 17, 2024
a9c401e
Fails nicely on non-files
denismerigoux Jun 17, 2024
0b9c3f5
Restores pas_calc module and connects it to executable
denismerigoux Jun 17, 2024
231dea9
Fix pas-calc generator module connection
mdurero Jun 18, 2024
51ba6ee
Allow to chose Pas-calc primitive or corrective format
mdurero Jun 19, 2024
b23a665
WIP to more parameters
mdurero Jun 19, 2024
947e60b
Allow pas-calc backend to generate monoline json
mdurero Jun 20, 2024
05cde11
Add an output for a valid file
mdurero Jun 20, 2024
3a2b3fd
Short option format and doc
mdurero Jun 20, 2024
50e5699
Add option for corrective/primitive only modes
mdurero Jun 20, 2024
980aa75
Typo in an error
mdurero Jun 20, 2024
ccfead1
WIP some error messages and test files
mdurero Jun 20, 2024
a5a6560
Remove a useless parser case
mdurero Jun 26, 2024
959c1b3
Better placeholder message and fix parser
denismerigoux Jun 26, 2024
1732c7b
Big name check
denismerigoux Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix uncaught error and formatting bug
denismerigoux committed Jun 17, 2024
commit 0f6d9d13aa5815a14b2775124380ab3bbc40936e
7 changes: 6 additions & 1 deletion src/mlang/test_framework/irj_file.ml
Original file line number Diff line number Diff line change
@@ -86,7 +86,12 @@ let fail text buffer (checkpoint : _ Irj_parser.MenhirInterpreter.checkpoint) =
(mk_position (MenhirLib.ErrorReports.last buffer))

let parse_file (test_name : string) : Irj_ast.irj_file =
let text, filebuf = MenhirLib.LexerUtil.read test_name in
let text, filebuf =
try MenhirLib.LexerUtil.read test_name
with Sys_error msg ->
Errors.raise_error
(Format.asprintf "Unable to open file %s (%s)" test_name msg)
in
let supplier =
Irj_parser.MenhirInterpreter.lexer_lexbuf_to_supplier Irj_lexer.token
filebuf
22 changes: 12 additions & 10 deletions src/mlang/utils/errors.ml
Original file line number Diff line number Diff line change
@@ -33,16 +33,18 @@ let format_structured_error fmt

let format_structured_error_gnu_format fmt
((msg, pos) : string * (string option * Pos.t) list) =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.pp_print_newline fmt ())
(fun fmt (pos_msg, pos) ->
Format.fprintf fmt "%a: %s %a\n" Pos.format_position_gnu pos msg
(fun fmt pos_msg ->
match pos_msg with
| None -> ()
| Some pos_msg -> Format.fprintf fmt "[%s]" pos_msg)
pos_msg)
fmt pos
if pos = [] then Format.fprintf fmt "%s\n" msg
else
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.pp_print_newline fmt ())
(fun fmt (pos_msg, pos) ->
Format.fprintf fmt "%a: %s %a\n" Pos.format_position_gnu pos msg
(fun fmt pos_msg ->
match pos_msg with
| None -> ()
| Some pos_msg -> Format.fprintf fmt "[%s]" pos_msg)
pos_msg)
fmt pos

let raise_spanned_error (msg : string) ?(span_msg : string option)
(span : Pos.t) : 'a =
23 changes: 14 additions & 9 deletions src/mlang/utils/pos.ml
Original file line number Diff line number Diff line change
@@ -177,26 +177,31 @@ let retrieve_loc_text (pos : t) : string =
let print_matched_line (line : string) (line_no : int) : string =
let line_indent = indent_number line in
let error_indicator_style = [ ANSITerminal.red; ANSITerminal.Bold ] in
let line_start_col =
if line_no = sline then get_start_column pos else 1
in
let line_end_col =
if line_no = eline then get_end_column pos else String.length line + 1
in
let line_length = String.length line + 1 in
line
^
if line_no >= sline && line_no <= eline then
"\n"
^
if line_no = sline && line_no = eline then
Cli.format_with_style error_indicator_style "%*s"
(get_end_column pos - 1)
(String.make (get_end_column pos - get_start_column pos) '^')
Cli.format_with_style error_indicator_style "%*s" (line_end_col - 1)
(String.make (line_end_col - line_start_col) '^')
else if line_no = sline && line_no <> eline then
Cli.format_with_style error_indicator_style "%*s"
(String.length line - 1)
(String.make (String.length line - get_start_column pos) '^')
Cli.format_with_style error_indicator_style "%*s" (line_length - 1)
(String.make (line_length - line_start_col) '^')
else if line_no <> sline && line_no <> eline then
Cli.format_with_style error_indicator_style "%*s%s" line_indent ""
(String.make (String.length line - line_indent) '^')
(String.make (line_length - line_indent) '^')
else if line_no <> sline && line_no = eline then
Cli.format_with_style error_indicator_style "%*s%*s" line_indent ""
(get_end_column pos - 1 - line_indent)
(String.make (get_end_column pos - line_indent) '^')
(line_end_col - 1 - line_indent)
(String.make (line_end_col - line_indent) '^')
else assert false (* should not happen *)
else ""
in