src/Pure/Isar/outer_syntax.ML
changeset 48646 91281e9472d8
parent 48638 22d65e375c01
child 48647 a5144c4c26a2
equal deleted inserted replaced
48645:33f00ce23e63 48646:91281e9472d8
    11 sig
    11 sig
    12   type outer_syntax
    12   type outer_syntax
    13   val is_markup: outer_syntax -> Thy_Output.markup -> string -> bool
    13   val is_markup: outer_syntax -> Thy_Output.markup -> string -> bool
    14   val get_syntax: unit -> (Scan.lexicon * Scan.lexicon) * outer_syntax
    14   val get_syntax: unit -> (Scan.lexicon * Scan.lexicon) * outer_syntax
    15   val check_syntax: unit -> unit
    15   val check_syntax: unit -> unit
    16   type command_spec = string * Keyword.T
    16   type command_spec = (string * Keyword.T) * Position.T
    17   val command: command_spec -> string ->
    17   val command: command_spec -> string ->
    18     (Toplevel.transition -> Toplevel.transition) parser -> unit
    18     (Toplevel.transition -> Toplevel.transition) parser -> unit
    19   val markup_command: Thy_Output.markup -> command_spec -> string ->
    19   val markup_command: Thy_Output.markup -> command_spec -> string ->
    20     (Toplevel.transition -> Toplevel.transition) parser -> unit
    20     (Toplevel.transition -> Toplevel.transition) parser -> unit
    21   val improper_command: command_spec -> string ->
    21   val improper_command: command_spec -> string ->
   116 
   116 
   117 
   117 
   118 
   118 
   119 (** global outer syntax **)
   119 (** global outer syntax **)
   120 
   120 
   121 type command_spec = string * Keyword.T;
   121 type command_spec = (string * Keyword.T) * Position.T;
   122 
   122 
   123 local
   123 local
   124 
   124 
   125 (*synchronized wrt. Keywords*)
   125 (*synchronized wrt. Keywords*)
   126 val global_outer_syntax = Unsynchronized.ref empty_outer_syntax;
   126 val global_outer_syntax = Unsynchronized.ref empty_outer_syntax;
   127 
   127 
   128 fun add_command (name, kind) cmd = CRITICAL (fn () =>
   128 fun add_command ((name, kind), pos) cmd = CRITICAL (fn () =>
   129   let
   129   let
   130     val thy = ML_Context.the_global_context ();
   130     val thy = ML_Context.the_global_context ();
   131     val _ =
   131     val _ =
   132       (case try (Thy_Header.the_keyword thy) name of
   132       (case try (Thy_Header.the_keyword thy) name of
   133         SOME spec =>
   133         SOME spec =>
   134           if Option.map #1 spec = SOME (Keyword.kind_of kind) then ()
   134           if Option.map #1 spec = SOME (Keyword.kind_of kind) then ()
   135           else error ("Inconsistent outer syntax keyword declaration " ^ quote name)
   135           else error ("Inconsistent outer syntax keyword declaration " ^
       
   136             quote name ^ Position.str_of pos)
   136       | NONE =>
   137       | NONE =>
   137           if Context.theory_name thy = Context.PureN
   138           if Context.theory_name thy = Context.PureN
   138           then Keyword.define (name, SOME kind)
   139           then Keyword.define (name, SOME kind)
   139           else error ("Undeclared outer syntax command " ^ quote name));
   140           else error ("Undeclared outer syntax command " ^ quote name ^ Position.str_of pos));
   140   in
   141   in
   141     Unsynchronized.change global_outer_syntax (map_commands (fn commands =>
   142     Unsynchronized.change global_outer_syntax (map_commands (fn commands =>
   142      (if not (Symtab.defined commands name) then ()
   143      (if not (Symtab.defined commands name) then ()
   143       else warning ("Redefining outer syntax command " ^ quote name);
   144       else warning ("Redefining outer syntax command " ^ quote name);
   144       Symtab.update (name, cmd) commands)))
   145       Symtab.update (name, cmd) commands)))