src/HOL/Import/import_syntax.ML
changeset 36959 f5417836dbea
parent 33317 b4534348b8fd
child 36960 01594f816e3a
equal deleted inserted replaced
36958:ad5313f1bd30 36959:f5417836dbea
     2     Author:     Sebastian Skalberg (TU Muenchen)
     2     Author:     Sebastian Skalberg (TU Muenchen)
     3 *)
     3 *)
     4 
     4 
     5 signature HOL4_IMPORT_SYNTAX =
     5 signature HOL4_IMPORT_SYNTAX =
     6 sig
     6 sig
     7     type token = OuterLex.token
     7     val import_segment: (theory -> theory) parser
     8     type command  = token list -> (theory -> theory) * token list 
     8     val import_theory : (theory -> theory) parser
     9 
     9     val end_import    : (theory -> theory) parser
    10     val import_segment: token list -> (theory -> theory) * token list
    10                         
    11     val import_theory : token list -> (theory -> theory) * token list
    11     val setup_theory  : (theory -> theory) parser
    12     val end_import    : token list -> (theory -> theory) * token list
    12     val end_setup     : (theory -> theory) parser
    13 
    13                         
    14     val setup_theory  : token list -> (theory -> theory) * token list
    14     val thm_maps      : (theory -> theory) parser
    15     val end_setup     : token list -> (theory -> theory) * token list
    15     val ignore_thms   : (theory -> theory) parser
    16 
    16     val type_maps     : (theory -> theory) parser
    17     val thm_maps      : token list -> (theory -> theory) * token list
    17     val def_maps      : (theory -> theory) parser
    18     val ignore_thms   : token list -> (theory -> theory) * token list
    18     val const_maps    : (theory -> theory) parser
    19     val type_maps     : token list -> (theory -> theory) * token list
    19     val const_moves   : (theory -> theory) parser
    20     val def_maps      : token list -> (theory -> theory) * token list
    20     val const_renames : (theory -> theory) parser
    21     val const_maps    : token list -> (theory -> theory) * token list
    21 
    22     val const_moves   : token list -> (theory -> theory) * token list
    22     val skip_import_dir : (theory -> theory) parser
    23     val const_renames : token list -> (theory -> theory) * token list
    23     val skip_import     : (theory -> theory) parser
    24 
       
    25     val skip_import_dir : token list -> (theory -> theory) * token list
       
    26     val skip_import     : token list -> (theory -> theory) * token list
       
    27 
    24 
    28     val setup        : unit -> unit
    25     val setup        : unit -> unit
    29 end
    26 end
    30 
    27 
    31 structure HOL4ImportSyntax :> HOL4_IMPORT_SYNTAX =
    28 structure HOL4ImportSyntax :> HOL4_IMPORT_SYNTAX =
    32 struct
    29 struct
    33 
       
    34 type token = OuterLex.token
       
    35 type command  = token list -> (theory -> theory) * token list 
       
    36 
    30 
    37 local structure P = OuterParse and K = OuterKeyword in
    31 local structure P = OuterParse and K = OuterKeyword in
    38 
    32 
    39 (* Parsers *)
    33 (* Parsers *)
    40 
    34 
    46                                   thy |> set_generating_thy thyname
    40                                   thy |> set_generating_thy thyname
    47                                       |> Sign.add_path thyname
    41                                       |> Sign.add_path thyname
    48                                       |> add_dump (";setup_theory " ^ thyname))
    42                                       |> add_dump (";setup_theory " ^ thyname))
    49 
    43 
    50 fun do_skip_import_dir s = (ImportRecorder.set_skip_import_dir (SOME s); I)
    44 fun do_skip_import_dir s = (ImportRecorder.set_skip_import_dir (SOME s); I)
    51 val skip_import_dir : command = P.string >> do_skip_import_dir
    45 val skip_import_dir = P.string >> do_skip_import_dir
    52 
    46 
    53 val lower = String.map Char.toLower
    47 val lower = String.map Char.toLower
    54 fun do_skip_import s = (ImportRecorder.set_skip_import (case lower s of "on" => true | "off" => false | _ => Scan.fail ()); I)
    48 fun do_skip_import s = (ImportRecorder.set_skip_import (case lower s of "on" => true | "off" => false | _ => Scan.fail ()); I)
    55 val skip_import : command = P.short_ident >> do_skip_import
    49 val skip_import = P.short_ident >> do_skip_import
    56 
    50 
    57 fun end_import toks =
    51 fun end_import toks =
    58     Scan.succeed
    52     Scan.succeed
    59         (fn thy =>
    53         (fn thy =>
    60             let
    54             let
   158         val symb_source = Symbol.source {do_recover = false} orig_source
   152         val symb_source = Symbol.source {do_recover = false} orig_source
   159         val lexes = Unsynchronized.ref
   153         val lexes = Unsynchronized.ref
   160           (Scan.make_lexicon (map Symbol.explode ["import_segment","ignore_thms","import","end",">","::","const_maps","const_moves","thm_maps","const_renames","type_maps","def_maps"]),
   154           (Scan.make_lexicon (map Symbol.explode ["import_segment","ignore_thms","import","end",">","::","const_maps","const_moves","thm_maps","const_renames","type_maps","def_maps"]),
   161                   Scan.empty_lexicon)
   155                   Scan.empty_lexicon)
   162         val get_lexes = fn () => !lexes
   156         val get_lexes = fn () => !lexes
   163         val token_source = OuterLex.source {do_recover = NONE} get_lexes Position.start symb_source
   157         val token_source = Token.source {do_recover = NONE} get_lexes Position.start symb_source
   164         val token_list = filter_out (OuterLex.is_kind OuterLex.Space) (Source.exhaust token_source)
   158         val token_list = filter_out (Token.is_kind Token.Space) (Source.exhaust token_source)
   165         val import_segmentP = OuterParse.$$$ "import_segment" |-- import_segment
   159         val import_segmentP = OuterParse.$$$ "import_segment" |-- import_segment
   166         val type_mapsP = OuterParse.$$$ "type_maps" |-- type_maps
   160         val type_mapsP = OuterParse.$$$ "type_maps" |-- type_maps
   167         val def_mapsP = OuterParse.$$$ "def_maps" |-- def_maps
   161         val def_mapsP = OuterParse.$$$ "def_maps" |-- def_maps
   168         val const_mapsP = OuterParse.$$$ "const_maps" |-- const_maps
   162         val const_mapsP = OuterParse.$$$ "const_maps" |-- const_maps
   169         val const_movesP = OuterParse.$$$ "const_moves" |-- const_moves
   163         val const_movesP = OuterParse.$$$ "const_moves" |-- const_moves