src/Pure/Isar/outer_syntax.ML
changeset 36959 f5417836dbea
parent 36955 226fb165833e
child 37216 3165bc303f66
equal deleted inserted replaced
36958:ad5313f1bd30 36959:f5417836dbea
    23   val local_theory_to_proof': string -> string -> Keyword.T ->
    23   val local_theory_to_proof': string -> string -> Keyword.T ->
    24     (bool -> local_theory -> Proof.state) parser -> unit
    24     (bool -> local_theory -> Proof.state) parser -> unit
    25   val local_theory_to_proof: string -> string -> Keyword.T ->
    25   val local_theory_to_proof: string -> string -> Keyword.T ->
    26     (local_theory -> Proof.state) parser -> unit
    26     (local_theory -> Proof.state) parser -> unit
    27   val print_outer_syntax: unit -> unit
    27   val print_outer_syntax: unit -> unit
    28   val scan: Position.T -> string -> OuterLex.token list
    28   val scan: Position.T -> string -> Token.T list
    29   val parse: Position.T -> string -> Toplevel.transition list
    29   val parse: Position.T -> string -> Toplevel.transition list
    30   val process_file: Path.T -> theory -> theory
    30   val process_file: Path.T -> theory -> theory
    31   type isar
    31   type isar
    32   val isar: bool -> isar
    32   val isar: bool -> isar
    33   val prepare_command: Position.T -> string -> Toplevel.transition
    33   val prepare_command: Position.T -> string -> Toplevel.transition
    34   val load_thy: string -> Position.T -> string list -> bool -> unit -> unit
    34   val load_thy: string -> Position.T -> string list -> bool -> unit -> unit
    35 end;
    35 end;
    36 
    36 
    37 structure Outer_Syntax: OUTER_SYNTAX =
    37 structure Outer_Syntax: OUTER_SYNTAX =
    38 struct
    38 struct
    39 
       
    40 structure T = OuterLex;
       
    41 type 'a parser = 'a Parse.parser;
       
    42 
       
    43 
       
    44 
    39 
    45 (** outer syntax **)
    40 (** outer syntax **)
    46 
    41 
    47 (* command parsers *)
    42 (* command parsers *)
    48 
    43 
   169 (* basic sources *)
   164 (* basic sources *)
   170 
   165 
   171 fun toplevel_source term do_recover cmd src =
   166 fun toplevel_source term do_recover cmd src =
   172   let
   167   let
   173     val no_terminator =
   168     val no_terminator =
   174       Scan.unless Parse.semicolon (Scan.one (T.not_sync andf T.not_eof));
   169       Scan.unless Parse.semicolon (Scan.one (Token.not_sync andf Token.not_eof));
   175     fun recover int =
   170     fun recover int =
   176       (int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]);
   171       (int, fn _ => Scan.prompt "recover# " (Scan.repeat no_terminator) >> K [NONE]);
   177   in
   172   in
   178     src
   173     src
   179     |> T.source_proper
   174     |> Token.source_proper
   180     |> Source.source T.stopper
   175     |> Source.source Token.stopper
   181       (Scan.bulk (Parse.$$$ "--" -- Parse.!!! Parse.doc_source >> K NONE || Parse.not_eof >> SOME))
   176       (Scan.bulk (Parse.$$$ "--" -- Parse.!!! Parse.doc_source >> K NONE || Parse.not_eof >> SOME))
   182         (Option.map recover do_recover)
   177         (Option.map recover do_recover)
   183     |> Source.map_filter I
   178     |> Source.map_filter I
   184     |> Source.source T.stopper
   179     |> Source.source Token.stopper
   185         (Scan.bulk (fn xs => Parse.!!! (parse_command term (cmd ())) xs))
   180         (Scan.bulk (fn xs => Parse.!!! (parse_command term (cmd ())) xs))
   186         (Option.map recover do_recover)
   181         (Option.map recover do_recover)
   187     |> Source.map_filter I
   182     |> Source.map_filter I
   188   end;
   183   end;
   189 
   184 
   191 (* off-line scanning/parsing *)
   186 (* off-line scanning/parsing *)
   192 
   187 
   193 fun scan pos str =
   188 fun scan pos str =
   194   Source.of_string str
   189   Source.of_string str
   195   |> Symbol.source {do_recover = false}
   190   |> Symbol.source {do_recover = false}
   196   |> T.source {do_recover = SOME false} Keyword.get_lexicons pos
   191   |> Token.source {do_recover = SOME false} Keyword.get_lexicons pos
   197   |> Source.exhaust;
   192   |> Source.exhaust;
   198 
   193 
   199 fun parse pos str =
   194 fun parse pos str =
   200   Source.of_string str
   195   Source.of_string str
   201   |> Symbol.source {do_recover = false}
   196   |> Symbol.source {do_recover = false}
   202   |> T.source {do_recover = SOME false} Keyword.get_lexicons pos
   197   |> Token.source {do_recover = SOME false} Keyword.get_lexicons pos
   203   |> toplevel_source false NONE get_command
   198   |> toplevel_source false NONE get_command
   204   |> Source.exhaust;
   199   |> Source.exhaust;
   205 
   200 
   206 
   201 
   207 (* process file *)
   202 (* process file *)
   220 
   215 
   221 (* interactive source of toplevel transformers *)
   216 (* interactive source of toplevel transformers *)
   222 
   217 
   223 type isar =
   218 type isar =
   224   (Toplevel.transition, (Toplevel.transition option,
   219   (Toplevel.transition, (Toplevel.transition option,
   225     (OuterLex.token, (OuterLex.token option, (OuterLex.token, (OuterLex.token,
   220     (Token.T, (Token.T option, (Token.T, (Token.T,
   226       (Symbol_Pos.T, Position.T * (Symbol.symbol, (string, unit) Source.source)
   221       (Symbol_Pos.T, Position.T * (Symbol.symbol, (string, unit) Source.source)
   227   Source.source) Source.source) Source.source) Source.source)
   222   Source.source) Source.source) Source.source) Source.source)
   228   Source.source) Source.source) Source.source) Source.source;
   223   Source.source) Source.source) Source.source) Source.source;
   229 
   224 
   230 fun isar term : isar =
   225 fun isar term : isar =
   231   Source.tty
   226   Source.tty
   232   |> Symbol.source {do_recover = true}
   227   |> Symbol.source {do_recover = true}
   233   |> T.source {do_recover = SOME true} Keyword.get_lexicons Position.none
   228   |> Token.source {do_recover = SOME true} Keyword.get_lexicons Position.none
   234   |> toplevel_source term (SOME true) get_command;
   229   |> toplevel_source term (SOME true) get_command;
   235 
   230 
   236 
   231 
   237 (* prepare toplevel commands -- fail-safe *)
   232 (* prepare toplevel commands -- fail-safe *)
   238 
   233