Skip to content

Commit

Permalink
Add a small standalone module for IRJ file validation (#236)
Browse files Browse the repository at this point in the history
This module uses the Mlang parser to display lexing and parsing errors associated to a test file at DGFiP IRJ format.
  • Loading branch information
mdurero authored Jun 12, 2024
2 parents 86b9338 + f73925e commit b52dbb5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 24 deletions.
14 changes: 7 additions & 7 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
(generate_opam_files true)

(source
(uri git+https://gitlab.inria.fr/verifisc/mlang.git))
(uri git+https://github.com/MLanguage/mlang.git))

(homepage https://gitlab.inria.fr/verifisc/mlang)
(homepage https://github.com/MLanguage/mlang)

(bug_reports https://gitlab.inria.fr/verifisc/mlang/issues)
(bug_reports https://github.com/MLanguage/mlang/issues)

(authors "Denis Merigoux" "Rapha\195\171l Monat")

Expand Down Expand Up @@ -54,10 +54,10 @@
(= 1.2.3))))

(package
(name irj_parser)
(synopsis "Parser for the IRJ tests")
(name irj_checker)
(synopsis "IRJ test validation tool")
(description
"This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax")
"This standalone module performs a syntactic validation of the DGFiP IRJ test format")
(depends
(ocaml
(and
Expand All @@ -67,4 +67,4 @@
(odoc
(>= 1.5.3))
(ocamlformat
(= 0.19.0))))
(= 0.19.0))))
10 changes: 5 additions & 5 deletions irj_parser.opam → irj_checker.opam
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "1.1.0"
synopsis: "Parser for the IRJ tests"
synopsis: "IRJ test validation tool"
description:
"This parser is aimed for the tests used by la DGFiP to test the calculation of the French income tax"
"This standalone module performs a syntactic validation of the DGFiP IRJ test format"
maintainer: ["[email protected]"]
authors: ["Denis Merigoux" "Raphaël Monat"]
license: "GPL-3.0-or-later"
homepage: "https://gitlab.inria.fr/verifisc/mlang"
bug-reports: "https://gitlab.inria.fr/verifisc/mlang/issues"
homepage: "https://github.com/MLanguage/mlang"
bug-reports: "https://github.com/MLanguage/mlang/issues"
depends: [
"ocaml" {>= "4.11.2"}
"dune" {build}
Expand All @@ -29,4 +29,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://gitlab.inria.fr/verifisc/mlang.git"
dev-repo: "git+https://github.com/MLanguage/mlang.git"
6 changes: 3 additions & 3 deletions mlang.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ before translating it into various backend languages.
maintainer: ["[email protected]"]
authors: ["Denis Merigoux" "Raphaël Monat"]
license: "GPL-3.0-or-later"
homepage: "https://gitlab.inria.fr/verifisc/mlang"
bug-reports: "https://gitlab.inria.fr/verifisc/mlang/issues"
homepage: "https://github.com/MLanguage/mlang"
bug-reports: "https://github.com/MLanguage/mlang/issues"
depends: [
"ocaml" {>= "4.11.2"}
"dune" {build}
Expand Down Expand Up @@ -42,4 +42,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://gitlab.inria.fr/verifisc/mlang.git"
dev-repo: "git+https://github.com/MLanguage/mlang.git"
10 changes: 10 additions & 0 deletions src/irj_checker/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(env
(dev
(flags
(:standard -warn-error -A))))

(executable
(name irj_checker)
(package irj_checker)
(public_name irj_checker)
(libraries mlang))
42 changes: 42 additions & 0 deletions src/irj_checker/irj_checker.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(* Copyright (C) 2023-2024 DGFiP, contributor: David Declerck, Mathieu Durero
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 <https://www.gnu.org/licenses/>. *)

(** The Irj_checker Module is a simple entry point to use the Mlang IRJ file
parser in order to perform syntactic checks on test files.
Usage: irj_checker.exe <test_file.irj>*)

let () =
if Array.length Sys.argv <> 2 then (
Printf.eprintf "This program requires a test file as argument\n";
exit 1);
let f = Sys.argv.(1) in
let _tf =
try Mlang.Irj_file.parse_file f with
| Mlang.Irj_ast.TestParsingError (s, pos) ->
let pos_1, pos_2 = pos.pos_loc in
Printf.eprintf "%s" (Filename.basename f);
Printf.eprintf ":(%d,%d)-(%d,%d)" pos_1.pos_lnum
(pos_1.pos_cnum - pos_1.pos_bol + 1)
pos_2.pos_lnum
(pos_2.pos_cnum - pos_2.pos_bol + 1);
Printf.eprintf " : %s\n" s;
exit 1
| _ ->
Printf.eprintf "%s" (Filename.basename f);
Printf.eprintf " : Unknown error\n";
exit 1
in
()
46 changes: 37 additions & 9 deletions src/mlang/test_framework/irj_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ irj_file:
fip?
prim = primitif
rapp = rappels
endsharp NL
EOF {
endmark {
let nom =
match nom with
| [n] -> n
Expand All @@ -67,6 +66,12 @@ irj_file:
{ nom; prim; rapp } }
| EOF { error $loc "Empty test file" }

endmark:
| endsharp
endline
EOF { () }
| EOF { error $loc "Unexpected end on file, missing ##"}

/* What's the point of this alternative?*/
name:
| n = NAME NL { n }
Expand All @@ -78,19 +83,27 @@ fip:
primitif:
ENTREESPRIM NL
entrees = list(variable_and_value)
CONTROLESPRIM NL
controlesprim NL
controles_attendus = list(calc_error)
RESULTATSPRIM NL
resultatsprim NL
resultats_attendus = list(variable_and_value)
{ { entrees; controles_attendus; resultats_attendus } }

controlesprim:
| CONTROLESPRIM { ( ) }
| error { error $loc "Missing part #CONTROLES-PRIMITIF" }

resultatsprim:
| RESULTATSPRIM { ( ) }
| error { error $loc "Missing part #RESULTATS-PRIMITIF" }

rappels:
/* The two constructions match respectively corrective test files and primary test files */
| ENTREESRAPP NL
| entreesrapp NL
entrees_rappels = list(rappel)
CONTROLESRAPP NL
controles_attendus = list(calc_error)
RESULTATSRAPP NL
resultatsrapp NL
resultats_attendus = list(variable_and_value)
{ Some { entrees_rappels; controles_attendus; resultats_attendus} }
| ENTREESCORR NL
Expand All @@ -102,15 +115,24 @@ rappels:
DATES? AVISIR? AVISCSG?
{ ignore (entrees_rappels, controles_attendus, resultats_attendus) ; None }

entreesrapp:
| ENTREESRAPP { ( ) }
| error { error $loc "Missing part #ENTREES-RAPPELS" }

resultatsrapp:
| RESULTATSRAPP { ( ) }
| error { error $loc "Missing part #RESULTATS-RAPPELS" }

variable_and_value:
| 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, mk_position $sloc) }
| error = SYMBOL NL { (error, mk_position $sloc) }
| variable_and_value { error $loc "Missing a #RESULTATS- header" }

rappel:
event_nb = integer SLASH
| event_nb = integer SLASH
rappel_nb = integer SLASH
variable_code = SYMBOL SLASH
change_value = integer SLASH (* No decimal value was found in existing files *)
Expand All @@ -136,6 +158,8 @@ rappel:
decl_2042_rect;
pos = mk_position $sloc }
}
| calc_error { error $loc "Missing #CONTROLES-RAPPELS header" }
| resultatsrapp { error $loc "Missing #CONTROLES-RAPPELS header" }

integer:
| i = INTEGER { i }
Expand All @@ -148,4 +172,8 @@ value:

endsharp:
| ENDSHARP { () }
| error { error $loc "Missing ## at end of file" }
| error { error $loc "End case mark is not ##" }

endline:
| NL { () }
| error { error $loc "No new line at end of file"}

0 comments on commit b52dbb5

Please sign in to comment.