28 |
28 |
29 (* Parser combinators *) |
29 (* Parser combinators *) |
30 |
30 |
31 exception Noparse; |
31 exception Noparse; |
32 exception SPASSError of string; |
32 exception SPASSError of string; |
|
33 exception VampError of string; |
|
34 |
33 |
35 |
34 fun (parser1 ++ parser2) input = |
36 fun (parser1 ++ parser2) input = |
35 let |
37 let |
36 val (result1, rest1) = parser1 input |
38 val (result1, rest1) = parser1 input |
37 val (result2, rest2) = parser2 rest1 |
39 val (result2, rest2) = parser2 rest1 |
157 else |
159 else |
158 raise SPASSError "Couldn't find a proof." |
160 raise SPASSError "Couldn't find a proof." |
159 *) |
161 *) |
160 |
162 |
161 |
163 |
|
164 |
|
165 |
|
166 |
162 fun several p = many (some p) |
167 fun several p = many (some p) |
163 fun collect (h, t) = h ^ (Utils.itlist (fn s1 => fn s2 => s1 ^ s2) t "") |
168 fun collect (h, t) = h ^ (Utils.itlist (fn s1 => fn s2 => s1 ^ s2) t "") |
164 |
169 |
165 fun lower_letter s = ("a" <= s) andalso (s <= "z") |
170 fun lower_letter s = ("a" <= s) andalso (s <= "z") |
166 fun upper_letter s = ("A" <= s) andalso (s <= "Z") |
171 fun upper_letter s = ("A" <= s) andalso (s <= "Z") |
180 val alltokens = (tokens ++ finished) >> fst |
185 val alltokens = (tokens ++ finished) >> fst |
181 |
186 |
182 (* val lex = fst ( alltokens ( (map str) explode))*) |
187 (* val lex = fst ( alltokens ( (map str) explode))*) |
183 fun lex s = alltokens (explode s) |
188 fun lex s = alltokens (explode s) |
184 |
189 |
|
190 |
|
191 (*********************************************************) |
|
192 (* Temporary code to "parse" Vampire proofs *) |
|
193 (*********************************************************) |
|
194 |
|
195 fun num_int (Number n) = n |
|
196 | num_int _ = raise VampError "Not a number" |
|
197 |
|
198 fun takeUntil ch [] res = (res, []) |
|
199 | takeUntil ch (x::xs) res = if x = ch |
|
200 then |
|
201 (res, xs) |
|
202 else |
|
203 takeUntil ch xs (res@[x]) |
|
204 |
|
205 fun linenums [] nums = nums |
|
206 | linenums (x::xs) nums = let val (fst, rest ) = takeUntil (Other "%") (x::xs) [] |
|
207 in |
|
208 if rest = [] |
|
209 then |
|
210 nums |
|
211 else |
|
212 let val num = hd rest |
|
213 val int_of = num_int num |
|
214 |
|
215 in |
|
216 linenums rest (int_of::nums) |
|
217 end |
|
218 end |
|
219 |
|
220 fun get_linenums proofstr = let val s = extract_proof proofstr |
|
221 val tokens = #1(lex s) |
|
222 |
|
223 in |
|
224 rev (linenums tokens []) |
|
225 end |
|
226 |
|
227 (************************************************************) |
|
228 (************************************************************) |
|
229 |
|
230 |
|
231 (**************************************************) |
|
232 (* Code to parse SPASS proofs *) |
|
233 (**************************************************) |
|
234 |
185 datatype Tree = Leaf of string |
235 datatype Tree = Leaf of string |
186 | Branch of Tree * Tree |
236 | Branch of Tree * Tree |
187 |
|
188 |
|
189 |
237 |
190 |
238 |
191 fun number ((Number n)::rest) = (n, rest) |
239 fun number ((Number n)::rest) = (n, rest) |
192 | number _ = raise NOPARSE_NUM |
240 | number _ = raise NOPARSE_NUM |
193 fun word ((Word w)::rest) = (w, rest) |
241 fun word ((Word w)::rest) = (w, rest) |