src/HOL/Tools/Predicate_Compile/code_prolog.ML
changeset 38076 2a9c14d9d2ef
parent 38075 3d5e2b7d1374
child 38077 46ff55ace18c
equal deleted inserted replaced
38075:3d5e2b7d1374 38076:2a9c14d9d2ef
   157 
   157 
   158 val scan_var =
   158 val scan_var =
   159   Scan.repeat (Scan.one
   159   Scan.repeat (Scan.one
   160     (fn s => Symbol.is_ascii_upper s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s))
   160     (fn s => Symbol.is_ascii_upper s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s))
   161 
   161 
       
   162 val scan_ident =
       
   163   Scan.repeat (Scan.one
       
   164     (fn s => Symbol.is_ascii_letter s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s))
       
   165 
   162 fun dest_Char (Symbol.Char s) = s
   166 fun dest_Char (Symbol.Char s) = s
   163 
   167 
   164 val string_of = concat o map (dest_Char o Symbol.decode)
   168 val string_of = concat o map (dest_Char o Symbol.decode)
   165 
   169 
       
   170 val is_atom_ident = forall Symbol.is_ascii_lower
       
   171 
       
   172 val is_var_ident =
       
   173   forall (fn s => Symbol.is_ascii_upper s orelse Symbol.is_ascii_digit s orelse Symbol.is_ascii_quasi s)
       
   174 
   166 val scan_term =
   175 val scan_term =
   167   scan_atom >> (Cons o string_of) || scan_var >> (Var o rpair dummyT o string_of)
   176   scan_ident >> (fn s => 
   168 
   177     if is_var_ident s then (Var (string_of s, dummyT))
       
   178     else if is_atom_ident s then Cons (string_of s)
       
   179     else raise Fail "unexpected")
       
   180     
   169 val parse_term = fst o Scan.finite Symbol.stopper
   181 val parse_term = fst o Scan.finite Symbol.stopper
   170             (Scan.error (!! (fn _ => raise Fail "parsing prolog output failed"))
   182             (Scan.error (!! (fn _ => raise Fail "parsing prolog output failed"))
   171                             scan_term)
   183                             scan_term)
   172   o explode
   184   o explode
   173   
   185