X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fmatita%2Frottener.ml;h=3674d25ebac94177cc329f39f92db287e8a45f20;hb=488f49d2ac60fa63e65a19ad8684414266e05ac6;hp=9888e11e7ddf4ac4137c09e93e76e3d543cb366c;hpb=ca351b377ef8cb69ef712df0050620f75d4b649a;p=helm.git diff --git a/helm/software/matita/rottener.ml b/helm/software/matita/rottener.ml index 9888e11e7..3674d25eb 100644 --- a/helm/software/matita/rottener.ml +++ b/helm/software/matita/rottener.ml @@ -59,22 +59,32 @@ let rotten_script ~fname statement = lexer.Token.tok_func (Obj.magic (Ulexing.from_utf8_string statement)) in let tokens = flush_token_stream (token_stream, loc_func) in let target_token, target_pos = - let rec sanitize_tokens = function - | [] -> [] + let rec sanitize_tokens acc = function + | [] -> List.rev acc | (("IDENT", ("theorem" | "definition" | "lemma" | "record" | "inductive")), _) - :: (("IDENT", _), _) :: tl + :: (("IDENT", _), _) :: tl -> + (* avoid rottening of object names *) + sanitize_tokens acc tl | (("SYMBOL", ("∀" | "λ" | "Π")), _) :: (("IDENT", _), _) :: tl -> + (* avoid rottening of binders *) let rec remove_args = function | (("SYMBOL", ","), _) :: (("IDENT", _), _) :: tl -> remove_args tl | tl -> tl in - let tl' = remove_args tl in - sanitize_tokens tl' - | hd :: tl -> hd :: sanitize_tokens tl in + sanitize_tokens acc (remove_args tl) + | (("SYMBOL", "⇒"), _) as hd :: tl -> + (* avoid rottening of constructor names in pattern matching *) + let rec remove_until_branch_start = function + | (("SYMBOL", ("|" | "[")), _) :: tl -> tl + | hd :: tl -> remove_until_branch_start tl + | [] -> [] in + sanitize_tokens (hd :: remove_until_branch_start acc) tl + | hd :: tl -> (* every other identfier can be rottened! *) + sanitize_tokens (hd :: acc) tl in let idents = List.filter (function (("IDENT", _), _) -> true | _ -> false) - (sanitize_tokens tokens) in + (sanitize_tokens [] tokens) in List.nth idents (Random.int (List.length idents)) in let start_pos, end_pos = @@ -101,7 +111,7 @@ let rotten_script ~fname statement = let script' = sprintf "%s%s%s%s" matches.(1) statement' matches.(3) trailer in let md5 = Digest.to_hex (Digest.string script') in HExtlib.output_file - ~filename:(sprintf "%s.rottened.%s.ma" (Filename.chop_extension fname) md5) + ~filename:(sprintf "%s.%s.rottened" fname md5) ~text:script' let grep () =