Commit 86783e13 authored by Juergen Reuter's avatar Juergen Reuter
Browse files

35783cd Merge branch 'tho/working' into 'master'

parent 734852d3
......@@ -70,8 +70,16 @@ let parse_string text =
| Parsing.Parse_error ->
invalid_arg ("parse error: " ^ text)
exception File_missing of string
let parse_file name =
let ic = open_in name in
let ic =
try open_in name with
| Sys_error msg as exc ->
if msg = name ^ ": No such file or directory" then
raise (File_missing name)
else
raise exc in
let result =
begin
try
......@@ -137,16 +145,18 @@ module Files : Files =
decays : UFO_syntax.t }
let parse_directory dir =
let parse stem = parse_file (Filename.concat dir (stem ^ ".py")) in
let filename stem = Filename.concat dir (stem ^ ".py") in
let parse stem = parse_file (filename stem) in
let parse_optional stem =
try parse stem with File_missing _ -> [] in
{ particles = parse "particles";
couplings = parse "couplings";
coupling_orders = (try parse "coupling_orders" with _ -> []);
coupling_orders = parse_optional "coupling_orders";
vertices = parse "vertices";
lorentz = parse "lorentz";
parameters = parse "parameters";
propagators = parse "propagators";
(* [(try parse "propagators" with _ -> []);] *)
decays = (try parse "decays" with _ -> []) }
propagators = parse_optional "propagators";
decays = parse_optional "decays" }
end
......
......@@ -971,6 +971,11 @@ module Tagged (Tagger : Tagger) (PT : Tuple.Poly)
(* \begin{dubious}
This is \emph{very} inefficient for [max_degree > 6]. Find a better
approach that avoids precomputing the huge lookup table!
\end{dubious}
\begin{dubious}
I should revive the above Idea to use [M.vertices] instead directly,
instead of rebuilding it from [M.fuse2],
[M.fuse3] and [M.fuse]!
\end{dubious} *)
let vertices_nocache max_degree flavors : vertices =
......
......@@ -136,6 +136,16 @@ let valid_fortran_id s =
false in
valid_fortran_id' (pred (String.length s))
let sanitize_fortran_id s =
let sanitize s =
String.map (fun c -> if is_alphanum c then c else '_') s in
if String.length s <= 0 then
invalid_arg "ThoString.sanitize_fortran_id: empty"
else if is_alpha s.[0] then
sanitize s
else
"N_" ^ sanitize s
module Test =
struct
......@@ -169,8 +179,32 @@ module Test =
"A_xyz_0_" >::
(fun () -> assert_equal true (valid_fortran_id "A_xyz_0_"))
let sanitize_digit =
"0" >::
(fun () -> assert_equal "N_0" (sanitize_fortran_id "0"))
let sanitize_digit_alpha =
"0abc" >::
(fun () -> assert_equal "N_0abc" (sanitize_fortran_id "0abc"))
let sanitize_underscore =
"_" >::
(fun () -> assert_equal "N__" (sanitize_fortran_id "_"))
let sanitize_underscore_alpha =
"_ABC" >::
(fun () -> assert_equal "N__ABC" (sanitize_fortran_id "_ABC"))
let sanitize_questionmark =
"A?C" >::
(fun () -> assert_equal "A_C" (sanitize_fortran_id "A?C"))
let sanitize_valid =
"A_xyz_0_" >::
(fun () -> assert_equal "A_xyz_0_" (sanitize_fortran_id "A_xyz_0_"))
let suite_fortran =
"compare" >:::
"valid_fortran_id" >:::
[fortran_empty;
fortran_digit;
fortran_digit_alpha;
......@@ -179,9 +213,19 @@ module Test =
fortran_questionmark;
fortran_valid]
let suite_sanitize =
"sanitize_fortran_id" >:::
[sanitize_digit;
sanitize_digit_alpha;
sanitize_underscore;
sanitize_underscore_alpha;
sanitize_questionmark;
sanitize_valid]
let suite =
"ThoString" >:::
[suite_fortran]
[suite_fortran;
suite_sanitize]
end
......@@ -63,5 +63,9 @@ val compare_caseless : string -> string -> int
\texttt{\lbrack A-Za-z\rbrack\lbrack A-Za-z0-9\_\rbrack*} *)
val valid_fortran_id : string -> bool
(* Replace any invalid character by ['_'] and prepend ["N_"] iff
the string doesn't start with a letter. *)
val sanitize_fortran_id : string -> string
module Test : sig val suite : OUnit.test end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment