-
Notifications
You must be signed in to change notification settings - Fork 9
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
IRJ files parser as an Mlang sublibrary #222
Changes from 1 commit
6b00947
68ea878
3d3aec5
e633129
1874466
7d7c8ab
9938401
6cb06e1
fc3ce45
9d59616
c8896bf
cc5f4d6
debeadf
d78259f
4114440
e492f35
900d4c7
906230c
9ca3ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: ["[email protected]"] | ||
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" |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there this empty file here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought we might want an executable at first and didn't delete it afterwards ^^' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,13 @@ | |
(ocamlopt_flags | ||
(-O3 -ccopt -static)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
||
(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"))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,22 @@ | |
You should have received a copy of the GNU General Public License along with | ||
this program. If not, see <https://www.gnu.org/licenses/>. *) | ||
|
||
type t = { pos_filename : string; pos_loc : Lexing.position * Lexing.position } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That type should not be named |
||
|
||
let mk_position sloc = | ||
{ pos_filename = (fst sloc).Lexing.pos_fname; pos_loc = sloc } | ||
|
||
exception | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to duplicate the full type here as you won't use all its components in exception TestParsingError of string * pos |
||
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 = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you can catch |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here raise a |
||
( "Test syntax error", | ||
[ (None, mk_position (filebuf.lex_start_p, filebuf.lex_curr_p)) ], | ||
None )) | ||
in | ||
close_in input; | ||
f |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,9 @@ | |
this program. If not, see <https://www.gnu.org/licenses/>. *) | ||
|
||
%{ 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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you can raise a |
||
|
||
%} | ||
|
||
|
@@ -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: | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ | |
|
||
open Irj_ast | ||
|
||
let convert_pos (sloc : Irj_ast.t) : Pos.t = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes perfect! |
||
{ 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 }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of opening the type you can just use the |
||
compatibility of this type t and that of the module Irj_parser *) | ||
|
||
val make_position : string -> Lexing.position * Lexing.position -> t | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha ha why did you remove yourself and Mathieu and put me as the maintainer ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahaha
I had a separate dune-project for irj_parser in the first commit, until I realised (thanks to @Keryan-dev) that you could declare both packages in the same dune-project file (and so with the same maintainers etc.)