From 6b00947c58e4f4e8431f3948342a6d8829478e2e Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Wed, 5 Jul 2023 14:19:39 +0200 Subject: [PATCH 01/19] Report work on parser from ocaml-backend branch --- src/mlang/irj_parser/dune | 4 ++ src/mlang/irj_parser/irj_ast.ml | 19 ++++++ src/mlang/irj_parser/irj_file.ml | 25 ++++++++ src/mlang/irj_parser/irj_file.mli | 19 ++++++ src/mlang/irj_parser/irj_lexer.mll | 74 +++++++++++++++++++++ src/mlang/irj_parser/irj_parser.mly | 99 +++++++++++++++++++++++++++++ 6 files changed, 240 insertions(+) create mode 100644 src/mlang/irj_parser/dune create mode 100644 src/mlang/irj_parser/irj_ast.ml create mode 100644 src/mlang/irj_parser/irj_file.ml create mode 100644 src/mlang/irj_parser/irj_file.mli create mode 100644 src/mlang/irj_parser/irj_lexer.mll create mode 100644 src/mlang/irj_parser/irj_parser.mly diff --git a/src/mlang/irj_parser/dune b/src/mlang/irj_parser/dune new file mode 100644 index 000000000..ff3cc36dc --- /dev/null +++ b/src/mlang/irj_parser/dune @@ -0,0 +1,4 @@ +(ocamllex irj_lexer) + +(menhir + (modules irj_parser)) diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/irj_ast.ml new file mode 100644 index 000000000..207e868cd --- /dev/null +++ b/src/mlang/irj_parser/irj_ast.ml @@ -0,0 +1,19 @@ +(*From test_ast.ml*) + +type literal = I of int | F of float + +type var_value = string * literal * Pos.t + +type var_values = var_value list + +type errors = (string * Pos.t) list + +type rappels = + (string * string * var_value * string * string * string * string * string) + list + +type irj_file = { + nom : string; + prim : var_values * errors * var_values; + rapp : (rappels * errors * var_values) option; +} diff --git a/src/mlang/irj_parser/irj_file.ml b/src/mlang/irj_parser/irj_file.ml new file mode 100644 index 000000000..a7a23cb97 --- /dev/null +++ b/src/mlang/irj_parser/irj_file.ml @@ -0,0 +1,25 @@ +(*From test_interpreter.ml*) + +open Irj_ast + +let parse_file (test_name : string) : irj_file = + let input = open_in test_name in + let filebuf = Lexing.from_channel input in + let filebuf = + { + filebuf with + lex_curr_p = { filebuf.lex_curr_p with pos_fname = test_name }; + } + in + let f = + try Irj_parser.irj_file Irj_lexer.token filebuf with + | Errors.StructuredError e -> + close_in input; + raise (Errors.StructuredError e) + | Irj_parser.Error -> + close_in input; + Errors.raise_spanned_error "Test syntax error" + (Parse_utils.mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) + in + close_in input; + f diff --git a/src/mlang/irj_parser/irj_file.mli b/src/mlang/irj_parser/irj_file.mli new file mode 100644 index 000000000..c0dab0c7f --- /dev/null +++ b/src/mlang/irj_parser/irj_file.mli @@ -0,0 +1,19 @@ +(* Copyright Inria, contributors: Raphaël Monat (2019) + Mathieu Durero (2023) + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . *) + +val parse_file : string -> Irj_ast.irj_file +(** [parse_file file] loads the content of a given IRJ [file] in a simple + datastructure. *) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll new file mode 100644 index 000000000..255f59e19 --- /dev/null +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -0,0 +1,74 @@ +(* +Copyright Inria, contributors: + Raphaël Monat (2019) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*) + +{ +open Lexing +open Irj_parser +} + +rule token = parse +| [' ' '\t'] (* also ignore newlines, not only whitespace and tabs *) + { token lexbuf } +| '*' [^ '\n']* '\n' (* ignore comments *) + { new_line lexbuf; token lexbuf } +| '\n' | "\r\n" + { new_line lexbuf; token lexbuf} +| "/" + { SLASH } +| "#NOM" + { NOM } +| "#FIP" + { FIP } +| "#ENTREES-PRIMITIF" + { ENTREESPRIM } +| "#CONTROLES-PRIMITIF" + { CONTROLESPRIM } +| "#RESULTATS-PRIMITIF" + { RESULTATSPRIM } +| "#ENTREES-CORRECTIF" + { ENTREESCORR } +| "#CONTROLES-CORRECTIF" + { CONTROLESCORR } +| "#RESULTATS-CORRECTIF" + { RESULTATSCORR } +| "#ENTREES-RAPPELS" + { ENTREESRAPP } +| "#CONTROLES-RAPPELS" + { CONTROLESRAPP } +| "#RESULTATS-RAPPELS" + { RESULTATSRAPP } +(*| "#DATES" + { DATES } +| "#AVIS_IR" + { AVISIR } +| "#AVIS_CSG" + { AVISCSG }*) +| "##" + { ENDSHARP } +| '-'? ['0' - '9']+ as i + { INTEGER i } +| '-'? ['0' - '9']+ '.' ['0' - '9']* as f + { FLOAT f } +| ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as s + { SYMBOL s } +| ['a'-'z' 'A'-'Z' ' ' '0'-'9' ';' '-']+ as s + { NAME s } +| eof + { EOF } +| _ + { Errors.raise_spanned_error "Test file lexer error" (Parse_utils.mk_position (Lexing.lexeme_start_p lexbuf, Lexing.lexeme_end_p lexbuf)) } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly new file mode 100644 index 000000000..eff8f4cf7 --- /dev/null +++ b/src/mlang/irj_parser/irj_parser.mly @@ -0,0 +1,99 @@ +(* +Copyright Inria, contributors: + Raphaël Monat (2019) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*) + +%{ open Irj_ast +%} + +%token SYMBOL NAME INTEGER FLOAT +/* Possibly use stronger constraints than just string on rappel's fields +some are characters, some are 0/1, etc. */ + +%token SLASH +%token NOM FIP +%token ENTREESPRIM CONTROLESPRIM RESULTATSPRIM +%token ENTREESCORR CONTROLESCORR RESULTATSCORR +%token ENTREESRAPP CONTROLESRAPP RESULTATSRAPP +/* %token DATES AVISIR AVISCSG*/ +%token ENDSHARP + +%token EOF + +%type irj_file + +%start irj_file + +%% + +irj_file: +| NOM nom = name + fip? + prim = primitif + rapp = rappels + ENDSHARP { { nom; prim; rapp } } +| EOF { assert false } + +primitif: + ENTREESPRIM + entrees_primitif = list(variable_and_value) + CONTROLESPRIM + erreurs_attendues_primitif = list(error_code) + RESULTATSPRIM + resultats_attendus_primitif = list(variable_and_value) + { (entrees_primitif, erreurs_attendues_primitif, resultats_attendus_primitif) } + +rappels: +| ENTREESRAPP + entrees_rappels = list(rappel) + CONTROLESRAPP + erreurs_attendues_rappels = list(error_code) + RESULTATSRAPP + resultats_attendus_rappels = list(variable_and_value) + { Some (entrees_rappels, erreurs_attendues_rappels, resultats_attendus_rappels) } +| ENTREESCORR CONTROLESCORR RESULTATSCORR { None } + +name: +| n = NAME { n } +| n = SYMBOL { n } + +fip: + FIP SLASH option(SYMBOL) { } + +variable_and_value: +| var = SYMBOL SLASH value = INTEGER { (var, I (int_of_string value), Parse_utils.mk_position $sloc) } +| var = SYMBOL SLASH value = FLOAT { (var, F (float_of_string value), Parse_utils.mk_position $sloc) } + +error_code: + error = SYMBOL { (error, Parse_utils.mk_position $sloc) } + +rappel: + event_nb = INTEGER SLASH + rappel_nb = INTEGER SLASH + variable_change = variable_and_value SLASH + direction = SYMBOL SLASH + penalty_code = INTEGER SLASH + base_tolerance_legale = INTEGER SLASH + month_year = INTEGER SLASH + decl_2042_rect = INTEGER + { (event_nb, + rappel_nb, + variable_change, + direction, + penalty_code, + base_tolerance_legale, + month_year, + decl_2042_rect) } From 68ea878d812ca6ead844f3ea67e9896fc8368840 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Thu, 6 Jul 2023 09:56:00 +0200 Subject: [PATCH 02/19] Reinstate old empty fields, if by chance some files from 2019 must be used --- src/mlang/irj_parser/irj_lexer.mll | 4 ++-- src/mlang/irj_parser/irj_parser.mly | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index 255f59e19..2fac3cd1f 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -52,12 +52,12 @@ rule token = parse { CONTROLESRAPP } | "#RESULTATS-RAPPELS" { RESULTATSRAPP } -(*| "#DATES" +| "#DATES" { DATES } | "#AVIS_IR" { AVISIR } | "#AVIS_CSG" - { AVISCSG }*) + { AVISCSG } | "##" { ENDSHARP } | '-'? ['0' - '9']+ as i diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index eff8f4cf7..90ff36b40 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -28,7 +28,7 @@ some are characters, some are 0/1, etc. */ %token ENTREESPRIM CONTROLESPRIM RESULTATSPRIM %token ENTREESCORR CONTROLESCORR RESULTATSCORR %token ENTREESRAPP CONTROLESRAPP RESULTATSRAPP -/* %token DATES AVISIR AVISCSG*/ +%token DATES AVISIR AVISCSG %token ENDSHARP %token EOF @@ -64,7 +64,7 @@ rappels: RESULTATSRAPP resultats_attendus_rappels = list(variable_and_value) { Some (entrees_rappels, erreurs_attendues_rappels, resultats_attendus_rappels) } -| ENTREESCORR CONTROLESCORR RESULTATSCORR { None } +| ENTREESCORR CONTROLESCORR RESULTATSCORR DATES? AVISIR? AVISCSG? { None } name: | n = NAME { n } From 3d3aec5d52b40fc3122ca06ec4b99ddf60ec951c Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Thu, 6 Jul 2023 10:28:01 +0200 Subject: [PATCH 03/19] Describe tokens in comments --- src/mlang/irj_parser/irj_parser.mly | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 90ff36b40..8177c4e79 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -24,12 +24,19 @@ along with this program. If not, see . some are characters, some are 0/1, etc. */ %token SLASH +/* Used as field separator */ %token NOM FIP +/* Identifiers */ %token ENTREESPRIM CONTROLESPRIM RESULTATSPRIM -%token ENTREESCORR CONTROLESCORR RESULTATSCORR +/* Primary computation data blocks */ %token ENTREESRAPP CONTROLESRAPP RESULTATSRAPP +/* Corrective computation data blocks */ +%token ENTREESCORR CONTROLESCORR RESULTATSCORR +/* Old form of corrective data blocks, always present and empty in primary computation test files */ %token DATES AVISIR AVISCSG +/* Old empty data blocks rarely found in primary files from 2019 and older */ %token ENDSHARP +/* Mark the end of a record */ %token EOF @@ -57,6 +64,7 @@ primitif: { (entrees_primitif, erreurs_attendues_primitif, resultats_attendus_primitif) } rappels: +/* The two constructions match respectively corrective test files and primary test files */ | ENTREESRAPP entrees_rappels = list(rappel) CONTROLESRAPP From e6331293224aeb2c1b98b739142ffef3723663bb Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Thu, 9 Nov 2023 16:33:04 +0100 Subject: [PATCH 04/19] Change IRJ file AST structure to use nested records instead of 3-uple for data blocks. It allows for easier integration in Mlang interpreter. --- src/mlang/irj_parser/irj_ast.ml | 16 ++++++++++++++-- src/mlang/irj_parser/irj_parser.mly | 14 +++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/irj_ast.ml index 207e868cd..7da573710 100644 --- a/src/mlang/irj_parser/irj_ast.ml +++ b/src/mlang/irj_parser/irj_ast.ml @@ -12,8 +12,20 @@ type rappels = (string * string * var_value * string * string * string * string * string) list +type prim_data_block = { + entrees : var_values; + controles_attendus : errors; + resultats_attendus : var_values; +} + +type corr_data_block = { + entrees_rappels : rappels; + controles_attendus : errors; + resultats_attendus : var_values; +} + type irj_file = { nom : string; - prim : var_values * errors * var_values; - rapp : (rappels * errors * var_values) option; + prim : prim_data_block; + rapp : corr_data_block option; } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 8177c4e79..5687a378f 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -56,22 +56,22 @@ irj_file: primitif: ENTREESPRIM - entrees_primitif = list(variable_and_value) + entrees = list(variable_and_value) CONTROLESPRIM - erreurs_attendues_primitif = list(error_code) + controles_attendus = list(error_code) RESULTATSPRIM - resultats_attendus_primitif = list(variable_and_value) - { (entrees_primitif, erreurs_attendues_primitif, resultats_attendus_primitif) } + resultats_attendus = list(variable_and_value) + { { entrees; controles_attendus; resultats_attendus } } rappels: /* The two constructions match respectively corrective test files and primary test files */ | ENTREESRAPP entrees_rappels = list(rappel) CONTROLESRAPP - erreurs_attendues_rappels = list(error_code) + controles_attendus = list(error_code) RESULTATSRAPP - resultats_attendus_rappels = list(variable_and_value) - { Some (entrees_rappels, erreurs_attendues_rappels, resultats_attendus_rappels) } + resultats_attendus = list(variable_and_value) + { Some { entrees_rappels; controles_attendus; resultats_attendus} } | ENTREESCORR CONTROLESCORR RESULTATSCORR DATES? AVISIR? AVISCSG? { None } name: From 18744666576c18b7e237503c2fd84b447a8712da Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Thu, 9 Nov 2023 16:37:14 +0100 Subject: [PATCH 05/19] Make Mlang test interpreter use IRJ parser instead of built-in Test parser. --- src/mlang/test_framework/test_interpreter.ml | 34 ++++---------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/src/mlang/test_framework/test_interpreter.ml b/src/mlang/test_framework/test_interpreter.ml index 7c050055c..66608e676 100644 --- a/src/mlang/test_framework/test_interpreter.ml +++ b/src/mlang/test_framework/test_interpreter.ml @@ -13,31 +13,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *) -open Test_ast +open Irj_ast -let parse_file (test_name : string) : test_file = - let input = open_in test_name in - let filebuf = Lexing.from_channel input in - let filebuf = - { - filebuf with - lex_curr_p = { filebuf.lex_curr_p with pos_fname = test_name }; - } - in - let f = - try Test_parser.test_file Test_lexer.token filebuf with - | Errors.StructuredError e -> - close_in input; - raise (Errors.StructuredError e) - | Test_parser.Error -> - close_in input; - Errors.raise_spanned_error "Test syntax error" - (Parse_utils.mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) - in - close_in input; - f - -let to_ast_literal (value : Test_ast.literal) : Mast.literal = +let to_ast_literal (value : Irj_ast.literal) : Mast.literal = match value with I i -> Float (float_of_int i) | F f -> Float f let find_var_of_name (p : Mir.program) (name : string Pos.marked) : @@ -58,7 +36,7 @@ let find_var_of_name (p : Mir.program) (name : string Pos.marked) : v2.Mir.Variable.execution_number) (Pos.VarNameToID.find name p.program_idmap)) -let to_MIR_function_and_inputs (program : Bir.program) (t : test_file) +let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file) (test_error_margin : float) : Bir_interface.bir_function * Mir.literal Bir.VariableMap.t = let func_variable_inputs, input_file = @@ -73,7 +51,7 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : test_file) in (Bir.VariableMap.add var () fv, Bir.VariableMap.add var lit in_f)) (Bir.VariableMap.empty, Bir.VariableMap.empty) - t.ep + t.prim.entrees in let func_constant_inputs = Bir.VariableMap.empty in let func_outputs = Bir.VariableMap.empty in @@ -115,7 +93,7 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : test_file) pos ) in (Mast.Binop ((Mast.And, pos), first_exp, second_exp), pos)) - t.rp) + t.prim.resultats_attendus) in ( { func_variable_inputs; func_constant_inputs; func_outputs; func_conds }, input_file ) @@ -125,7 +103,7 @@ let check_test (combined_program : Bir.program) (test_name : string) (round_ops : Cli.round_ops) (test_error_margin : float) : Bir_instrumentation.code_coverage_result = Cli.debug_print "Parsing %s..." test_name; - let t = parse_file test_name in + let t = Irj_file.parse_file test_name in Cli.debug_print "Running test %s..." t.nom; let f, input_file = to_MIR_function_and_inputs combined_program t test_error_margin From 7d7c8ab22f75127582c2b4ad8ac218d7132b59f4 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Thu, 9 Nov 2023 17:24:46 +0100 Subject: [PATCH 06/19] Remove Test parser files --- src/mlang/irj_parser/irj_ast.ml | 16 ++++- src/mlang/irj_parser/irj_file.ml | 16 ++++- src/mlang/irj_parser/irj_lexer.mll | 26 ++++---- src/mlang/irj_parser/irj_parser.mly | 34 +++++------ src/mlang/test_framework/dune | 4 -- src/mlang/test_framework/test_ast.ml | 26 -------- src/mlang/test_framework/test_lexer.mll | 68 --------------------- src/mlang/test_framework/test_parser.mly | 75 ------------------------ 8 files changed, 58 insertions(+), 207 deletions(-) delete mode 100644 src/mlang/test_framework/dune delete mode 100644 src/mlang/test_framework/test_ast.ml delete mode 100644 src/mlang/test_framework/test_lexer.mll delete mode 100644 src/mlang/test_framework/test_parser.mly diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/irj_ast.ml index 7da573710..292b5d0cb 100644 --- a/src/mlang/irj_parser/irj_ast.ml +++ b/src/mlang/irj_parser/irj_ast.ml @@ -1,4 +1,18 @@ -(*From test_ast.ml*) +(* Copyright Inria, contributors: Raphaël Monat (2019) + Mathieu Durero (2023) + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . *) type literal = I of int | F of float diff --git a/src/mlang/irj_parser/irj_file.ml b/src/mlang/irj_parser/irj_file.ml index a7a23cb97..f82e495d6 100644 --- a/src/mlang/irj_parser/irj_file.ml +++ b/src/mlang/irj_parser/irj_file.ml @@ -1,4 +1,18 @@ -(*From test_interpreter.ml*) +(* Copyright Inria, contributors: Raphaël Monat (2019) + Mathieu Durero (2023) + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . *) open Irj_ast diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index 2fac3cd1f..635d336df 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -1,20 +1,18 @@ -(* -Copyright Inria, contributors: - Raphaël Monat (2019) +(* Copyright Inria, contributors: Raphaël Monat (2019) + Mathieu Durero (2023) -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*) + You should have received a copy of the GNU General Public License along with + this program. If not, see . *) { open Lexing diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 5687a378f..43cb06cb3 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -1,21 +1,19 @@ -(* -Copyright Inria, contributors: - Raphaël Monat (2019) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*) - +(* Copyright Inria, contributors: Raphaël Monat (2019) + Mathieu Durero (2023) + + This program is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . *) + %{ open Irj_ast %} diff --git a/src/mlang/test_framework/dune b/src/mlang/test_framework/dune deleted file mode 100644 index 9c35987bf..000000000 --- a/src/mlang/test_framework/dune +++ /dev/null @@ -1,4 +0,0 @@ -(ocamllex test_lexer) - -(menhir - (modules test_parser)) diff --git a/src/mlang/test_framework/test_ast.ml b/src/mlang/test_framework/test_ast.ml deleted file mode 100644 index 88c1d9f38..000000000 --- a/src/mlang/test_framework/test_ast.ml +++ /dev/null @@ -1,26 +0,0 @@ -(* Copyright Inria, contributors: Raphaël Monat (2019) - - This program is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see . *) - -type literal = I of int | F of float - -type var_values = (string * literal * Pos.t) list - -type test_file = { - nom : string; - ep : var_values; - cp : var_values; - rp : var_values; - corr : (var_values * var_values * var_values) option; -} diff --git a/src/mlang/test_framework/test_lexer.mll b/src/mlang/test_framework/test_lexer.mll deleted file mode 100644 index f8109b14a..000000000 --- a/src/mlang/test_framework/test_lexer.mll +++ /dev/null @@ -1,68 +0,0 @@ -(* -Copyright Inria, contributors: - Raphaël Monat (2019) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*) - -{ -open Lexing -open Test_parser -} - -rule token = parse -| [' ' '\t'] (* also ignore newlines, not only whitespace and tabs *) - { token lexbuf } -| '*' [^ '\n']* '\n' (* ignore comments *) - { new_line lexbuf; token lexbuf } -| '\n' | "\r\n" - { new_line lexbuf; token lexbuf} -| "/" - { SLASH } -| "#NOM" - { NOM } -| "#FIP" - { FIP } -| "#ENTREES-PRIMITIF" - { ENTREESP } -| "#CONTROLES-PRIMITIF" - { CONTROLESP } -| "#RESULTATS-PRIMITIF" - { RESULTATSP } -| "#ENTREES-CORRECTIF" - { ENTREESC } -| "#CONTROLES-CORRECTIF" - { CONTROLESC } -| "#RESULTATS-CORRECTIF" - { RESULTATSC } -| "#DATES" - { DATES } -| "#AVIS_IR" - { AVISIR } -| "#AVIS_CSG" - { AVISCSG } -| "##" - { ENDSHARP } -| '-'? ['0' - '9']+ as i - { INTEGER i } -| '-'? ['0' - '9']+ '.' ['0' - '9']* as f - { FLOAT f } -| ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as s - { SYMBOL s } -| ['a'-'z' 'A'-'Z' ' ' '0'-'9' ';' '-']+ as s - { NAME s } -| eof - { EOF } -| _ - { Errors.raise_spanned_error "Test file lexer error" (Parse_utils.mk_position (Lexing.lexeme_start_p lexbuf, Lexing.lexeme_end_p lexbuf)) } diff --git a/src/mlang/test_framework/test_parser.mly b/src/mlang/test_framework/test_parser.mly deleted file mode 100644 index 5af2d69f7..000000000 --- a/src/mlang/test_framework/test_parser.mly +++ /dev/null @@ -1,75 +0,0 @@ -(* -Copyright Inria, contributors: - Raphaël Monat (2019) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*) - -%{ open Test_ast - open Parse_utils %} - -%token SYMBOL NAME INTEGER FLOAT - -%token SLASH -%token NOM FIP -%token ENTREESP CONTROLESP RESULTATSP -%token ENTREESC CONTROLESC RESULTATSC -%token DATES AVISIR AVISCSG -%token ENDSHARP - -%token EOF - -%type test_file - -%start test_file - -%% - - - -test_file: -| NOM nom = name - fip? - ENTREESP - ep = list(variable_and_value) - CONTROLESP - cp = list(variable_and_value) - RESULTATSP - rp = list(variable_and_value) - corr = correctif? - DATES? - AVISIR? - AVISCSG? - ENDSHARP { { nom; ep; cp; rp; corr } } -| EOF { assert false } - -correctif: - ENTREESC - ec = list(variable_and_value) - CONTROLESC - cc = list(variable_and_value) - RESULTATSC - rc = list(variable_and_value) { (ec, cc, rc) } - - -name: -| n = NAME { n } -| n = SYMBOL { n } - -fip: - FIP SLASH option(SYMBOL) { } - -variable_and_value: -| var = SYMBOL SLASH value = INTEGER { (var, I (int_of_string value), mk_position $sloc) } -| var = SYMBOL SLASH value = FLOAT { (var, F (float_of_string value), mk_position $sloc) } From 9938401784e75badeca380be0422bcc27daaaf72 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 14:20:48 +0100 Subject: [PATCH 07/19] Add flags to Menhir for test file checker compatibility, #224 --- src/mlang/irj_parser/dune | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mlang/irj_parser/dune b/src/mlang/irj_parser/dune index ff3cc36dc..bc6790ba2 100644 --- a/src/mlang/irj_parser/dune +++ b/src/mlang/irj_parser/dune @@ -1,4 +1,5 @@ (ocamllex irj_lexer) (menhir - (modules irj_parser)) + (modules irj_parser) + (flags --strict --explain)) From 6cb06e1f01188929c92735dbe4a55e5f6818d1eb Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 18:26:50 +0100 Subject: [PATCH 08/19] With a true "rappel" implementation as records, and some errors, as taken from #224. Step in allowing a peaceful merge for #222 and #224. --- src/mlang/irj_parser/irj_ast.ml | 43 ++++++++++++----- src/mlang/irj_parser/irj_parser.mly | 72 +++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 30 deletions(-) diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/irj_ast.ml index 292b5d0cb..1b59e2303 100644 --- a/src/mlang/irj_parser/irj_ast.ml +++ b/src/mlang/irj_parser/irj_ast.ml @@ -1,5 +1,6 @@ (* Copyright Inria, contributors: Raphaël Monat (2019) Mathieu Durero (2023) + David Declerck (2023) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -18,28 +19,48 @@ type literal = I of int | F of float type var_value = string * literal * Pos.t -type var_values = var_value list +(* type var_values = var_value list *) -type errors = (string * Pos.t) list +type calc_error = string * Pos.t -type rappels = - (string * string * var_value * string * string * string * string * string) - list +(* type calc_errors = calc_error list *) + +(* type rappel = string * string * var_value * string * string * string * string + * string *) +type rappel = { + event_nb : int; + rappel_nb : int; + variable_code : string; + change_value : int; + direction : string; + (* R, C, M, P *) + penalty_code : int option; + (* 0 - 99 *) + base_tolerance_legale : int option; + month_year : int; + (* MMYYYY *) + decl_2042_rect : int option; + (* 0 or 1 *) + pos : Pos.t; +} type prim_data_block = { - entrees : var_values; - controles_attendus : errors; - resultats_attendus : var_values; + entrees : var_value list; + controles_attendus : calc_error list; + resultats_attendus : var_value list; } type corr_data_block = { - entrees_rappels : rappels; - controles_attendus : errors; - resultats_attendus : var_values; + entrees_rappels : rappel list; + controles_attendus : calc_error list; + resultats_attendus : var_value list; } type irj_file = { nom : string; prim : prim_data_block; rapp : corr_data_block option; + (* corr : prim_data_block option; *) + (*corr is for old correctif form from primitif files, rapp is for the + actual one in correctif files*) } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 43cb06cb3..95d1919ec 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -1,5 +1,6 @@ (* Copyright Inria, contributors: Raphaël Monat (2019) Mathieu Durero (2023) + David Declerck (2023) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -13,8 +14,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *) - + %{ open Irj_ast + + let error (sp, ep) msg = + Errors.raise_spanned_error ("Parse error : " ^ msg) + (Parse_utils.mk_position (sp, ep)) + %} %token SYMBOL NAME INTEGER FLOAT @@ -36,6 +42,8 @@ some are characters, some are 0/1, etc. */ %token ENDSHARP /* Mark the end of a record */ +%token NL +/* New line */ %token EOF %type irj_file @@ -49,7 +57,7 @@ irj_file: fip? prim = primitif rapp = rappels - ENDSHARP { { nom; prim; rapp } } + endsharp { { nom; prim; rapp } } | EOF { assert false } primitif: @@ -80,26 +88,52 @@ fip: FIP SLASH option(SYMBOL) { } variable_and_value: -| var = SYMBOL SLASH value = INTEGER { (var, I (int_of_string value), Parse_utils.mk_position $sloc) } -| var = SYMBOL SLASH value = FLOAT { (var, F (float_of_string value), Parse_utils.mk_position $sloc) } +| var = SYMBOL SLASH value = value { (var, value, Parse_utils.mk_position $sloc) } +| SYMBOL error { error $loc "Missing slash in pair variable/value" } error_code: error = SYMBOL { (error, Parse_utils.mk_position $sloc) } rappel: - event_nb = INTEGER SLASH - rappel_nb = INTEGER SLASH - variable_change = variable_and_value SLASH + event_nb = integer SLASH + rappel_nb = integer SLASH + variable_code = SYMBOL SLASH + change_value = integer SLASH direction = SYMBOL SLASH - penalty_code = INTEGER SLASH - base_tolerance_legale = INTEGER SLASH - month_year = INTEGER SLASH - decl_2042_rect = INTEGER - { (event_nb, - rappel_nb, - variable_change, - direction, - penalty_code, - base_tolerance_legale, - month_year, - decl_2042_rect) } + penalty_code = INTEGER? SLASH + base_tolerance_legale = INTEGER? SLASH + month_year = integer SLASH + decl_2042_rect = INTEGER? NL + { + if direction <> "R" && direction <> "C" && direction <> "M" && direction <> "P" then + error $loc(direction) ("Unknown value for 'direction' (type of the 'rappel', should be R, C, M or P) : " ^ direction); + let p = match penalty_code with Some p -> int_of_string p | _ -> 0 in + if p < 0 || p > 99 then + error $loc(direction) ("Invalid value for 'penalty_code' (out of range 0-99) : " ^ (string_of_int p)); + let penalty_code = match penalty_code with Some i -> Some (int_of_string i) | None -> None in + let base_tolerance_legale = match base_tolerance_legale with Some i -> Some (int_of_string i) | None -> None in + let decl_2042_rect = match decl_2042_rect with Some i -> Some (int_of_string i) | None -> None in + {event_nb; + rappel_nb; + variable_code; + change_value; + direction; + penalty_code; + base_tolerance_legale; + month_year; + decl_2042_rect; + pos = Parse_utils.mk_position $sloc } + } + +integer: +| i = INTEGER { int_of_string i } +| error { error $loc "Missing integer" } + +value: +| i = INTEGER { I (int_of_string i) } +| f = FLOAT { F (float_of_string f) } +| error { error $loc "Missing numerical value" } + +endsharp: +| ENDSHARP { () } +| error { error $loc "Missing ## at end of file" } From fc3ce45d043383d017db30751106deacac6ab7b7 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 19:10:43 +0100 Subject: [PATCH 09/19] Only moving parts and page layout --- src/mlang/irj_parser/irj_ast.ml | 3 +-- src/mlang/irj_parser/irj_parser.mly | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/irj_ast.ml index 1b59e2303..9466f8001 100644 --- a/src/mlang/irj_parser/irj_ast.ml +++ b/src/mlang/irj_parser/irj_ast.ml @@ -1,6 +1,5 @@ (* Copyright Inria, contributors: Raphaël Monat (2019) - Mathieu Durero (2023) - David Declerck (2023) + Mathieu Durero , David Declerck (2023) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 95d1919ec..13535a2c0 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -60,6 +60,14 @@ irj_file: endsharp { { nom; prim; rapp } } | EOF { assert false } + +name: +| n = NAME { n } +| n = SYMBOL { n } + +fip: + FIP SLASH option(SYMBOL) { } + primitif: ENTREESPRIM entrees = list(variable_and_value) @@ -80,13 +88,6 @@ rappels: { Some { entrees_rappels; controles_attendus; resultats_attendus} } | ENTREESCORR CONTROLESCORR RESULTATSCORR DATES? AVISIR? AVISCSG? { None } -name: -| n = NAME { n } -| n = SYMBOL { n } - -fip: - FIP SLASH option(SYMBOL) { } - variable_and_value: | var = SYMBOL SLASH value = value { (var, value, Parse_utils.mk_position $sloc) } | SYMBOL error { error $loc "Missing slash in pair variable/value" } From 9d59616328aa10acc9047e2bea3ed26df30ed30a Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 19:27:32 +0100 Subject: [PATCH 10/19] Add NL and EOF where they do not break CI with current lexer --- src/mlang/irj_parser/irj_parser.mly | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 13535a2c0..0df50be55 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -57,16 +57,17 @@ irj_file: fip? prim = primitif rapp = rappels - endsharp { { nom; prim; rapp } } + endsharp + EOF { { nom; prim; rapp } } | EOF { assert false } - +/* What's the point of this alternative?*/ name: | n = NAME { n } | n = SYMBOL { n } fip: - FIP SLASH option(SYMBOL) { } + FIP SLASH SYMBOL? NL { } (* it is actually allowed to leave it blank *) primitif: ENTREESPRIM @@ -88,12 +89,13 @@ rappels: { Some { entrees_rappels; controles_attendus; resultats_attendus} } | ENTREESCORR CONTROLESCORR RESULTATSCORR DATES? AVISIR? AVISCSG? { None } +/* Add NL token below?*/ variable_and_value: | var = SYMBOL SLASH value = value { (var, value, Parse_utils.mk_position $sloc) } | SYMBOL error { error $loc "Missing slash in pair variable/value" } error_code: - error = SYMBOL { (error, Parse_utils.mk_position $sloc) } + error = SYMBOL NL { (error, Parse_utils.mk_position $sloc) } rappel: event_nb = integer SLASH From c8896bfdbb020884c539064c6185d55828072921 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 19:31:39 +0100 Subject: [PATCH 11/19] Add the last parser checks from #224 --- src/mlang/irj_parser/irj_parser.mly | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 0df50be55..33c7e3e92 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -53,13 +53,20 @@ some are characters, some are 0/1, etc. */ %% irj_file: -| NOM nom = name +| NOM nom = list(name) fip? prim = primitif rapp = rappels endsharp - EOF { { nom; prim; rapp } } -| EOF { assert false } + EOF { + let nom = + match nom with + | [n] -> n + | [] -> error $loc(nom) "Missing name in section #NOM" + | _ -> error $loc(nom) "Extra line(s) in section #NOM" + in + { nom; prim; rapp } } +| EOF { error $loc "Empty test file" } /* What's the point of this alternative?*/ name: From cc5f4d687bb338de7115dfe44737dda7d2c9e301 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 20:02:12 +0100 Subject: [PATCH 12/19] Import #224 lexer, adding all NL tokens --- src/mlang/irj_parser/irj_lexer.mll | 121 ++++++++++++++++++---------- src/mlang/irj_parser/irj_parser.mly | 26 +++--- 2 files changed, 91 insertions(+), 56 deletions(-) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index 635d336df..38549c88e 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -1,5 +1,5 @@ (* Copyright Inria, contributors: Raphaël Monat (2019) - Mathieu Durero (2023) + David Declerck (2023) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -17,56 +17,91 @@ { open Lexing open Irj_parser + +module StrMap = Map.Make (String) + +let keywords = + List.fold_left (fun map (kw, tok) -> + StrMap.add kw tok map + ) StrMap.empty [ + "#NOM", NOM; + "#FIP", FIP; + "#ENTREES-PRIMITIF", ENTREESPRIM; + "#CONTROLES-PRIMITIF", CONTROLESPRIM; + "#RESULTATS-PRIMITIF", RESULTATSPRIM; + "#ENTREES-CORRECTIF", ENTREESCORR; + "#CONTROLES-CORRECTIF", CONTROLESCORR; + "#RESULTATS-CORRECTIF", RESULTATSCORR; + "#ENTREES-RAPPELS", ENTREESRAPP; + "#CONTROLES-RAPPELS", CONTROLESRAPP; + "#RESULTATS-RAPPELS", RESULTATSRAPP; + "#DATES", DATES; + "#AVIS_IR", AVISIR; + "#AVIS_CSG", AVISCSG; + ] + +let error lb msg = + Errors.raise_spanned_error ("Lexing error : " ^ msg) + (Parse_utils.mk_position (Lexing.lexeme_start_p lb, + Lexing.lexeme_end_p lb)) + +let is_bol lb = + lb.lex_start_p.pos_cnum - lb.lex_start_p.pos_bol = 0 + +let check_cr lb = + if String.contains (lexeme lb) '\r' then + error lb ("Carriage return detected") + } +let blank = [' ' '\t'] +let any = [^ '\n'] +let nl = ['\n'] + rule token = parse -| [' ' '\t'] (* also ignore newlines, not only whitespace and tabs *) - { token lexbuf } -| '*' [^ '\n']* '\n' (* ignore comments *) - { new_line lexbuf; token lexbuf } + | '\n' | "\r\n" - { new_line lexbuf; token lexbuf} -| "/" - { SLASH } -| "#NOM" - { NOM } -| "#FIP" - { FIP } -| "#ENTREES-PRIMITIF" - { ENTREESPRIM } -| "#CONTROLES-PRIMITIF" - { CONTROLESPRIM } -| "#RESULTATS-PRIMITIF" - { RESULTATSPRIM } -| "#ENTREES-CORRECTIF" - { ENTREESCORR } -| "#CONTROLES-CORRECTIF" - { CONTROLESCORR } -| "#RESULTATS-CORRECTIF" - { RESULTATSCORR } -| "#ENTREES-RAPPELS" - { ENTREESRAPP } -| "#CONTROLES-RAPPELS" - { CONTROLESRAPP } -| "#RESULTATS-RAPPELS" - { RESULTATSRAPP } -| "#DATES" - { DATES } -| "#AVIS_IR" - { AVISIR } -| "#AVIS_CSG" - { AVISCSG } -| "##" - { ENDSHARP } + { check_cr lexbuf; new_line lexbuf; + if is_bol lexbuf then token lexbuf + else NL } + +| '*' any* nl + { check_cr lexbuf; new_line lexbuf; + if is_bol lexbuf then token lexbuf + else error lexbuf "Comment with * must start in the first column" } + +| blank any* nl + { check_cr lexbuf; new_line lexbuf; + if is_bol lexbuf then error lexbuf "Line can not start with a blank" + else NL } + | '-'? ['0' - '9']+ as i - { INTEGER i } + { INTEGER i} + (* Change here for int_of_string i and float_of_string f*) + | '-'? ['0' - '9']+ '.' ['0' - '9']* as f - { FLOAT f } + { FLOAT f} + | ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as s { SYMBOL s } -| ['a'-'z' 'A'-'Z' ' ' '0'-'9' ';' '-']+ as s + +| ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' '.' ';' (*' '*)]+ as s { NAME s } + +| "/" + { SLASH } + +| "##" + { ENDSHARP } + +| "#" ['a'-'z' 'A'-'Z' '0'-'9' '_' '-']+ as s + { match StrMap.find_opt s keywords with + | None -> error lexbuf (Printf.sprintf "Unknown section name: '#%s'" s) + | Some t -> t } + | eof { EOF } -| _ - { Errors.raise_spanned_error "Test file lexer error" (Parse_utils.mk_position (Lexing.lexeme_start_p lexbuf, Lexing.lexeme_end_p lexbuf)) } + +| _ as c + { error lexbuf (Printf.sprintf + "Unexpected character '%c' (%d)" c (Char.code c)) } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 33c7e3e92..afb8c512b 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -53,11 +53,12 @@ some are characters, some are 0/1, etc. */ %% irj_file: -| NOM nom = list(name) +| NOM NL + nom = list(name) fip? prim = primitif rapp = rappels - endsharp + endsharp NL EOF { let nom = match nom with @@ -70,35 +71,34 @@ irj_file: /* What's the point of this alternative?*/ name: -| n = NAME { n } -| n = SYMBOL { n } +| n = NAME NL { n } +| n = SYMBOL NL { n } fip: FIP SLASH SYMBOL? NL { } (* it is actually allowed to leave it blank *) primitif: - ENTREESPRIM + ENTREESPRIM NL entrees = list(variable_and_value) - CONTROLESPRIM + CONTROLESPRIM NL controles_attendus = list(error_code) - RESULTATSPRIM + RESULTATSPRIM NL resultats_attendus = list(variable_and_value) { { entrees; controles_attendus; resultats_attendus } } rappels: /* The two constructions match respectively corrective test files and primary test files */ -| ENTREESRAPP +| ENTREESRAPP NL entrees_rappels = list(rappel) - CONTROLESRAPP + CONTROLESRAPP NL controles_attendus = list(error_code) - RESULTATSRAPP + RESULTATSRAPP NL resultats_attendus = list(variable_and_value) { Some { entrees_rappels; controles_attendus; resultats_attendus} } -| ENTREESCORR CONTROLESCORR RESULTATSCORR DATES? AVISIR? AVISCSG? { None } +| ENTREESCORR NL CONTROLESCORR NL RESULTATSCORR NL DATES? AVISIR? AVISCSG? { None } -/* Add NL token below?*/ variable_and_value: -| var = SYMBOL SLASH value = value { (var, value, Parse_utils.mk_position $sloc) } +| var = SYMBOL SLASH value = value NL { (var, value, Parse_utils.mk_position $sloc) } | SYMBOL error { error $loc "Missing slash in pair variable/value" } error_code: From debeadf77a3d628ec861598fd58354d9e7f7d4ed Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 20:05:33 +0100 Subject: [PATCH 13/19] Explicit calc_error name for errors from 'Calculette' --- src/mlang/irj_parser/irj_parser.mly | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index afb8c512b..3fc51a9f2 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -81,7 +81,7 @@ primitif: ENTREESPRIM NL entrees = list(variable_and_value) CONTROLESPRIM NL - controles_attendus = list(error_code) + controles_attendus = list(calc_error) RESULTATSPRIM NL resultats_attendus = list(variable_and_value) { { entrees; controles_attendus; resultats_attendus } } @@ -91,7 +91,7 @@ rappels: | ENTREESRAPP NL entrees_rappels = list(rappel) CONTROLESRAPP NL - controles_attendus = list(error_code) + controles_attendus = list(calc_error) RESULTATSRAPP NL resultats_attendus = list(variable_and_value) { Some { entrees_rappels; controles_attendus; resultats_attendus} } @@ -101,7 +101,7 @@ variable_and_value: | var = SYMBOL SLASH value = value NL { (var, value, Parse_utils.mk_position $sloc) } | SYMBOL error { error $loc "Missing slash in pair variable/value" } -error_code: +calc_error: error = SYMBOL NL { (error, Parse_utils.mk_position $sloc) } rappel: From d78259f1ab1e742661449d3732ba977b7d143b46 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 20:20:11 +0100 Subject: [PATCH 14/19] Comments on lexer --- src/mlang/irj_parser/irj_lexer.mll | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index 38549c88e..e5418631f 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -46,12 +46,13 @@ let error lb msg = Lexing.lexeme_end_p lb)) let is_bol lb = + (* bol = beginning of line *) lb.lex_start_p.pos_cnum - lb.lex_start_p.pos_bol = 0 let check_cr lb = if String.contains (lexeme lb) '\r' then error lb ("Carriage return detected") - + (* No more supposed to be an error in autotests. Keeping it to enforce it later? *) } let blank = [' ' '\t'] @@ -69,6 +70,7 @@ rule token = parse { check_cr lexbuf; new_line lexbuf; if is_bol lexbuf then token lexbuf else error lexbuf "Comment with * must start in the first column" } + (* Quite sure this will be to much: we have end of line comments*) | blank any* nl { check_cr lexbuf; new_line lexbuf; @@ -87,6 +89,7 @@ rule token = parse | ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' '.' ';' (*' '*)]+ as s { NAME s } + (* Compared to the old lexer, adds _ and . remove space *) | "/" { SLASH } From 41144400ce63361c13f4c0b117b0ca20b6c0544d Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 20:44:01 +0100 Subject: [PATCH 15/19] Use actual integer and float tokens in parser String conversion now takes place in lexer. --- src/mlang/irj_parser/irj_lexer.mll | 7 +++---- src/mlang/irj_parser/irj_parser.mly | 17 +++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index e5418631f..af690bc19 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -78,11 +78,10 @@ rule token = parse else NL } | '-'? ['0' - '9']+ as i - { INTEGER i} - (* Change here for int_of_string i and float_of_string f*) - + { INTEGER (int_of_string i) } + | '-'? ['0' - '9']+ '.' ['0' - '9']* as f - { FLOAT f} + { FLOAT (float_of_string f) } (* DONT KEEP THAT *) | ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as s { SYMBOL s } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 3fc51a9f2..7aebcb5ac 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -23,9 +23,9 @@ %} -%token SYMBOL NAME INTEGER FLOAT -/* Possibly use stronger constraints than just string on rappel's fields -some are characters, some are 0/1, etc. */ +%token SYMBOL NAME +%token INTEGER +%token FLOAT %token SLASH /* Used as field separator */ @@ -117,12 +117,9 @@ rappel: { if direction <> "R" && direction <> "C" && direction <> "M" && direction <> "P" then error $loc(direction) ("Unknown value for 'direction' (type of the 'rappel', should be R, C, M or P) : " ^ direction); - let p = match penalty_code with Some p -> int_of_string p | _ -> 0 in + let p = match penalty_code with Some p -> p | _ -> 0 in if p < 0 || p > 99 then error $loc(direction) ("Invalid value for 'penalty_code' (out of range 0-99) : " ^ (string_of_int p)); - let penalty_code = match penalty_code with Some i -> Some (int_of_string i) | None -> None in - let base_tolerance_legale = match base_tolerance_legale with Some i -> Some (int_of_string i) | None -> None in - let decl_2042_rect = match decl_2042_rect with Some i -> Some (int_of_string i) | None -> None in {event_nb; rappel_nb; variable_code; @@ -136,12 +133,12 @@ rappel: } integer: -| i = INTEGER { int_of_string i } +| i = INTEGER { i } | error { error $loc "Missing integer" } value: -| i = INTEGER { I (int_of_string i) } -| f = FLOAT { F (float_of_string f) } +| i = INTEGER { I (i) } +| f = FLOAT { F (f) } | error { error $loc "Missing numerical value" } endsharp: From e492f35cf689fe87d34da59503c76ac6d0c7de27 Mon Sep 17 00:00:00 2001 From: Mathieu Durero Date: Fri, 10 Nov 2023 20:57:03 +0100 Subject: [PATCH 16/19] Comments on design choices --- src/mlang/irj_parser/irj_lexer.mll | 4 ++-- src/mlang/irj_parser/irj_parser.mly | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/irj_lexer.mll index af690bc19..82b925bb1 100644 --- a/src/mlang/irj_parser/irj_lexer.mll +++ b/src/mlang/irj_parser/irj_lexer.mll @@ -70,7 +70,6 @@ rule token = parse { check_cr lexbuf; new_line lexbuf; if is_bol lexbuf then token lexbuf else error lexbuf "Comment with * must start in the first column" } - (* Quite sure this will be to much: we have end of line comments*) | blank any* nl { check_cr lexbuf; new_line lexbuf; @@ -82,13 +81,14 @@ rule token = parse | '-'? ['0' - '9']+ '.' ['0' - '9']* as f { FLOAT (float_of_string f) } (* DONT KEEP THAT *) + (* Probably in order to write a specific function for our number format *) | ['a'-'z' 'A'-'Z' '0'-'9' '_']+ as s { SYMBOL s } | ['a'-'z' 'A'-'Z' '0'-'9' '_' '-' '.' ';' (*' '*)]+ as s { NAME s } - (* Compared to the old lexer, adds _ and . remove space *) + (* Compared to the old lexer, adds _ and . removes space *) | "/" { SLASH } diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/irj_parser.mly index 7aebcb5ac..407650931 100644 --- a/src/mlang/irj_parser/irj_parser.mly +++ b/src/mlang/irj_parser/irj_parser.mly @@ -108,7 +108,7 @@ rappel: event_nb = integer SLASH rappel_nb = integer SLASH variable_code = SYMBOL SLASH - change_value = integer SLASH + change_value = integer SLASH (* No decimal value was found in existing files *) direction = SYMBOL SLASH penalty_code = INTEGER? SLASH base_tolerance_legale = INTEGER? SLASH From 900d4c73155ca47fc7043d6aec17ac851e2e8424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Ensarguet?= Date: Wed, 22 Nov 2023 14:04:09 +0100 Subject: [PATCH 17/19] reorganized to include a irj-parser opam package --- src/mlang/dune | 2 +- src/mlang/irj_parser/dune | 13 ++++-- src/mlang/irj_parser/dune-project | 46 +++++++++++++++++++ src/mlang/irj_parser/irj_parser.opam | 35 ++++++++++++++ src/mlang/irj_parser/main.ml | 0 src/mlang/irj_parser/src/dune | 22 +++++++++ src/mlang/irj_parser/{ => src}/irj_ast.ml | 0 src/mlang/irj_parser/{ => src}/irj_file.ml | 0 src/mlang/irj_parser/{ => src}/irj_file.mli | 0 src/mlang/irj_parser/{ => src}/irj_lexer.mll | 0 src/mlang/irj_parser/{ => src}/irj_parser.mly | 0 .../{ => irj_parser/src}/m_frontend/mast.ml | 0 .../src}/m_frontend/parse_utils.ml | 0 .../src}/m_frontend/parse_utils.mli | 0 src/mlang/{ => irj_parser/src}/utils/cli.ml | 0 src/mlang/{ => irj_parser/src}/utils/cli.mli | 0 .../{ => irj_parser/src}/utils/errors.ml | 0 .../{ => irj_parser/src}/utils/errors.mli | 0 src/mlang/{ => irj_parser/src}/utils/pos.ml | 0 src/mlang/{ => irj_parser/src}/utils/pos.mli | 0 20 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 src/mlang/irj_parser/dune-project create mode 100644 src/mlang/irj_parser/irj_parser.opam create mode 100644 src/mlang/irj_parser/main.ml create mode 100644 src/mlang/irj_parser/src/dune rename src/mlang/irj_parser/{ => src}/irj_ast.ml (100%) rename src/mlang/irj_parser/{ => src}/irj_file.ml (100%) rename src/mlang/irj_parser/{ => src}/irj_file.mli (100%) rename src/mlang/irj_parser/{ => src}/irj_lexer.mll (100%) rename src/mlang/irj_parser/{ => src}/irj_parser.mly (100%) rename src/mlang/{ => irj_parser/src}/m_frontend/mast.ml (100%) rename src/mlang/{ => irj_parser/src}/m_frontend/parse_utils.ml (100%) rename src/mlang/{ => irj_parser/src}/m_frontend/parse_utils.mli (100%) rename src/mlang/{ => irj_parser/src}/utils/cli.ml (100%) rename src/mlang/{ => irj_parser/src}/utils/cli.mli (100%) rename src/mlang/{ => irj_parser/src}/utils/errors.ml (100%) rename src/mlang/{ => irj_parser/src}/utils/errors.mli (100%) rename src/mlang/{ => irj_parser/src}/utils/pos.ml (100%) rename src/mlang/{ => irj_parser/src}/utils/pos.mli (100%) diff --git a/src/mlang/dune b/src/mlang/dune index ccce97d59..52665702d 100644 --- a/src/mlang/dune +++ b/src/mlang/dune @@ -8,7 +8,7 @@ (library (public_name mlang) (libraries ocamlgraph re ANSITerminal parmap cmdliner threads - dune-build-info num gmp)) + dune-build-info num gmp irj_parser)) (documentation (package mlang) diff --git a/src/mlang/irj_parser/dune b/src/mlang/irj_parser/dune index bc6790ba2..4dfcbc39f 100644 --- a/src/mlang/irj_parser/dune +++ b/src/mlang/irj_parser/dune @@ -1,5 +1,10 @@ -(ocamllex irj_lexer) +(env + (static + (ocamlopt_flags + (-O3 -ccopt -static)))) -(menhir - (modules irj_parser) - (flags --strict --explain)) +(executable + (name main) + (package irj_parser) + (public_name irj_parser.exe) + (libraries irj_parser)) diff --git a/src/mlang/irj_parser/dune-project b/src/mlang/irj_parser/dune-project new file mode 100644 index 000000000..9d75c62f9 --- /dev/null +++ b/src/mlang/irj_parser/dune-project @@ -0,0 +1,46 @@ +(lang dune 2.5) + +(name irj_parser) + +(generate_opam_files true) + +(homepage https://github.com/MLanguage/mlang/tree/IRJ-parser-library) + +(bug_reports https://github.com/MLanguage/mlang/issues) + +(authors "Mathieu Durero" "Rapha\195\171l Monat") + +(maintainers "Mathieu Durero" " Noé Ensarguet") + +(license GPL-3.0-or-later) + +;(documentation https://url/to/documentation) + +(using menhir 2.0) + +(package + (name irj_parser) + (synopsis "Parser for the IRJ tests") + (description "This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax") + (depends + (ocaml + (and(>= "4.11.2"))) + (dune + (and :build)) + (ANSITerminal + (= 0.8.2)) + (cmdliner + (= 1.1.0)) + (re + (= 1.9.0)) + (ocamlgraph + (= 1.8.8)) + (odoc + (= 1.5.3)) + (dune-build-info + (= 2.5.1)) + (ocamlformat + (= 0.19.0)) + )) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/src/mlang/irj_parser/irj_parser.opam b/src/mlang/irj_parser/irj_parser.opam new file mode 100644 index 000000000..a2707b377 --- /dev/null +++ b/src/mlang/irj_parser/irj_parser.opam @@ -0,0 +1,35 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "Parser for the IRJ tests" +description: + "This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax" +maintainer: ["Mathieu Durero" " Noé Ensarguet"] +authors: ["Mathieu Durero" "Raphaël Monat"] +license: "GPL-3.0-or-later" +homepage: "https://github.com/MLanguage/mlang/tree/IRJ-parser-library" +bug-reports: "https://github.com/MLanguage/mlang/issues" +depends: [ + "ocaml" {>= "4.11.2"} + "dune" {build} + "ANSITerminal" {= "0.8.2"} + "cmdliner" {= "1.1.0"} + "re" {= "1.9.0"} + "ocamlgraph" {= "1.8.8"} + "odoc" {= "1.5.3"} + "dune-build-info" {= "2.5.1"} + "ocamlformat" {= "0.19.0"} +] +build: [ + ["dune" "subst"] {pinned} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] diff --git a/src/mlang/irj_parser/main.ml b/src/mlang/irj_parser/main.ml new file mode 100644 index 000000000..e69de29bb diff --git a/src/mlang/irj_parser/src/dune b/src/mlang/irj_parser/src/dune new file mode 100644 index 000000000..21f2f64e1 --- /dev/null +++ b/src/mlang/irj_parser/src/dune @@ -0,0 +1,22 @@ +(env + (static + (ocamlopt_flags + (-O3 -ccopt -static)))) + +(include_subdirs unqualified) + +(library + (name irj_file) + (public_name irj_parser) + (wrapped false) + (libraries ANSITerminal re dune-build-info threads cmdliner)) + +(ocamllex irj_lexer) + +(menhir + (modules irj_parser) + (flags --strict --explain)) + +;(documentation +; (package irj_parser) +; (mld_files ("index"))) diff --git a/src/mlang/irj_parser/irj_ast.ml b/src/mlang/irj_parser/src/irj_ast.ml similarity index 100% rename from src/mlang/irj_parser/irj_ast.ml rename to src/mlang/irj_parser/src/irj_ast.ml diff --git a/src/mlang/irj_parser/irj_file.ml b/src/mlang/irj_parser/src/irj_file.ml similarity index 100% rename from src/mlang/irj_parser/irj_file.ml rename to src/mlang/irj_parser/src/irj_file.ml diff --git a/src/mlang/irj_parser/irj_file.mli b/src/mlang/irj_parser/src/irj_file.mli similarity index 100% rename from src/mlang/irj_parser/irj_file.mli rename to src/mlang/irj_parser/src/irj_file.mli diff --git a/src/mlang/irj_parser/irj_lexer.mll b/src/mlang/irj_parser/src/irj_lexer.mll similarity index 100% rename from src/mlang/irj_parser/irj_lexer.mll rename to src/mlang/irj_parser/src/irj_lexer.mll diff --git a/src/mlang/irj_parser/irj_parser.mly b/src/mlang/irj_parser/src/irj_parser.mly similarity index 100% rename from src/mlang/irj_parser/irj_parser.mly rename to src/mlang/irj_parser/src/irj_parser.mly diff --git a/src/mlang/m_frontend/mast.ml b/src/mlang/irj_parser/src/m_frontend/mast.ml similarity index 100% rename from src/mlang/m_frontend/mast.ml rename to src/mlang/irj_parser/src/m_frontend/mast.ml diff --git a/src/mlang/m_frontend/parse_utils.ml b/src/mlang/irj_parser/src/m_frontend/parse_utils.ml similarity index 100% rename from src/mlang/m_frontend/parse_utils.ml rename to src/mlang/irj_parser/src/m_frontend/parse_utils.ml diff --git a/src/mlang/m_frontend/parse_utils.mli b/src/mlang/irj_parser/src/m_frontend/parse_utils.mli similarity index 100% rename from src/mlang/m_frontend/parse_utils.mli rename to src/mlang/irj_parser/src/m_frontend/parse_utils.mli diff --git a/src/mlang/utils/cli.ml b/src/mlang/irj_parser/src/utils/cli.ml similarity index 100% rename from src/mlang/utils/cli.ml rename to src/mlang/irj_parser/src/utils/cli.ml diff --git a/src/mlang/utils/cli.mli b/src/mlang/irj_parser/src/utils/cli.mli similarity index 100% rename from src/mlang/utils/cli.mli rename to src/mlang/irj_parser/src/utils/cli.mli diff --git a/src/mlang/utils/errors.ml b/src/mlang/irj_parser/src/utils/errors.ml similarity index 100% rename from src/mlang/utils/errors.ml rename to src/mlang/irj_parser/src/utils/errors.ml diff --git a/src/mlang/utils/errors.mli b/src/mlang/irj_parser/src/utils/errors.mli similarity index 100% rename from src/mlang/utils/errors.mli rename to src/mlang/irj_parser/src/utils/errors.mli diff --git a/src/mlang/utils/pos.ml b/src/mlang/irj_parser/src/utils/pos.ml similarity index 100% rename from src/mlang/utils/pos.ml rename to src/mlang/irj_parser/src/utils/pos.ml diff --git a/src/mlang/utils/pos.mli b/src/mlang/irj_parser/src/utils/pos.mli similarity index 100% rename from src/mlang/utils/pos.mli rename to src/mlang/irj_parser/src/utils/pos.mli From 906230cff00f2796e8ab6730ed05000bb758641c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Ensarguet?= Date: Thu, 23 Nov 2023 18:09:35 +0100 Subject: [PATCH 18/19] irj_parser library (somewhat properly) reorganised --- dune-project | 14 ++++++ .../irj_parser.opam => irj_parser.opam | 15 +++--- src/{mlang => }/irj_parser/dune | 0 src/{mlang => }/irj_parser/main.ml | 0 src/{mlang => }/irj_parser/src/dune | 9 +--- src/{mlang => }/irj_parser/src/irj_ast.ml | 15 ++++-- src/{mlang => }/irj_parser/src/irj_file.ml | 11 +++-- src/{mlang => }/irj_parser/src/irj_file.mli | 0 src/{mlang => }/irj_parser/src/irj_lexer.mll | 11 +++-- src/{mlang => }/irj_parser/src/irj_parser.mly | 11 ++--- src/mlang/irj_parser/dune-project | 46 ------------------- .../{irj_parser/src => }/m_frontend/mast.ml | 0 .../src => }/m_frontend/parse_utils.ml | 0 .../src => }/m_frontend/parse_utils.mli | 0 src/mlang/test_framework/test_interpreter.ml | 41 ++++++++++------- src/mlang/{irj_parser/src => }/utils/cli.ml | 0 src/mlang/{irj_parser/src => }/utils/cli.mli | 0 .../{irj_parser/src => }/utils/errors.ml | 0 .../{irj_parser/src => }/utils/errors.mli | 0 src/mlang/{irj_parser/src => }/utils/pos.ml | 0 src/mlang/{irj_parser/src => }/utils/pos.mli | 4 +- 21 files changed, 78 insertions(+), 99 deletions(-) rename src/mlang/irj_parser/irj_parser.opam => irj_parser.opam (60%) rename src/{mlang => }/irj_parser/dune (100%) rename src/{mlang => }/irj_parser/main.ml (100%) rename src/{mlang => }/irj_parser/src/dune (52%) rename src/{mlang => }/irj_parser/src/irj_ast.ml (83%) rename src/{mlang => }/irj_parser/src/irj_file.ml (83%) rename src/{mlang => }/irj_parser/src/irj_file.mli (100%) rename src/{mlang => }/irj_parser/src/irj_lexer.mll (93%) rename src/{mlang => }/irj_parser/src/irj_parser.mly (93%) delete mode 100644 src/mlang/irj_parser/dune-project rename src/mlang/{irj_parser/src => }/m_frontend/mast.ml (100%) rename src/mlang/{irj_parser/src => }/m_frontend/parse_utils.ml (100%) rename src/mlang/{irj_parser/src => }/m_frontend/parse_utils.mli (100%) rename src/mlang/{irj_parser/src => }/utils/cli.ml (100%) rename src/mlang/{irj_parser/src => }/utils/cli.mli (100%) rename src/mlang/{irj_parser/src => }/utils/errors.ml (100%) rename src/mlang/{irj_parser/src => }/utils/errors.mli (100%) rename src/mlang/{irj_parser/src => }/utils/pos.ml (100%) rename src/mlang/{irj_parser/src => }/utils/pos.mli (88%) diff --git a/dune-project b/dune-project index 269f44852..6961e3afe 100644 --- a/dune-project +++ b/dune-project @@ -51,3 +51,17 @@ (= 0.19.0)) (parmap (= 1.2.3)))) + +(package + (name irj_parser) + (synopsis "Parser for the IRJ tests") + (description "This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax") + (depends + (ocaml + (and(>= "4.11.2"))) + (dune + (and :build)) + (odoc + (= 1.5.3)) + (ocamlformat + (= 0.19.0)))) diff --git a/src/mlang/irj_parser/irj_parser.opam b/irj_parser.opam similarity index 60% rename from src/mlang/irj_parser/irj_parser.opam rename to irj_parser.opam index a2707b377..1ca3bb977 100644 --- a/src/mlang/irj_parser/irj_parser.opam +++ b/irj_parser.opam @@ -1,22 +1,18 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" +version: "1.1.0" synopsis: "Parser for the IRJ tests" description: "This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax" -maintainer: ["Mathieu Durero" " Noé Ensarguet"] -authors: ["Mathieu Durero" "Raphaël Monat"] +maintainer: ["denis.merigoux@inria.fr"] +authors: ["Denis Merigoux" "Raphaël Monat"] license: "GPL-3.0-or-later" -homepage: "https://github.com/MLanguage/mlang/tree/IRJ-parser-library" -bug-reports: "https://github.com/MLanguage/mlang/issues" +homepage: "https://gitlab.inria.fr/verifisc/mlang" +bug-reports: "https://gitlab.inria.fr/verifisc/mlang/issues" depends: [ "ocaml" {>= "4.11.2"} "dune" {build} - "ANSITerminal" {= "0.8.2"} - "cmdliner" {= "1.1.0"} - "re" {= "1.9.0"} - "ocamlgraph" {= "1.8.8"} "odoc" {= "1.5.3"} - "dune-build-info" {= "2.5.1"} "ocamlformat" {= "0.19.0"} ] build: [ @@ -33,3 +29,4 @@ build: [ "@doc" {with-doc} ] ] +dev-repo: "git+https://gitlab.inria.fr/verifisc/mlang.git" diff --git a/src/mlang/irj_parser/dune b/src/irj_parser/dune similarity index 100% rename from src/mlang/irj_parser/dune rename to src/irj_parser/dune diff --git a/src/mlang/irj_parser/main.ml b/src/irj_parser/main.ml similarity index 100% rename from src/mlang/irj_parser/main.ml rename to src/irj_parser/main.ml diff --git a/src/mlang/irj_parser/src/dune b/src/irj_parser/src/dune similarity index 52% rename from src/mlang/irj_parser/src/dune rename to src/irj_parser/src/dune index 21f2f64e1..694ab371f 100644 --- a/src/mlang/irj_parser/src/dune +++ b/src/irj_parser/src/dune @@ -3,20 +3,13 @@ (ocamlopt_flags (-O3 -ccopt -static)))) -(include_subdirs unqualified) - (library (name irj_file) (public_name irj_parser) - (wrapped false) - (libraries ANSITerminal re dune-build-info threads cmdliner)) + (wrapped false)) (ocamllex irj_lexer) (menhir (modules irj_parser) (flags --strict --explain)) - -;(documentation -; (package irj_parser) -; (mld_files ("index"))) diff --git a/src/mlang/irj_parser/src/irj_ast.ml b/src/irj_parser/src/irj_ast.ml similarity index 83% rename from src/mlang/irj_parser/src/irj_ast.ml rename to src/irj_parser/src/irj_ast.ml index 9466f8001..6e40e57b7 100644 --- a/src/mlang/irj_parser/src/irj_ast.ml +++ b/src/irj_parser/src/irj_ast.ml @@ -14,13 +14,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *) +type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position } + +let mk_position sloc = + { pos_filename = (fst sloc).Lexing.pos_fname; pos_loc = sloc } + +exception + StructuredError of (string * (string option * t) list * (unit -> unit) option) +(* duplication of some of the utils *) + type literal = I of int | F of float -type var_value = string * literal * Pos.t +type var_value = string * literal * t (* type var_values = var_value list *) -type calc_error = string * Pos.t +type calc_error = string * t (* type calc_errors = calc_error list *) @@ -40,7 +49,7 @@ type rappel = { (* MMYYYY *) decl_2042_rect : int option; (* 0 or 1 *) - pos : Pos.t; + pos : t; } type prim_data_block = { diff --git a/src/mlang/irj_parser/src/irj_file.ml b/src/irj_parser/src/irj_file.ml similarity index 83% rename from src/mlang/irj_parser/src/irj_file.ml rename to src/irj_parser/src/irj_file.ml index f82e495d6..9b661929c 100644 --- a/src/mlang/irj_parser/src/irj_file.ml +++ b/src/irj_parser/src/irj_file.ml @@ -27,13 +27,16 @@ let parse_file (test_name : string) : irj_file = in let f = try Irj_parser.irj_file Irj_lexer.token filebuf with - | Errors.StructuredError e -> + | StructuredError e -> close_in input; - raise (Errors.StructuredError e) + raise (StructuredError e) | Irj_parser.Error -> close_in input; - Errors.raise_spanned_error "Test syntax error" - (Parse_utils.mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) + raise + (StructuredError + ( "Test syntax error", + [ (None, mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) ], + None )) in close_in input; f diff --git a/src/mlang/irj_parser/src/irj_file.mli b/src/irj_parser/src/irj_file.mli similarity index 100% rename from src/mlang/irj_parser/src/irj_file.mli rename to src/irj_parser/src/irj_file.mli diff --git a/src/mlang/irj_parser/src/irj_lexer.mll b/src/irj_parser/src/irj_lexer.mll similarity index 93% rename from src/mlang/irj_parser/src/irj_lexer.mll rename to src/irj_parser/src/irj_lexer.mll index 82b925bb1..39f8ad6d8 100644 --- a/src/mlang/irj_parser/src/irj_lexer.mll +++ b/src/irj_parser/src/irj_lexer.mll @@ -17,6 +17,12 @@ { open Lexing open Irj_parser +open Irj_ast + +let error lb msg = + raise (StructuredError ("Lexing error : " ^ msg, + [ (None, mk_position (Lexing.lexeme_start_p lb, Lexing.lexeme_end_p lb)) ], + None)) module StrMap = Map.Make (String) @@ -40,11 +46,6 @@ let keywords = "#AVIS_CSG", AVISCSG; ] -let error lb msg = - Errors.raise_spanned_error ("Lexing error : " ^ msg) - (Parse_utils.mk_position (Lexing.lexeme_start_p lb, - Lexing.lexeme_end_p lb)) - let is_bol lb = (* bol = beginning of line *) lb.lex_start_p.pos_cnum - lb.lex_start_p.pos_bol = 0 diff --git a/src/mlang/irj_parser/src/irj_parser.mly b/src/irj_parser/src/irj_parser.mly similarity index 93% rename from src/mlang/irj_parser/src/irj_parser.mly rename to src/irj_parser/src/irj_parser.mly index 407650931..fb9f6b78c 100644 --- a/src/mlang/irj_parser/src/irj_parser.mly +++ b/src/irj_parser/src/irj_parser.mly @@ -16,10 +16,9 @@ this program. If not, see . *) %{ open Irj_ast - + let error (sp, ep) msg = - Errors.raise_spanned_error ("Parse error : " ^ msg) - (Parse_utils.mk_position (sp, ep)) + raise (StructuredError ("Parse error : " ^ msg, [ (None, mk_position (sp, ep)) ], None)) %} @@ -98,11 +97,11 @@ rappels: | ENTREESCORR NL CONTROLESCORR NL RESULTATSCORR NL DATES? AVISIR? AVISCSG? { None } variable_and_value: -| var = SYMBOL SLASH value = value NL { (var, value, Parse_utils.mk_position $sloc) } +| var = SYMBOL SLASH value = value NL { (var, value, mk_position $sloc) } | SYMBOL error { error $loc "Missing slash in pair variable/value" } calc_error: - error = SYMBOL NL { (error, Parse_utils.mk_position $sloc) } + error = SYMBOL NL { (error, mk_position $sloc) } rappel: event_nb = integer SLASH @@ -129,7 +128,7 @@ rappel: base_tolerance_legale; month_year; decl_2042_rect; - pos = Parse_utils.mk_position $sloc } + pos = mk_position $sloc } } integer: diff --git a/src/mlang/irj_parser/dune-project b/src/mlang/irj_parser/dune-project deleted file mode 100644 index 9d75c62f9..000000000 --- a/src/mlang/irj_parser/dune-project +++ /dev/null @@ -1,46 +0,0 @@ -(lang dune 2.5) - -(name irj_parser) - -(generate_opam_files true) - -(homepage https://github.com/MLanguage/mlang/tree/IRJ-parser-library) - -(bug_reports https://github.com/MLanguage/mlang/issues) - -(authors "Mathieu Durero" "Rapha\195\171l Monat") - -(maintainers "Mathieu Durero" " Noé Ensarguet") - -(license GPL-3.0-or-later) - -;(documentation https://url/to/documentation) - -(using menhir 2.0) - -(package - (name irj_parser) - (synopsis "Parser for the IRJ tests") - (description "This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax") - (depends - (ocaml - (and(>= "4.11.2"))) - (dune - (and :build)) - (ANSITerminal - (= 0.8.2)) - (cmdliner - (= 1.1.0)) - (re - (= 1.9.0)) - (ocamlgraph - (= 1.8.8)) - (odoc - (= 1.5.3)) - (dune-build-info - (= 2.5.1)) - (ocamlformat - (= 0.19.0)) - )) - -; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/src/mlang/irj_parser/src/m_frontend/mast.ml b/src/mlang/m_frontend/mast.ml similarity index 100% rename from src/mlang/irj_parser/src/m_frontend/mast.ml rename to src/mlang/m_frontend/mast.ml diff --git a/src/mlang/irj_parser/src/m_frontend/parse_utils.ml b/src/mlang/m_frontend/parse_utils.ml similarity index 100% rename from src/mlang/irj_parser/src/m_frontend/parse_utils.ml rename to src/mlang/m_frontend/parse_utils.ml diff --git a/src/mlang/irj_parser/src/m_frontend/parse_utils.mli b/src/mlang/m_frontend/parse_utils.mli similarity index 100% rename from src/mlang/irj_parser/src/m_frontend/parse_utils.mli rename to src/mlang/m_frontend/parse_utils.mli diff --git a/src/mlang/test_framework/test_interpreter.ml b/src/mlang/test_framework/test_interpreter.ml index 66608e676..75f360143 100644 --- a/src/mlang/test_framework/test_interpreter.ml +++ b/src/mlang/test_framework/test_interpreter.ml @@ -15,6 +15,12 @@ open Irj_ast +let convert_pos (sloc : Irj_ast.t) : Pos.t = + { pos_filename = sloc.pos_filename; pos_loc = sloc.pos_loc } + +(* enforces type compatibility (the type t is defined in exactly the same way in + Irj_ast and in Pos) *) + let to_ast_literal (value : Irj_ast.literal) : Mast.literal = match value with I i -> Float (float_of_int i) | F f -> Float f @@ -43,7 +49,7 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file) List.fold_left (fun (fv, in_f) (var, value, pos) -> let var = - find_var_of_name program.mir_program (var, pos) + find_var_of_name program.mir_program (var, convert_pos pos) |> Bir.(var_from_mir default_tgv) in let lit = @@ -65,34 +71,35 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file) two using the line below*) let var = Pos.unmark - (find_var_of_name program.mir_program (var, pos)) + (find_var_of_name program.mir_program (var, convert_pos pos)) .Mir.Variable.name in (* we allow a difference of 0.000001 between the control value and the result *) let first_exp = ( Mast.Comparison - ( (Lte, pos), + ( (Lte, convert_pos pos), ( Mast.Binop - ( (Mast.Sub, pos), - (Literal (Variable (Normal var)), pos), - (Literal (to_ast_literal value), pos) ), - pos ), - (Literal (Float test_error_margin), pos) ), - pos ) + ( (Mast.Sub, convert_pos pos), + (Literal (Variable (Normal var)), convert_pos pos), + (Literal (to_ast_literal value), convert_pos pos) ), + convert_pos pos ), + (Literal (Float test_error_margin), convert_pos pos) ), + convert_pos pos ) in let second_exp = ( Mast.Comparison - ( (Lte, pos), + ( (Lte, convert_pos pos), ( Mast.Binop - ( (Mast.Sub, pos), - (Literal (to_ast_literal value), pos), - (Literal (Variable (Normal var)), pos) ), - pos ), - (Literal (Float test_error_margin), pos) ), - pos ) + ( (Mast.Sub, convert_pos pos), + (Literal (to_ast_literal value), convert_pos pos), + (Literal (Variable (Normal var)), convert_pos pos) ), + convert_pos pos ), + (Literal (Float test_error_margin), convert_pos pos) ), + convert_pos pos ) in - (Mast.Binop ((Mast.And, pos), first_exp, second_exp), pos)) + ( Mast.Binop ((Mast.And, convert_pos pos), first_exp, second_exp), + convert_pos pos )) t.prim.resultats_attendus) in ( { func_variable_inputs; func_constant_inputs; func_outputs; func_conds }, diff --git a/src/mlang/irj_parser/src/utils/cli.ml b/src/mlang/utils/cli.ml similarity index 100% rename from src/mlang/irj_parser/src/utils/cli.ml rename to src/mlang/utils/cli.ml diff --git a/src/mlang/irj_parser/src/utils/cli.mli b/src/mlang/utils/cli.mli similarity index 100% rename from src/mlang/irj_parser/src/utils/cli.mli rename to src/mlang/utils/cli.mli diff --git a/src/mlang/irj_parser/src/utils/errors.ml b/src/mlang/utils/errors.ml similarity index 100% rename from src/mlang/irj_parser/src/utils/errors.ml rename to src/mlang/utils/errors.ml diff --git a/src/mlang/irj_parser/src/utils/errors.mli b/src/mlang/utils/errors.mli similarity index 100% rename from src/mlang/irj_parser/src/utils/errors.mli rename to src/mlang/utils/errors.mli diff --git a/src/mlang/irj_parser/src/utils/pos.ml b/src/mlang/utils/pos.ml similarity index 100% rename from src/mlang/irj_parser/src/utils/pos.ml rename to src/mlang/utils/pos.ml diff --git a/src/mlang/irj_parser/src/utils/pos.mli b/src/mlang/utils/pos.mli similarity index 88% rename from src/mlang/irj_parser/src/utils/pos.mli rename to src/mlang/utils/pos.mli index 43fed6881..1d2a77fd9 100644 --- a/src/mlang/irj_parser/src/utils/pos.mli +++ b/src/mlang/utils/pos.mli @@ -18,7 +18,9 @@ (** {2 Source code position} *) -type t +type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position } +(* opened this type. Not very satisfactory but necessary to enforce the + compatibility of this type t and that of the module Irj_parser *) val make_position : string -> Lexing.position * Lexing.position -> t From 9ca3ac1eca2e4c5a115fbce6eeb54c25010de83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Ensarguet?= Date: Mon, 27 Nov 2023 11:37:24 +0100 Subject: [PATCH 19/19] Minor corrections --- src/irj_parser/dune | 14 +++++++++----- src/irj_parser/{src => }/irj_ast.ml | 14 ++++++++------ src/irj_parser/{src => }/irj_file.ml | 9 ++++----- src/irj_parser/{src => }/irj_file.mli | 0 src/irj_parser/{src => }/irj_lexer.mll | 5 ++--- src/irj_parser/{src => }/irj_parser.mly | 3 +-- src/irj_parser/main.ml | 0 src/irj_parser/src/dune | 15 --------------- src/mlang/test_framework/test_interpreter.ml | 16 +++++++++------- src/mlang/utils/pos.mli | 4 +--- 10 files changed, 34 insertions(+), 46 deletions(-) rename src/irj_parser/{src => }/irj_ast.ml (88%) rename src/irj_parser/{src => }/irj_file.ml (86%) rename src/irj_parser/{src => }/irj_file.mli (100%) rename src/irj_parser/{src => }/irj_lexer.mll (94%) rename src/irj_parser/{src => }/irj_parser.mly (97%) delete mode 100644 src/irj_parser/main.ml delete mode 100644 src/irj_parser/src/dune diff --git a/src/irj_parser/dune b/src/irj_parser/dune index 4dfcbc39f..c899620eb 100644 --- a/src/irj_parser/dune +++ b/src/irj_parser/dune @@ -3,8 +3,12 @@ (ocamlopt_flags (-O3 -ccopt -static)))) -(executable - (name main) - (package irj_parser) - (public_name irj_parser.exe) - (libraries irj_parser)) +(library + (name irj_include) + (public_name irj_parser)) + +(ocamllex irj_lexer) + +(menhir + (modules irj_parser) + (flags --strict --explain)) diff --git a/src/irj_parser/src/irj_ast.ml b/src/irj_parser/irj_ast.ml similarity index 88% rename from src/irj_parser/src/irj_ast.ml rename to src/irj_parser/irj_ast.ml index 6e40e57b7..1e03092b5 100644 --- a/src/irj_parser/src/irj_ast.ml +++ b/src/irj_parser/irj_ast.ml @@ -14,22 +14,24 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *) -type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position } +type pos = { + pos_filename : string; + pos_loc : Lexing.position * Lexing.position; +} let mk_position sloc = { pos_filename = (fst sloc).Lexing.pos_fname; pos_loc = sloc } -exception - StructuredError of (string * (string option * t) list * (unit -> unit) option) +exception TestParsingError of (string * pos) (* duplication of some of the utils *) type literal = I of int | F of float -type var_value = string * literal * t +type var_value = string * literal * pos (* type var_values = var_value list *) -type calc_error = string * t +type calc_error = string * pos (* type calc_errors = calc_error list *) @@ -49,7 +51,7 @@ type rappel = { (* MMYYYY *) decl_2042_rect : int option; (* 0 or 1 *) - pos : t; + pos : pos; } type prim_data_block = { diff --git a/src/irj_parser/src/irj_file.ml b/src/irj_parser/irj_file.ml similarity index 86% rename from src/irj_parser/src/irj_file.ml rename to src/irj_parser/irj_file.ml index 9b661929c..edc84f425 100644 --- a/src/irj_parser/src/irj_file.ml +++ b/src/irj_parser/irj_file.ml @@ -27,16 +27,15 @@ let parse_file (test_name : string) : irj_file = in let f = try Irj_parser.irj_file Irj_lexer.token filebuf with - | StructuredError e -> + | TestParsingError e -> close_in input; - raise (StructuredError e) + raise (TestParsingError e) | Irj_parser.Error -> close_in input; raise - (StructuredError + (TestParsingError ( "Test syntax error", - [ (None, mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) ], - None )) + mk_position (filebuf.lex_start_p, filebuf.lex_curr_p) )) in close_in input; f diff --git a/src/irj_parser/src/irj_file.mli b/src/irj_parser/irj_file.mli similarity index 100% rename from src/irj_parser/src/irj_file.mli rename to src/irj_parser/irj_file.mli diff --git a/src/irj_parser/src/irj_lexer.mll b/src/irj_parser/irj_lexer.mll similarity index 94% rename from src/irj_parser/src/irj_lexer.mll rename to src/irj_parser/irj_lexer.mll index 39f8ad6d8..200a38c04 100644 --- a/src/irj_parser/src/irj_lexer.mll +++ b/src/irj_parser/irj_lexer.mll @@ -20,9 +20,8 @@ open Irj_parser open Irj_ast let error lb msg = - raise (StructuredError ("Lexing error : " ^ msg, - [ (None, mk_position (Lexing.lexeme_start_p lb, Lexing.lexeme_end_p lb)) ], - None)) + raise (TestParsingError ("Lexing error : " ^ msg, + mk_position (Lexing.lexeme_start_p lb, Lexing.lexeme_end_p lb))) module StrMap = Map.Make (String) diff --git a/src/irj_parser/src/irj_parser.mly b/src/irj_parser/irj_parser.mly similarity index 97% rename from src/irj_parser/src/irj_parser.mly rename to src/irj_parser/irj_parser.mly index fb9f6b78c..88675a680 100644 --- a/src/irj_parser/src/irj_parser.mly +++ b/src/irj_parser/irj_parser.mly @@ -18,8 +18,7 @@ %{ open Irj_ast let error (sp, ep) msg = - raise (StructuredError ("Parse error : " ^ msg, [ (None, mk_position (sp, ep)) ], None)) - + raise (TestParsingError ("Parse error : " ^ msg, mk_position (sp, ep))) %} %token SYMBOL NAME diff --git a/src/irj_parser/main.ml b/src/irj_parser/main.ml deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/irj_parser/src/dune b/src/irj_parser/src/dune deleted file mode 100644 index 694ab371f..000000000 --- a/src/irj_parser/src/dune +++ /dev/null @@ -1,15 +0,0 @@ -(env - (static - (ocamlopt_flags - (-O3 -ccopt -static)))) - -(library - (name irj_file) - (public_name irj_parser) - (wrapped false)) - -(ocamllex irj_lexer) - -(menhir - (modules irj_parser) - (flags --strict --explain)) diff --git a/src/mlang/test_framework/test_interpreter.ml b/src/mlang/test_framework/test_interpreter.ml index 75f360143..f262ce1b5 100644 --- a/src/mlang/test_framework/test_interpreter.ml +++ b/src/mlang/test_framework/test_interpreter.ml @@ -13,13 +13,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *) -open Irj_ast +open Irj_include -let convert_pos (sloc : Irj_ast.t) : Pos.t = - { pos_filename = sloc.pos_filename; pos_loc = sloc.pos_loc } +let convert_pos (pos : Irj_ast.pos) = + Pos.make_position pos.pos_filename pos.pos_loc -(* enforces type compatibility (the type t is defined in exactly the same way in - Irj_ast and in Pos) *) +(* enforces type compatibility (the type Irj_ast.pos is defined in exactly the + same way as Pos.t) *) let to_ast_literal (value : Irj_ast.literal) : Mast.literal = match value with I i -> Float (float_of_int i) | F f -> Float f @@ -42,7 +42,7 @@ let find_var_of_name (p : Mir.program) (name : string Pos.marked) : v2.Mir.Variable.execution_number) (Pos.VarNameToID.find name p.program_idmap)) -let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file) +let to_MIR_function_and_inputs (program : Bir.program) (t : Irj_ast.irj_file) (test_error_margin : float) : Bir_interface.bir_function * Mir.literal Bir.VariableMap.t = let func_variable_inputs, input_file = @@ -53,7 +53,9 @@ let to_MIR_function_and_inputs (program : Bir.program) (t : irj_file) |> Bir.(var_from_mir default_tgv) in let lit = - match value with I i -> Mir.Float (float_of_int i) | F f -> Float f + match value with + | Irj_ast.I i -> Mir.Float (float_of_int i) + | F f -> Float f in (Bir.VariableMap.add var () fv, Bir.VariableMap.add var lit in_f)) (Bir.VariableMap.empty, Bir.VariableMap.empty) diff --git a/src/mlang/utils/pos.mli b/src/mlang/utils/pos.mli index 1d2a77fd9..43fed6881 100644 --- a/src/mlang/utils/pos.mli +++ b/src/mlang/utils/pos.mli @@ -18,9 +18,7 @@ (** {2 Source code position} *) -type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position } -(* opened this type. Not very satisfactory but necessary to enforce the - compatibility of this type t and that of the module Irj_parser *) +type t val make_position : string -> Lexing.position * Lexing.position -> t