equal
deleted
inserted
replaced
113 (** error handling **) |
113 (** error handling **) |
114 |
114 |
115 (* group atomic parsers (no cuts!) *) |
115 (* group atomic parsers (no cuts!) *) |
116 |
116 |
117 fun fail_with s = Scan.fail_with |
117 fun fail_with s = Scan.fail_with |
118 (fn [] => s ^ " expected (past end-of-file!)" |
118 (fn [] => (fn () => s ^ " expected (past end-of-file!)") |
119 | tok :: _ => |
119 | tok :: _ => |
120 (case Token.text_of tok of |
120 (fn () => |
121 (txt, "") => |
121 (case Token.text_of tok of |
122 s ^ " expected,\nbut " ^ txt ^ Token.pos_of tok ^ " was found" |
122 (txt, "") => |
123 | (txt1, txt2) => |
123 s ^ " expected,\nbut " ^ txt ^ Token.pos_of tok ^ " was found" |
124 s ^ " expected,\nbut " ^ txt1 ^ Token.pos_of tok ^ " was found:\n" ^ txt2)); |
124 | (txt1, txt2) => |
|
125 s ^ " expected,\nbut " ^ txt1 ^ Token.pos_of tok ^ " was found:\n" ^ txt2))); |
125 |
126 |
126 fun group s scan = scan || fail_with s; |
127 fun group s scan = scan || fail_with s; |
127 |
128 |
128 |
129 |
129 (* cut *) |
130 (* cut *) |
131 fun cut kind scan = |
132 fun cut kind scan = |
132 let |
133 let |
133 fun get_pos [] = " (past end-of-file!)" |
134 fun get_pos [] = " (past end-of-file!)" |
134 | get_pos (tok :: _) = Token.pos_of tok; |
135 | get_pos (tok :: _) = Token.pos_of tok; |
135 |
136 |
136 fun err (toks, NONE) = kind ^ get_pos toks |
137 fun err (toks, NONE) = (fn () => kind ^ get_pos toks) |
137 | err (toks, SOME msg) = |
138 | err (toks, SOME msg) = |
138 if String.isPrefix kind msg then msg |
139 (fn () => |
139 else kind ^ get_pos toks ^ ": " ^ msg; |
140 let val s = msg () in |
|
141 if String.isPrefix kind s then s |
|
142 else kind ^ get_pos toks ^ ": " ^ s |
|
143 end); |
140 in Scan.!! err scan end; |
144 in Scan.!! err scan end; |
141 |
145 |
142 fun !!! scan = cut "Outer syntax error" scan; |
146 fun !!! scan = cut "Outer syntax error" scan; |
143 fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; |
147 fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; |
144 |
148 |