equal
deleted
inserted
replaced
29 (*concatenation*) |
29 (*concatenation*) |
30 val ^^ : ('a -> string * 'b) * ('b -> string * 'c) -> 'a -> string * 'c |
30 val ^^ : ('a -> string * 'b) * ('b -> string * 'c) -> 'a -> string * 'c |
31 (*one element literal*) |
31 (*one element literal*) |
32 val $$ : ''a -> ''a list -> ''a * ''a list |
32 val $$ : ''a -> ''a list -> ''a * ''a list |
33 (*literal list*) |
33 (*literal list*) |
34 val list: ''a list -> ''a list -> ''a list * ''a list |
34 val this: ''a list -> ''a list -> ''a list * ''a list |
35 end; |
35 end; |
36 |
36 |
37 signature SCAN = |
37 signature SCAN = |
38 sig |
38 sig |
39 include BASIC_SCAN |
39 include BASIC_SCAN |
149 |
149 |
150 fun $$ _ [] = raise MORE None |
150 fun $$ _ [] = raise MORE None |
151 | $$ a (x :: xs) = |
151 | $$ a (x :: xs) = |
152 if a = x then (x, xs) else raise FAIL None; |
152 if a = x then (x, xs) else raise FAIL None; |
153 |
153 |
154 fun list ys xs = |
154 fun this ys xs = |
155 let |
155 let |
156 fun drop_prefix [] xs = xs |
156 fun drop_prefix [] xs = xs |
157 | drop_prefix (_ :: _) [] = raise MORE None |
157 | drop_prefix (_ :: _) [] = raise MORE None |
158 | drop_prefix (y :: ys) (x :: xs) = |
158 | drop_prefix (y :: ys) (x :: xs) = |
159 if y = x then drop_prefix ys xs else raise FAIL None; |
159 if y = x then drop_prefix ys xs else raise FAIL None; |
223 fun !! err scan xs = scan xs handle FAIL msg => raise ABORT (err (xs, msg)); |
223 fun !! err scan xs = scan xs handle FAIL msg => raise ABORT (err (xs, msg)); |
224 fun try scan xs = scan xs handle MORE _ => raise FAIL None | ABORT _ => raise FAIL None; |
224 fun try scan xs = scan xs handle MORE _ => raise FAIL None | ABORT _ => raise FAIL None; |
225 fun force scan xs = scan xs handle MORE _ => raise FAIL None; |
225 fun force scan xs = scan xs handle MORE _ => raise FAIL None; |
226 fun prompt str scan xs = scan xs handle MORE None => raise MORE (Some str); |
226 fun prompt str scan xs = scan xs handle MORE None => raise MORE (Some str); |
227 fun catch scan xs = scan xs handle ABORT msg => raise FAIL (Some msg); |
227 fun catch scan xs = scan xs handle ABORT msg => raise FAIL (Some msg); |
228 fun error scan xs = scan xs handle ABORT msg => Library.error msg; |
228 fun error scan xs = scan xs handle ABORT msg => Output.error msg; |
229 |
229 |
230 |
230 |
231 (* finite scans *) |
231 (* finite scans *) |
232 |
232 |
233 fun finite' (stopper, is_stopper) scan (state, input) = |
233 fun finite' (stopper, is_stopper) scan (state, input) = |