src/HOL/Tools/ATP/recon_parse.ML
changeset 17306 5cde710a8a23
parent 16953 f025e0dc638b
child 17312 159783c74f75
equal deleted inserted replaced
17305:6cef3aedd661 17306:5cde710a8a23
    23 
    23 
    24 
    24 
    25 (* Parser combinators *)
    25 (* Parser combinators *)
    26 
    26 
    27 exception Noparse;
    27 exception Noparse;
    28 exception SPASSError of string;
       
    29 exception VampError of string;
    28 exception VampError of string;
    30 
    29 
    31 
    30 
    32 fun (parser1 ++ parser2) input =
    31 fun (parser1 ++ parser2) input =
    33       let
    32       let
   116            o fst o cut_after "contradiction.\n") s
   115            o fst o cut_after "contradiction.\n") s
   117         else
   116         else
   118           raise (GandalfError "Couldn't find a proof.")
   117           raise (GandalfError "Couldn't find a proof.")
   119 *)
   118 *)
   120 
   119 
   121 val proofstring =
   120 (*Identifies the start/end lines of an ATP's output*)
   122 "0:00:00.00 for the reduction.\
   121 fun extract_proof s =
   123 \\
   122   if cut_exists "Here is a proof with" s then
   124 \Here is a proof with depth 3, length 7 :\
   123     (kill_lines 0
   125 \1[0:Inp] ||  -> P(xa)*.\
   124      o snd o cut_after ":"
   126 \2[0:Inp] ||  -> Q(xb)*.\
   125      o snd o cut_after "Here is a proof with"
   127 \3[0:Inp] || R(U)* -> .\
   126      o fst o cut_after " ||  -> .") s
   128 \4[0:Inp] || Q(U) P(V) -> R(x(V,U))*.\
   127   else if cut_exists "%================== Proof: ======================" s then
   129 \9[0:Res:4.2,3.0] || Q(U)*+ P(V)* -> .\
   128     (kill_lines 0    (*Vampire 5.0*)
   130 \11[0:Res:2.0,9.0] || P(U)* -> .\
   129      o snd o cut_after "%================== Proof: ======================"
   131 \12[0:Res:1.0,11.0] ||  -> .\
   130      o fst o cut_before "==============  End of proof. ==================") s
   132 \Formulae used in the proof :\
   131   else if cut_exists "# Proof object ends here." s then
   133 \\
   132     (kill_lines 0    (*eproof*)
   134 \--------------------------SPASS-STOP------------------------------"
   133      o snd o cut_after "# Proof object starts here."
   135 
   134      o fst o cut_before "# Proof object ends here.") s
   136 fun extract_proof s
   135   else "??extract_proof failed" (*Couldn't find a proof*)
   137       = if cut_exists "Here is a proof with" s then
       
   138           (kill_lines 0
       
   139            o snd o cut_after ":"
       
   140            o snd o cut_after "Here is a proof with"
       
   141            o fst o cut_after " ||  -> .") s
       
   142         else if cut_exists "%================== Proof: ======================" s then
       
   143           (kill_lines 0
       
   144            o snd o cut_after "%================== Proof: ======================"
       
   145            o fst o cut_before "==============  End of proof. ==================") s
       
   146         else
       
   147           raise SPASSError "Couldn't find a proof."
       
   148 
       
   149 (*fun extract_proof s
       
   150       = if cut_exists "Here is a proof with" s then
       
   151           (kill_lines 0
       
   152            o snd o cut_after ":"
       
   153            o snd o cut_after "Here is a proof with"
       
   154            o fst o cut_after " ||  -> .") s
       
   155         else
       
   156           raise SPASSError "Couldn't find a proof."
       
   157 *)
       
   158 
       
   159 
       
   160 
       
   161 
       
   162 
   136 
   163 fun several p = many (some p)
   137 fun several p = many (some p)
   164       fun collect (h, t) = h ^ (fold_rev (fn s1 => fn s2 => s1 ^ s2) t "")
   138       fun collect (h, t) = h ^ (fold_rev (fn s1 => fn s2 => s1 ^ s2) t "")
   165   
   139   
   166       fun lower_letter s = ("a" <= s) andalso (s <= "z")
   140       fun lower_letter s = ("a" <= s) andalso (s <= "z")
   356                  >> (fn (_,(_, (_,(b, _)))) => b)
   330                  >> (fn (_,(_, (_,(b, _)))) => b)
   357 
   331 
   358      
   332      
   359 exception NOTERM
   333 exception NOTERM
   360 
   334 
   361 
       
   362 fun implode_with_space [] = implode []
       
   363 |   implode_with_space [x] = implode [x]
       
   364 |   implode_with_space (x::[y]) = x^" "^y
       
   365 |   implode_with_space (x::xs) =  (x^" "^(implode_with_space xs))
       
   366 
       
   367 (* FIX - should change the stars and pluses to many rather than explicit patterns *)
   335 (* FIX - should change the stars and pluses to many rather than explicit patterns *)
   368 
   336 
   369 fun trim_prefix a b =
   337 fun trim_prefix a b =
   370   let val n = String.size a 
   338   let val n = String.size a 
   371   in  String.substring (b, n, (size b) - n)  end;
   339   in  String.substring (b, n, (size b) - n)  end;
   497 and ntermlist input = (many  nterm
   465 and ntermlist input = (many  nterm
   498                       >> (fn (a) => (a))) input
   466                       >> (fn (a) => (a))) input
   499 
   467 
   500 (*and arglist input = (    nterm >> (fn (a) => (a))
   468 (*and arglist input = (    nterm >> (fn (a) => (a))
   501                      ||  nterm ++ many (a (Other ",") ++ nterm >> snd)
   469                      ||  nterm ++ many (a (Other ",") ++ nterm >> snd)
   502                       >> (fn (a, b) => (a^" "^(implode_with_space b)))) input*)
   470                       >> (fn (a, b) => (a^" "^(space_implode " " b)))) input*)
   503 
   471 
   504 and arglist input = (   nterm ++ many (a (Other ",") ++ nterm >> snd)
   472 and arglist input = (   nterm ++ many (a (Other ",") ++ nterm >> snd)
   505                       >> (fn (a, b) => (a^" "^(implode_with_space b))) 
   473                       >> (fn (a, b) => (a^" "^(space_implode " " b))) 
   506                       ||    nterm >> (fn (a) => (a)))input
   474                       ||    nterm >> (fn (a) => (a)))input
   507 
   475 
   508  val clause =  term
   476  val clause =  term
   509 
       
   510 
       
   511 
       
   512  (*val line = number ++ justification ++ a (Other "|") ++ 
       
   513             a (Other "|") ++ clause ++ a (Other ".")
       
   514           >> (fn (a, (z, (_,( _, (c, _))))) => (a, z, c))*)
       
   515 
       
   516 
   477 
   517 (* not entirely sure nterm is right here, but I don't think you get negative things before the ||s *)
   478 (* not entirely sure nterm is right here, but I don't think you get negative things before the ||s *)
   518  val line = number ++ justification ++ many( nterm) ++ a (Other "|") ++ 
   479  val line = number ++ justification ++ many( nterm) ++ a (Other "|") ++ 
   519             a (Other "|") ++ clause ++ a (Other ".")
   480             a (Other "|") ++ clause ++ a (Other ".")
   520           >> (fn (a, (z, (w, (_,( _, (c, _)))))) => (a, z,(w@ c)))
   481           >> (fn (a, (z, (w, (_,( _, (c, _)))))) => (a, z,(w@ c)))
   521        
   482        
   522 
       
   523 
       
   524  val lines = many line
   483  val lines = many line
   525  val alllines = (lines ++ finished) >> fst
   484  val alllines = (lines ++ finished) >> fst
   526     
   485     
   527  val parse = fst o alllines
   486  val parse = fst o alllines
   528  val s = proofstring;
       
   529  
       
   530  
       
   531 
       
   532 
       
   533 fun dropUntilNot ch []   = ( [])
       
   534  |   dropUntilNot ch (x::xs)  = if  not(x = ch )
       
   535                                 then
       
   536                                      (x::xs)
       
   537                                 else
       
   538                                      dropUntilNot ch xs
       
   539 
       
   540 
       
   541 fun remove_spaces str  []  = str
       
   542 |   remove_spaces str (x::[]) = if x = " " 
       
   543                                 then 
       
   544                                     str 
       
   545                                 else 
       
   546                                     (str^x)
       
   547 |   remove_spaces str (x::xs) = 
       
   548       let val (first, rest) = ReconOrderClauses.takeUntil " " (x::xs) []
       
   549 	  val (next) = dropUntilNot " " rest 
       
   550       in 
       
   551 	  if next = []
       
   552 	  then 
       
   553 	       (str^(implode first)) 
       
   554 	  else remove_spaces  (str^(implode first)^" ") next 
       
   555       end
       
   556 
       
   557 
       
   558 fun remove_space_strs clsstrs = map (remove_spaces "") (map explode clsstrs)
       
   559 
       
   560 
       
   561 fun all_spaces xs = List.filter  (not_equal " " ) xs
       
   562 
       
   563 fun just_change_space []  = []
       
   564 |   just_change_space ((clausenum, step, strs)::xs) =
       
   565       let val newstrs = remove_space_strs strs
       
   566       in
       
   567 	 if (all_spaces newstrs = [] ) (* all type_info *)
       
   568 	 then    
       
   569 	    (clausenum, step, newstrs)::(just_change_space xs)
       
   570 	 else 
       
   571 	     (clausenum, step, newstrs)::(just_change_space xs) 
       
   572       end;
       
   573 
       
   574 fun change_space []  = []
       
   575 |   change_space ((clausenum, step, strs)::xs) = 
       
   576       let val newstrs = remove_space_strs strs
       
   577       in
       
   578 	 if (all_spaces newstrs = [] ) (* all type_info *)
       
   579 	 then    
       
   580 	    (clausenum, step, T_info, newstrs)::(change_space xs)
       
   581 	 else 
       
   582 	     (clausenum, step, P_info, newstrs)::(change_space xs) 
       
   583       end
       
   584 
   487 
   585 end;
   488 end;