src/Pure/Tools/codegen_serializer.ML
changeset 19884 a7be206d8655
parent 19816 a8c8ed1c85e0
child 19936 18b4e43ac583
equal deleted inserted replaced
19883:d064712bdd1d 19884:a7be206d8655
    13       string list list
    13       string list list
    14       -> OuterParse.token list ->
    14       -> OuterParse.token list ->
    15       ((string -> string option)
    15       ((string -> string option)
    16         * (string -> CodegenThingol.itype pretty_syntax option)
    16         * (string -> CodegenThingol.itype pretty_syntax option)
    17         * (string -> CodegenThingol.iexpr pretty_syntax option)
    17         * (string -> CodegenThingol.iexpr pretty_syntax option)
    18       -> string list option
    18       -> string list * string list option
    19       -> CodegenThingol.module -> unit)
    19       -> CodegenThingol.module -> unit)
    20       * OuterParse.token list;
    20       * OuterParse.token list;
    21   val parse_syntax: ('b -> int) -> (string -> 'b -> 'a * 'b) -> OuterParse.token list ->
    21   val parse_syntax: ('b -> int) -> (string -> 'b -> 'a * 'b) -> OuterParse.token list ->
    22     ('b -> 'a pretty_syntax * 'b) * OuterParse.token list;
    22     ('b -> 'a pretty_syntax * 'b) * OuterParse.token list;
    23   val pretty_list: string -> string -> int * string -> CodegenThingol.iexpr pretty_syntax;
    23   val pretty_list: string -> string -> int * string -> CodegenThingol.iexpr pretty_syntax;
   197     string list list
   197     string list list
   198     -> OuterParse.token list ->
   198     -> OuterParse.token list ->
   199     ((string -> string option)
   199     ((string -> string option)
   200       * (string -> itype pretty_syntax option)
   200       * (string -> itype pretty_syntax option)
   201       * (string -> iexpr pretty_syntax option)
   201       * (string -> iexpr pretty_syntax option)
   202     -> string list option
   202     -> string list * string list option
   203     -> CodegenThingol.module -> unit)
   203     -> CodegenThingol.module -> unit)
   204     * OuterParse.token list;
   204     * OuterParse.token list;
   205 
   205 
   206 fun abstract_serializer (target, nspgrp) name_root (from_defs, from_module, validator, postproc)
   206 fun abstract_serializer (target, nspgrp) name_root (from_defs, from_module, validator, postproc)
   207     postprocess (class_syntax, tyco_syntax, const_syntax)
   207     postprocess (class_syntax, tyco_syntax, const_syntax)
   208     select module =
   208     (drop: string list, select) module =
   209   let
   209   let
   210     fun from_module' resolv imps ((name_qual, name), defs) =
   210     fun from_module' resolv imps ((name_qual, name), defs) =
   211       from_module resolv imps ((name_qual, name), defs)
   211       from_module resolv imps ((name_qual, name), defs)
   212       |> postprocess (resolv name_qual);
   212       |> postprocess (resolv name_qual);
   213   in
   213   in
   461             ml_from_expr NOBR e
   461             ml_from_expr NOBR e
   462           ]
   462           ]
   463       | ml_from_expr fxy (INum (n, _)) =
   463       | ml_from_expr fxy (INum (n, _)) =
   464           brackify BR [
   464           brackify BR [
   465             (str o IntInf.toString) n,
   465             (str o IntInf.toString) n,
   466             str ":IntInf.int"
   466             str ":",
       
   467             str "IntInf.int"
   467           ]
   468           ]
   468       | ml_from_expr _ (IChar (c, _)) =
   469       | ml_from_expr _ (IChar (c, _)) =
   469           (str o prefix "#" o quote)
   470           (str o prefix "#" o quote)
   470             (let val i = (Char.ord o the o Char.fromString) c
   471             (let val i = (Char.ord o the o Char.fromString) c
   471               in if i < 32 
   472               in if i < 32 
   808                parse_multi_file
   809                parse_multi_file
   809                  (K o SOME o str o suffix ";" o prefix "val _ = use "
   810                  (K o SOME o str o suffix ";" o prefix "val _ = use "
   810                   o quote o suffix ".ML" o translate_string (fn "." => "/" | s => s)) "ML" serializer
   811                   o quote o suffix ".ML" o translate_string (fn "." => "/" | s => s)) "ML" serializer
   811             | _ => Scan.fail ());
   812             | _ => Scan.fail ());
   812   in
   813   in
   813     (parse_multi
   814     parse_multi
   814      || parse_internal serializer
   815     || parse_internal serializer
   815      || parse_single_file serializer)
   816     || parse_single_file serializer
   816     >> (fn seri => fn (class_syntax, tyco_syntax, const_syntax) => seri 
       
   817          (class_syntax, tyco_syntax, const_syntax))
       
   818   end;
   817   end;
   819 
   818 
   820 fun mk_flat_ml_resolver names =
   819 fun mk_flat_ml_resolver names =
   821   let
   820   let
   822     val mangler =
   821     val mangler =
  1075       |> Option.map (fst o fst)
  1074       |> Option.map (fst o fst)
  1076       |> the_default 0;
  1075       |> the_default 0;
  1077   in
  1076   in
  1078     (Scan.optional (OuterParse.name >> (fn "no_typs" => false | s => Scan.fail_with (fn _ => "illegal flag: " ^ quote s) true)) true
  1077     (Scan.optional (OuterParse.name >> (fn "no_typs" => false | s => Scan.fail_with (fn _ => "illegal flag: " ^ quote s) true)) true
  1079     #-> (fn with_typs => parse_multi_file ((K o K) NONE) "hs" (serializer with_typs)))
  1078     #-> (fn with_typs => parse_multi_file ((K o K) NONE) "hs" (serializer with_typs)))
  1080     >> (fn (seri) => fn (class_syntax, tyco_syntax, const_syntax) => seri 
       
  1081          (class_syntax, tyco_syntax, const_syntax))
       
  1082   end;
  1079   end;
  1083 
  1080 
  1084 end; (* local *)
  1081 end; (* local *)
  1085 
  1082 
  1086 
  1083