src/HOL/Tools/ATP/recon_parse.ML
author haftmann
Tue May 09 10:09:37 2006 +0200 (2006-05-09)
changeset 19599 a5c7eb37d14f
parent 18443 a1d53af4c4c7
permissions -rw-r--r--
added DatatypeHooks
paulson@15789
     1
(*  ID:         $Id$
paulson@15789
     2
    Author:     Claire Quigley
paulson@15789
     3
    Copyright   2004  University of Cambridge
paulson@15789
     4
*)
paulson@15789
     5
quigley@15642
     6
(* Parsing functions *)
quigley@15642
     7
quigley@15642
     8
(* Auxiliary functions *)
quigley@15642
     9
paulson@15684
    10
structure Recon_Parse =
paulson@15684
    11
struct
paulson@15684
    12
paulson@17488
    13
open ReconTranslateProof;
quigley@15642
    14
quigley@15642
    15
exception NOPARSE_WORD
quigley@15642
    16
exception NOPARSE_NUM
quigley@15642
    17
fun to_upper s = String.translate (Char.toString o Char.toUpper) s;
quigley@15642
    18
quigley@15642
    19
fun string2int s =
wenzelm@16804
    20
  (case Int.fromString s of SOME i => i
paulson@17488
    21
  | NONE => error "string -> int failed");
wenzelm@16804
    22
quigley@15642
    23
quigley@15642
    24
(* Parser combinators *)
quigley@15642
    25
quigley@15642
    26
exception Noparse;
quigley@15642
    27
paulson@15688
    28
fun (parser1 ++ parser2) input =
quigley@15642
    29
      let
quigley@15642
    30
        val (result1, rest1) = parser1 input
quigley@15642
    31
        val (result2, rest2) = parser2 rest1
quigley@15642
    32
      in
quigley@15642
    33
        ((result1, result2), rest2)
quigley@15642
    34
      end;
quigley@15642
    35
quigley@15642
    36
fun many parser input =
quigley@15642
    37
      let   (* Tree * token list*)
quigley@15642
    38
        val (result, next) = parser input
quigley@15642
    39
        val (results, rest) = many parser next
quigley@15642
    40
      in
quigley@15642
    41
        ((result::results), rest)
quigley@15642
    42
      end
quigley@15642
    43
      handle Noparse => ([], input)
quigley@15642
    44
|            NOPARSE_WORD => ([], input)
quigley@15642
    45
|            NOPARSE_NUM  => ([], input);
quigley@15642
    46
quigley@15642
    47
quigley@15642
    48
paulson@15688
    49
fun (parser >> treatment) input =
quigley@15642
    50
      let
quigley@15642
    51
        val (result, rest) = parser input
quigley@15642
    52
      in
quigley@15642
    53
        (treatment result, rest)
quigley@15642
    54
      end;
quigley@15642
    55
paulson@15688
    56
fun (parser1 || parser2) input = parser1 input
quigley@15642
    57
handle Noparse => parser2 input;
quigley@15642
    58
quigley@15642
    59
infixr 8 ++; infixr 7 >>; infixr 6 ||;
quigley@15642
    60
quigley@15642
    61
fun some p [] = raise Noparse
quigley@15642
    62
  | some p (h::t) = if p h then (h, t) else raise Noparse;
quigley@15642
    63
quigley@15642
    64
fun a tok = some (fn item => item = tok);
quigley@15642
    65
quigley@15642
    66
fun finished input = if input = [] then (0, input) else raise Noparse;
quigley@15642
    67
quigley@15642
    68
quigley@15642
    69
  (* Parsing the output from gandalf *)
quigley@15642
    70
datatype token = Word of string
quigley@15642
    71
               | Number of int
quigley@15642
    72
               | Other of string
quigley@15642
    73
quigley@15642
    74
quigley@15642
    75
      exception NOCUT
quigley@15642
    76
      fun remove_prefix [] l = l
paulson@17488
    77
        | remove_prefix (h::t) [] = error "can't remove prefix"
quigley@15642
    78
        | remove_prefix (h::t) (h'::t') = remove_prefix t t'
quigley@15642
    79
      fun ccut t [] = raise NOCUT
quigley@15642
    80
        | ccut t s =
haftmann@18443
    81
            if is_prefix (op =) t s then ([], remove_prefix t s) else
quigley@15642
    82
              let val (a, b) = ccut t (tl s) in ((hd s)::a, b) end
quigley@15642
    83
      fun cut t s =
quigley@15642
    84
        let
quigley@15642
    85
          val t' = explode t
quigley@15642
    86
          val s' = explode s
quigley@15642
    87
          val (a, b) = ccut t' s'
quigley@15642
    88
        in
quigley@15642
    89
          (implode a, implode b)
quigley@15642
    90
        end
quigley@15642
    91
    
quigley@15642
    92
      fun cut_exists t s
quigley@15642
    93
          = let val (a, b) = cut t s in true end handle NOCUT => false
quigley@15642
    94
quigley@15642
    95
      fun cut_before t s = let val (a, b) = cut t s in (a, t ^ b) end
quigley@15642
    96
      fun cut_after t s = let val (a, b) = cut t s in (a ^ t, b) end
quigley@15642
    97
    
quigley@15642
    98
paulson@15684
    99
    fun kill_lines 0 = Library.I
quigley@15642
   100
      | kill_lines n = kill_lines (n - 1) o snd o cut_after "\n";
quigley@15642
   101
quigley@16478
   102
quigley@15642
   103
fun several p = many (some p)
wenzelm@16840
   104
      fun collect (h, t) = h ^ (fold_rev (fn s1 => fn s2 => s1 ^ s2) t "")
quigley@15642
   105
  
quigley@15642
   106
      fun lower_letter s = ("a" <= s) andalso (s <= "z")
quigley@15642
   107
      fun upper_letter s = ("A" <= s) andalso (s <= "Z")
quigley@15642
   108
      fun digit s = ("0" <= s) andalso (s <= "9")
quigley@15642
   109
      fun letter s = lower_letter s orelse upper_letter s
quigley@15642
   110
      fun alpha s = letter s orelse (s = "_")
quigley@15642
   111
      fun alphanum s = alpha s orelse digit s
quigley@15642
   112
      fun space s = (s = " ") orelse (s = "\n") orelse (s = "\t")
quigley@15642
   113
      (* FIX this is stopping it picking up numbers *)
quigley@15642
   114
      val word = (some alpha ++ several alphanum) >> (Word o collect)
quigley@15642
   115
      val number =
quigley@15642
   116
            (some digit ++ several digit) >> (Number o string2int o collect)
quigley@15642
   117
      val other = some (K true) >> Other
quigley@15642
   118
      
quigley@15642
   119
      val token = (word || number || other) ++ several space >> fst
quigley@15642
   120
      val tokens = (several space ++ many token) >> snd
quigley@15642
   121
      val alltokens = (tokens ++ finished) >> fst
quigley@15642
   122
    
quigley@15642
   123
     (* val lex = fst ( alltokens ( (map str)  explode))*)
quigley@15642
   124
     fun lex s =  alltokens  (explode s)
quigley@15642
   125
quigley@16478
   126
quigley@16478
   127
(************************************************************)
quigley@16478
   128
quigley@16478
   129
(**************************************************)
quigley@16478
   130
(* Code to parse SPASS proofs                     *)
quigley@16478
   131
(**************************************************)
quigley@16478
   132
quigley@15642
   133
datatype Tree = Leaf of string
quigley@15642
   134
                | Branch of Tree * Tree
quigley@15642
   135
quigley@15642
   136
   
quigley@15642
   137
      fun number ((Number n)::rest) = (n, rest)
quigley@15642
   138
        | number _ = raise NOPARSE_NUM
quigley@15642
   139
      fun word ((Word w)::rest) = (w, rest)
quigley@15642
   140
        | word _ = raise NOPARSE_WORD
quigley@15642
   141
quigley@15642
   142
      fun other_char ( (Other p)::rest) = (p, rest)
quigley@15642
   143
      | other_char _ =raise NOPARSE_WORD
quigley@15642
   144
     
quigley@15642
   145
      val number_list =
quigley@15642
   146
        (number ++ many number)
quigley@15642
   147
        >> (fn (a, b) => (a::b))
quigley@15642
   148
     
quigley@15642
   149
      val term_num =
quigley@15642
   150
        (number ++ (a (Other ".")) ++ number) >> (fn (a, (_, c)) => (a, c))
quigley@15642
   151
quigley@16548
   152
quigley@16548
   153
      val term_num_list = (term_num ++ many (a (Other ",") ++ term_num >> snd)
quigley@16548
   154
			   >> (fn (a, b) => (a::b)))
quigley@16548
   155
quigley@15642
   156
      val axiom = (a (Word "Inp"))
quigley@15642
   157
            >> (fn (_) => Axiom)
quigley@15642
   158
      
quigley@15642
   159
      
quigley@15642
   160
      val binary = (a (Word "Res")) ++ (a (Other ":"))
quigley@15642
   161
                   ++ term_num ++ (a (Other ","))
quigley@15642
   162
                   ++ term_num
quigley@15642
   163
            >> (fn (_, (_, (c, (_, e)))) => Binary (c, e))
quigley@15642
   164
      
quigley@15642
   165
quigley@15642
   166
quigley@15642
   167
      val factor = (a (Word "Fac")) ++ (a (Other ":")) 
quigley@15642
   168
                    ++ term_num ++ (a (Other ",")) 
quigley@15642
   169
                    ++ term_num
quigley@15642
   170
            >> (fn (_, (_, (c, (_, e)))) =>  Factor ((fst c), (snd c),(snd e)))
quigley@15642
   171
     
quigley@15642
   172
      val para  = (a (Word "SPm")) ++ (a (Other ":"))
quigley@15642
   173
                   ++ term_num ++ (a (Other ","))
quigley@15642
   174
                   ++ term_num
quigley@15642
   175
            >> (fn (_, (_, (c, (_, e)))) => Para (c, e))
quigley@15642
   176
      
quigley@16357
   177
      val super_l  = (a (Word "SpL")) ++ (a (Other ":"))
quigley@16357
   178
                   ++ term_num ++ (a (Other ","))
quigley@16357
   179
                   ++ term_num
quigley@16357
   180
            >> (fn (_, (_, (c, (_, e)))) => Super_l (c, e))
quigley@16357
   181
quigley@16357
   182
quigley@16357
   183
      val super_r  = (a (Word "SpR")) ++ (a (Other ":"))
quigley@16357
   184
                   ++ term_num ++ (a (Other ","))
quigley@16357
   185
                   ++ term_num
quigley@16357
   186
            >> (fn (_, (_, (c, (_, e)))) => Super_r (c, e))
quigley@16357
   187
quigley@16357
   188
quigley@16357
   189
      val aed = (a (Word "AED")) ++ (a (Other ":")) ++ term_num
quigley@16357
   190
                 >> (fn (_, (_, c)) => Obvious ((fst c),(snd c)))
quigley@16357
   191
quigley@15642
   192
      val rewrite = (a (Word "Rew")) ++ (a (Other ":")) 
quigley@16548
   193
                    ++ term_num_list
quigley@16548
   194
            >> (fn (_, (_, (c))) =>  Rewrite (c))
quigley@15642
   195
quigley@15642
   196
quigley@15642
   197
      val mrr = (a (Word "MRR")) ++ (a (Other ":"))
quigley@15642
   198
                   ++ term_num ++ (a (Other ","))
quigley@15642
   199
                   ++ term_num
quigley@15642
   200
            >> (fn (_, (_, (c, (_, e)))) => MRR (c, e))
quigley@15642
   201
quigley@16357
   202
      val ssi = (a (Word "SSi")) ++ (a (Other ":"))
quigley@16357
   203
                   ++ term_num ++ (a (Other ","))
quigley@16357
   204
                   ++ term_num
quigley@16357
   205
            >> (fn (_, (_, (c, (_, e)))) => SortSimp (c, e))
quigley@16357
   206
quigley@16357
   207
    val unc = (a (Word "UnC")) ++ (a (Other ":"))
quigley@16357
   208
                   ++ term_num ++ (a (Other ","))
quigley@16357
   209
                   ++ term_num
quigley@16357
   210
            >> (fn (_, (_, (c, (_, e)))) => UnitConf (c, e))
quigley@16357
   211
quigley@16357
   212
quigley@15642
   213
quigley@15642
   214
      val obv = (a (Word "Obv")) ++ (a (Other ":")) ++ term_num
quigley@15642
   215
                 >> (fn (_, (_, c)) => Obvious ((fst c),(snd c)))
quigley@16357
   216
quigley@16357
   217
      val eqres = (a (Word "EqR")) ++ (a (Other ":")) ++ term_num
quigley@16357
   218
                 >> (fn (_, (_, c)) => EqualRes ((fst c),(snd c)))
quigley@16357
   219
   
quigley@16357
   220
      val con = (a (Word "Con")) ++ (a (Other ":")) ++ term_num
quigley@16357
   221
                 >> (fn (_, (_, c)) => Condense ((fst c),(snd c)))
quigley@16357
   222
quigley@15642
   223
(*
quigley@15642
   224
      val hyper = a (Word "hyper")
quigley@15642
   225
                  ++ many ((a (Other ",") ++ number) >> snd)
quigley@15642
   226
                  >> (Hyper o snd)
quigley@15642
   227
*)
quigley@15642
   228
     (* val method = axiom ||binary || factor || para || hyper*)
quigley@15642
   229
quigley@16357
   230
      val method = axiom || binary || factor || para ||super_l || super_r || rewrite || mrr || obv || aed || ssi || unc|| con
quigley@16357
   231
quigley@15642
   232
      val binary_s = a (Word "binary_s") ++ a (Other ",") ++ term_num
quigley@15642
   233
            >> (fn (_, (_, a)) => Binary_s a)
quigley@15642
   234
      val factor_s = a (Word "factor_s")
quigley@15642
   235
            >> (fn _ => Factor_s ())
quigley@15642
   236
      val demod_s = a (Word "demod")
quigley@15642
   237
                    ++ (many ((a (Other ",") ++ term_num) >> snd))
quigley@15642
   238
            >> (fn (_, a) => Demod_s a)
quigley@15642
   239
quigley@15642
   240
      val hyper_s = a (Word "hyper_s")
quigley@15642
   241
                    ++ many ((a (Other ",") ++ number) >> snd)
quigley@15642
   242
                    >> (Hyper_s o snd)
quigley@15642
   243
      val simp_method = binary_s || factor_s || demod_s || hyper_s
quigley@15642
   244
      val simp = a (Other ",") ++ simp_method >> snd
quigley@15642
   245
      val simps = many simp
quigley@15642
   246
 
quigley@15642
   247
quigley@15642
   248
      val justification =
quigley@15642
   249
           a (Other "[") ++number ++ a (Other ":") ++ method ++ a (Other "]")
quigley@15642
   250
                 >> (fn (_,(_, (_,(b, _)))) => b)
quigley@15642
   251
quigley@15642
   252
     
quigley@15642
   253
exception NOTERM
quigley@15642
   254
quigley@15642
   255
(* FIX - should change the stars and pluses to many rather than explicit patterns *)
quigley@15642
   256
paulson@16953
   257
fun trim_prefix a b =
paulson@16953
   258
  let val n = String.size a 
paulson@16953
   259
  in  String.substring (b, n, (size b) - n)  end;
paulson@16953
   260
  
paulson@16953
   261
quigley@15642
   262
(* FIX - add the other things later *)
paulson@16953
   263
fun remove_typeinfo x  =  
paulson@16953
   264
    if String.isPrefix ResClause.fixed_var_prefix x
paulson@16953
   265
    then trim_prefix ResClause.fixed_var_prefix x
paulson@16953
   266
    else if String.isPrefix ResClause.schematic_var_prefix x
paulson@16953
   267
    then trim_prefix ResClause.schematic_var_prefix x
paulson@16953
   268
    else if String.isPrefix ResClause.const_prefix x
paulson@16953
   269
    then trim_prefix ResClause.const_prefix x
paulson@16953
   270
    else if String.isPrefix ResClause.tfree_prefix x
paulson@16953
   271
    then ""
paulson@16953
   272
    else if String.isPrefix ResClause.tvar_prefix x
paulson@16953
   273
    then ""
paulson@16953
   274
    else if String.isPrefix ResClause.tconst_prefix x
paulson@16953
   275
    then ""
paulson@16953
   276
    else x;                                               
quigley@15642
   277
quigley@15642
   278
fun term input = (  ntermlist ++ a (Other "-") ++ a (Other ">") ++ ptermlist >>(fn (a,(_,(_,b))) =>  (a@b))
quigley@15642
   279
                  ) input
quigley@15642
   280
quigley@15642
   281
(* pterms are terms from the rhs of the -> in the spass proof.  *)
quigley@15642
   282
(* they should have a "~" in front of them so that they match with *)
quigley@15642
   283
(* positive terms in the meta-clause *)
quigley@15642
   284
(* nterm are terms from the lhs of the spass proof, and shouldn't *)
quigley@15642
   285
(* "~"s added  word ++ a (Other "(") ++ arglist ++ a (Other ")") >> (fn (a,(_,(b,_ ))) =>  (a^" "^b)) *)
quigley@15642
   286
quigley@15642
   287
and  pterm input = (
quigley@15642
   288
           peqterm >> (fn (a) => a)
quigley@15642
   289
        
quigley@15642
   290
         || word ++ a (Other "(") ++ arglist ++  a (Other ")") ++ a (Other "*")++ a (Other "*") ++ a (Other "+")
quigley@15642
   291
           >> (fn (a, (_,(b, (_,(_,_))))) =>  ("~"^" "^(remove_typeinfo a)^" "^b))
quigley@15642
   292
         
quigley@15642
   293
        || word ++ a (Other "(") ++ arglist ++  a (Other ")") ++ a (Other "*") ++ a (Other "+")
quigley@15642
   294
           >> (fn ( a, (_,(b, (_,(_,_))))) =>  ("~"^" "^(remove_typeinfo a)^" "^b))
quigley@15642
   295
        
quigley@15642
   296
        || word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*")
quigley@15642
   297
           >> (fn ( a, (_,(b, (_,(_,_))))) =>  ("~"^" "^(remove_typeinfo a)^" "^b))
quigley@15642
   298
        
quigley@15642
   299
	|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*")
quigley@15642
   300
           >> (fn (a, (_,(b, (_,_)))) =>  ("~"^" "^(remove_typeinfo a)^" "^b))
quigley@15642
   301
quigley@15642
   302
        || word ++ a (Other "(") ++  arglist ++ a (Other ")") 
quigley@15642
   303
           >> (fn ( a, (_,(b,_ ))) => ("~"^" "^(remove_typeinfo a)^" "^b))
quigley@15642
   304
quigley@16357
   305
        || word ++ a (Other "*") >> (fn (w,b) => "~"^" "^(remove_typeinfo w))
quigley@16357
   306
quigley@16357
   307
        || word                  >> (fn w => "~"^" "^(remove_typeinfo w))) input
quigley@15642
   308
quigley@15642
   309
and  nterm input =
quigley@15642
   310
    
quigley@15642
   311
       (  
quigley@15642
   312
           neqterm >> (fn (a) => a)
quigley@15642
   313
quigley@15642
   314
        || word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*") ++ a (Other "+")
quigley@15642
   315
           >> (fn ( a, (_,(b, (_,(_,_))))) =>  ((remove_typeinfo a)^" "^b))
quigley@15642
   316
quigley@15642
   317
        || word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "+")
quigley@15642
   318
           >> (fn ( a, (_,(b, (_,(_,_))))) =>  ((remove_typeinfo a)^" "^b))
quigley@15642
   319
        
quigley@15642
   320
        || word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*") ++ a (Other "*")
quigley@15642
   321
           >> (fn ( a, (_,(b, (_,(_,_))))) =>  ((remove_typeinfo a)^" "^b))
quigley@15642
   322
        
quigley@15642
   323
	|| word ++ a (Other "(") ++ arglist ++ a (Other ")") ++ a (Other "*")
quigley@15642
   324
           >> (fn ( a, (_,(b, (_,_)))) =>  ((remove_typeinfo a)^" "^b))
quigley@15642
   325
quigley@15642
   326
        || word ++ a (Other "(") ++ arglist ++ a (Other ")") 
quigley@15642
   327
           >> (fn (a, (_,(b,_ ))) => ((remove_typeinfo a)^" "^b))
quigley@15642
   328
quigley@16357
   329
        || word ++ a (Other "*") >> (fn (w,b) =>  (remove_typeinfo w)) 
quigley@16357
   330
        || word                  >> (fn w =>  (remove_typeinfo w)) 
quigley@16357
   331
         ) input 
quigley@15642
   332
quigley@15642
   333
quigley@15642
   334
and peqterm input =(
quigley@15642
   335
 
quigley@15642
   336
         a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   337
         ++ a (Other "*") ++ a (Other "*") ++ a (Other "+")
quigley@15642
   338
            >> (fn (_,(_,(a,(_,(b,(_,(_,(_,_)))))))) => (a^" ~= "^b))
quigley@15642
   339
quigley@15642
   340
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   341
          ++ a (Other "*") ++ a (Other "+")
quigley@15642
   342
            >> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" ~= "^b))
quigley@15642
   343
quigley@15642
   344
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   345
         ++ a (Other "*") ++ a (Other "*")
quigley@15642
   346
            >> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" ~= "^b))
quigley@15642
   347
quigley@15642
   348
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   349
         ++ a (Other "*") 
quigley@15642
   350
            >> (fn (_,(_,(a,(_,(b,(_,_)))))) => (a^" ~= "^b))
quigley@15642
   351
quigley@15642
   352
quigley@15642
   353
       ||a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   354
            >> (fn (_,(_,(a,(_,(b,_))))) => (a^" ~= "^b))) input
quigley@15642
   355
quigley@15642
   356
quigley@15642
   357
quigley@15642
   358
and neqterm input =(
quigley@15642
   359
 
quigley@15642
   360
         a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   361
         ++ a (Other "*") ++ a (Other "*") ++ a (Other "+")
quigley@15642
   362
            >> (fn (_,(_,(a,(_,(b,(_,(_,(_,_)))))))) => (a^" = "^b))
quigley@15642
   363
quigley@15642
   364
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   365
          ++ a (Other "*") ++ a (Other "+")
quigley@15642
   366
            >> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" = "^b))
quigley@15642
   367
quigley@15642
   368
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   369
         ++ a (Other "*") ++ a (Other "*")
quigley@15642
   370
            >> (fn (_,(_,(a,(_,(b,(_,(_,_))))))) => (a^" = "^b))
quigley@15642
   371
quigley@15642
   372
      || a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   373
         ++ a (Other "*") 
quigley@15642
   374
            >> (fn (_,(_,(a,(_,(b,(_,_)))))) => (a^" = "^b))
quigley@15642
   375
quigley@15642
   376
quigley@15642
   377
       ||a (Word "equal") ++  a (Other "(") ++ nterm ++ a (Other ",") ++ nterm ++ a (Other ")") 
quigley@15642
   378
            >> (fn (_,(_,(a,(_,(b,_))))) => (a^" = "^b))) input
quigley@15642
   379
quigley@15642
   380
quigley@15642
   381
quigley@15642
   382
and ptermlist input = (many  pterm
quigley@15642
   383
                      >> (fn (a) => (a))) input
quigley@15642
   384
quigley@15642
   385
and ntermlist input = (many  nterm
quigley@15642
   386
                      >> (fn (a) => (a))) input
quigley@15642
   387
quigley@15642
   388
(*and arglist input = (    nterm >> (fn (a) => (a))
quigley@15642
   389
                     ||  nterm ++ many (a (Other ",") ++ nterm >> snd)
paulson@17306
   390
                      >> (fn (a, b) => (a^" "^(space_implode " " b)))) input*)
quigley@15642
   391
quigley@15642
   392
and arglist input = (   nterm ++ many (a (Other ",") ++ nterm >> snd)
paulson@17306
   393
                      >> (fn (a, b) => (a^" "^(space_implode " " b))) 
quigley@15642
   394
                      ||    nterm >> (fn (a) => (a)))input
quigley@15642
   395
quigley@15642
   396
 val clause =  term
quigley@15642
   397
quigley@15919
   398
(* not entirely sure nterm is right here, but I don't think you get negative things before the ||s *)
quigley@15919
   399
 val line = number ++ justification ++ many( nterm) ++ a (Other "|") ++ 
quigley@15919
   400
            a (Other "|") ++ clause ++ a (Other ".")
quigley@15919
   401
          >> (fn (a, (z, (w, (_,( _, (c, _)))))) => (a, z,(w@ c)))
quigley@15919
   402
       
quigley@15642
   403
 val lines = many line
quigley@15642
   404
 val alllines = (lines ++ finished) >> fst
quigley@15642
   405
    
quigley@15642
   406
 val parse = fst o alllines
quigley@15642
   407
paulson@15684
   408
end;