mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
refactor(plugins): add scope as argument for the apply function
This commit is contained in:
parent
8e3fd34424
commit
6ce6ea8afc
@ -345,7 +345,8 @@ let driver source_file (options : Cli.options) : int =
|
||||
p.Plugin.name;
|
||||
Cli.debug_print "Writing to %s..."
|
||||
(Option.value ~default:"stdout" output_file);
|
||||
p.Plugin.apply output_file prgm type_ordering
|
||||
p.Plugin.apply ~output_file ~scope:options.ex_scope prgm
|
||||
type_ordering
|
||||
| (`Python | `Scalc | `Plugin (Plugin.Scalc _)) as backend -> (
|
||||
let prgm = Scalc.Compile_from_lambda.translate_program prgm in
|
||||
match backend with
|
||||
@ -383,7 +384,8 @@ let driver source_file (options : Cli.options) : int =
|
||||
p.Plugin.name;
|
||||
Cli.debug_print "Writing to %s..."
|
||||
(Option.value ~default:"stdout" output_file);
|
||||
p.Plugin.apply output_file prgm type_ordering)))))));
|
||||
p.Plugin.apply ~output_file ~scope:options.ex_scope prgm
|
||||
type_ordering)))))));
|
||||
0
|
||||
with
|
||||
| Errors.StructuredError (msg, pos) ->
|
||||
|
@ -14,10 +14,17 @@
|
||||
License for the specific language governing permissions and limitations under
|
||||
the License. *)
|
||||
|
||||
type 'ast plugin_apply_fun_typ =
|
||||
output_file:string option ->
|
||||
scope:string option ->
|
||||
'ast ->
|
||||
Scopelang.Dependency.TVertex.t list ->
|
||||
unit
|
||||
|
||||
type 'ast gen = {
|
||||
name : string;
|
||||
extension : string;
|
||||
apply : string option -> 'ast -> Scopelang.Dependency.TVertex.t list -> unit;
|
||||
apply : 'ast plugin_apply_fun_typ;
|
||||
}
|
||||
|
||||
type t =
|
||||
|
@ -16,10 +16,17 @@
|
||||
|
||||
(** {2 catala-facing API} *)
|
||||
|
||||
type 'ast plugin_apply_fun_typ =
|
||||
output_file:string option ->
|
||||
scope:string option ->
|
||||
'ast ->
|
||||
Scopelang.Dependency.TVertex.t list ->
|
||||
unit
|
||||
|
||||
type 'ast gen = {
|
||||
name : string;
|
||||
extension : string;
|
||||
apply : string option -> 'ast -> Scopelang.Dependency.TVertex.t list -> unit;
|
||||
apply : 'ast plugin_apply_fun_typ;
|
||||
}
|
||||
|
||||
type t =
|
||||
@ -41,19 +48,13 @@ module PluginAPI : sig
|
||||
val register_lcalc :
|
||||
name:string ->
|
||||
extension:string ->
|
||||
(string option ->
|
||||
Dcalc.Ast.untyped Lcalc.Ast.program ->
|
||||
Scopelang.Dependency.TVertex.t list ->
|
||||
unit) ->
|
||||
Dcalc.Ast.untyped Lcalc.Ast.program plugin_apply_fun_typ ->
|
||||
unit
|
||||
|
||||
val register_scalc :
|
||||
name:string ->
|
||||
extension:string ->
|
||||
(string option ->
|
||||
Scalc.Ast.program ->
|
||||
Scopelang.Dependency.TVertex.t list ->
|
||||
unit) ->
|
||||
Scalc.Ast.program plugin_apply_fun_typ ->
|
||||
unit
|
||||
end
|
||||
|
||||
|
@ -414,9 +414,11 @@ module To_jsoo = struct
|
||||
end
|
||||
|
||||
let apply
|
||||
(output_file : string option)
|
||||
~(output_file : string option)
|
||||
~(scope : string option)
|
||||
(prgm : 'm Lcalc.Ast.program)
|
||||
(type_ordering : Scopelang.Dependency.TVertex.t list) =
|
||||
let _ = scope in
|
||||
let filename_without_ext_opt =
|
||||
Option.map
|
||||
(fun f -> Filename.basename f |> String.split_on_char '.' |> List.hd)
|
||||
|
@ -23,7 +23,8 @@
|
||||
let name = "python-plugin"
|
||||
let extension = ".py"
|
||||
|
||||
let apply output_file prgm type_ordering =
|
||||
let apply ~output_file ~scope prgm type_ordering =
|
||||
ignore scope;
|
||||
Utils.File.with_formatter_of_opt_file output_file @@ fun fmt ->
|
||||
Scalc.To_python.format_program fmt prgm type_ordering
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user