diff --git a/tools/compiler_version.ml b/tools/compiler_version.ml index f675a20..ee4169b 100644 --- a/tools/compiler_version.ml +++ b/tools/compiler_version.ml @@ -137,11 +137,15 @@ let known_versions = let is_known v = List.mem v known_versions +let is_known_release {major; minor; _} = + List.exists (fun { major = major'; minor = minor'; _ } -> + major = major' && minor = minor') known_versions + let is_development _ = false let make x y z extra_info = let v = mk x y z in - if is_known v then { v with extra_info } else raise Not_found + { v with extra_info } let to_string { major; minor; patch_level; extra_info } = let printer = Printf.sprintf in diff --git a/tools/compiler_version.mli b/tools/compiler_version.mli index c3ab3d6..7c272fd 100644 --- a/tools/compiler_version.mli +++ b/tools/compiler_version.mli @@ -56,6 +56,8 @@ val known_versions : t list val is_known : t -> bool +val is_known_release : t -> bool + val is_development : t -> bool val major : t -> int diff --git a/tools/stdcompatpp.mll b/tools/stdcompatpp.mll index 57914b1..9b49a2b 100644 --- a/tools/stdcompatpp.mll +++ b/tools/stdcompatpp.mll @@ -27,8 +27,8 @@ type options = { debug : bool; } -let init_options () = { - compiler_version = Compiler_version.of_string Sys.ocaml_version; +let init_options compiler_version = { + compiler_version; source_type = OCaml; debug = false; } @@ -40,11 +40,11 @@ let dprintf options fmt = printer stderr fmt let set_compiler_version opts version = - let compiler_version = - try Compiler_version.of_string version with - _ -> unknown "compiler version" version - in - opts := { !opts with compiler_version } + let compiler_version = Compiler_version.of_string version in + if Compiler_version.is_known compiler_version then + opts := { !opts with compiler_version } + else + unknown "compiler version" version let set_source_type opts source_type = let source_type = @@ -339,7 +339,14 @@ and c_lexer options state = parse { let main () = - let options = init_options () |> parse_commandline in + let compiler_version = Compiler_version.of_string Sys.ocaml_version in + let compiler_version = + if Compiler_version.is_known_release compiler_version then + compiler_version + else + List.hd (List.rev Compiler_version.known_versions) + in + let options = init_options compiler_version |> parse_commandline in let lexer = match options.source_type with | OCaml -> ocaml_lexer | C -> c_lexer