src/Pure/Isar/outer_syntax.ML
changeset 60073 76a8400a58d9
parent 59990 a81dc82ecba3
child 60095 35f626b11422
equal deleted inserted replaced
60072:dda1e781c7b4 60073:76a8400a58d9
   175         SOME (Command {command_parser = Parser parse, ...}) =>
   175         SOME (Command {command_parser = Parser parse, ...}) =>
   176           Parse.!!! (command_tags |-- parse) >> (fn f => f tr0)
   176           Parse.!!! (command_tags |-- parse) >> (fn f => f tr0)
   177       | SOME (Command {command_parser = Limited_Parser parse, ...}) =>
   177       | SOME (Command {command_parser = Limited_Parser parse, ...}) =>
   178           before_command :|-- (fn limited =>
   178           before_command :|-- (fn limited =>
   179             Parse.!!! (command_tags |-- parse limited)) >> (fn f => f tr0)
   179             Parse.!!! (command_tags |-- parse limited)) >> (fn f => f tr0)
   180       | NONE =>
   180       | NONE => Scan.fail_with (fn _ => fn _ => err_command "Undefined command " name [pos]))
   181           Scan.succeed
       
   182             (tr0 |> Toplevel.imperative (fn () => err_command "Undefined command " name [pos])))
       
   183     end);
   181     end);
   184 
   182 
   185 val parse_cmt = Parse.$$$ "--" -- Parse.!!! Parse.document_source;
   183 val parse_cmt = Parse.$$$ "--" -- Parse.!!! Parse.document_source;
   186 
       
   187 in
       
   188 
   184 
   189 fun commands_source thy =
   185 fun commands_source thy =
   190   Token.source_proper #>
   186   Token.source_proper #>
   191   Source.source Token.stopper (Scan.bulk (parse_cmt >> K NONE || Parse.not_eof >> SOME)) #>
   187   Source.source Token.stopper (Scan.bulk (parse_cmt >> K NONE || Parse.not_eof >> SOME)) #>
   192   Source.map_filter I #>
   188   Source.map_filter I #>
   193   Source.source Token.stopper (Scan.bulk (fn xs => Parse.!!! (parse_command thy) xs));
   189   Source.source Token.stopper (Scan.bulk (fn xs => Parse.!!! (parse_command thy) xs));
   194 
   190 
   195 end;
   191 in
   196 
   192 
   197 fun parse thy pos str =
   193 fun parse thy pos str =
   198   Source.of_string str
   194   Source.of_string str
   199   |> Symbol.source
   195   |> Symbol.source
   200   |> Token.source (Thy_Header.get_keywords thy) pos
   196   |> Token.source (Thy_Header.get_keywords thy) pos
   203 
   199 
   204 fun parse_tokens thy toks =
   200 fun parse_tokens thy toks =
   205   Source.of_list toks
   201   Source.of_list toks
   206   |> commands_source thy
   202   |> commands_source thy
   207   |> Source.exhaust;
   203   |> Source.exhaust;
       
   204 
       
   205 end;
   208 
   206 
   209 
   207 
   210 (* parse spans *)
   208 (* parse spans *)
   211 
   209 
   212 local
   210 local