376 fun args_of_ctr_spec (_, args) = args; |
376 fun args_of_ctr_spec (_, args) = args; |
377 |
377 |
378 val code_plugin = Plugin_Name.declare_setup @{binding code}; |
378 val code_plugin = Plugin_Name.declare_setup @{binding code}; |
379 |
379 |
380 fun prepare_free_constructors kind prep_plugins prep_term |
380 fun prepare_free_constructors kind prep_plugins prep_term |
381 ((((raw_plugins, discs_sels), raw_case_binding), ctr_specs), |
381 ((((raw_plugins, discs_sels), raw_case_binding), ctr_specs), sel_default_eqs) no_defs_lthy = |
382 sel_default_eqs) no_defs_lthy = |
|
383 let |
382 let |
384 val plugins = prep_plugins no_defs_lthy raw_plugins; |
383 val plugins = prep_plugins no_defs_lthy raw_plugins; |
385 |
|
386 |
384 |
387 (* TODO: sanity checks on arguments *) |
385 (* TODO: sanity checks on arguments *) |
388 |
386 |
389 val raw_ctrs = map ctr_of_ctr_spec ctr_specs; |
387 val raw_ctrs = map ctr_of_ctr_spec ctr_specs; |
390 val raw_disc_bindings = map disc_of_ctr_spec ctr_specs; |
388 val raw_disc_bindings = map disc_of_ctr_spec ctr_specs; |
391 val raw_sel_bindingss = map args_of_ctr_spec ctr_specs; |
389 val raw_sel_bindingss = map args_of_ctr_spec ctr_specs; |
392 |
390 |
393 val n = length raw_ctrs; |
391 val n = length raw_ctrs; |
394 val ks = 1 upto n; |
392 val ks = 1 upto n; |
395 |
393 |
396 val _ = if n > 0 then () else error "No constructors specified"; |
394 val _ = n > 0 orelse error "No constructors specified"; |
397 |
395 |
398 val ctrs0 = map (prep_term no_defs_lthy) raw_ctrs; |
396 val ctrs0 = map (prep_term no_defs_lthy) raw_ctrs; |
399 |
397 |
400 val Type (fcT_name, As0) = body_type (fastype_of (hd ctrs0)); |
398 val Type (fcT_name, As0) = body_type (fastype_of (hd ctrs0)); |
401 val fc_b_name = Long_Name.base_name fcT_name; |
399 val fc_b_name = Long_Name.base_name fcT_name; |
1125 val default_ctr_options : ctr_options = (Plugin_Name.default_filter, false); |
1123 val default_ctr_options : ctr_options = (Plugin_Name.default_filter, false); |
1126 val default_ctr_options_cmd : ctr_options_cmd = (K Plugin_Name.default_filter, false); |
1124 val default_ctr_options_cmd : ctr_options_cmd = (K Plugin_Name.default_filter, false); |
1127 |
1125 |
1128 val parse_ctr_options = |
1126 val parse_ctr_options = |
1129 Scan.optional (@{keyword "("} |-- Parse.list1 |
1127 Scan.optional (@{keyword "("} |-- Parse.list1 |
1130 (Plugin_Name.parse_filter >> (apfst o K) || |
1128 (Plugin_Name.parse_filter >> (apfst o K) |
1131 Parse.reserved "discs_sels" >> (apsnd o K o K true)) --| |
1129 || Parse.reserved "discs_sels" >> (apsnd o K o K true)) --| |
1132 @{keyword ")"} |
1130 @{keyword ")"} |
1133 >> (fn fs => fold I fs default_ctr_options_cmd)) |
1131 >> (fn fs => fold I fs default_ctr_options_cmd)) |
1134 default_ctr_options_cmd; |
1132 default_ctr_options_cmd; |
1135 |
1133 |
1136 fun parse_ctr_spec parse_ctr parse_arg = |
1134 fun parse_ctr_spec parse_ctr parse_arg = |