ADT generator: add support for open and include

This commit is contained in:
Suzanne Dupéron 2020-04-03 15:20:50 +02:00
parent 516a3a85ff
commit 58fc08b6a7
2 changed files with 11 additions and 2 deletions

View File

@ -1,3 +1,5 @@
(* open Amodule_utils *)
type root = type root =
| A of rootA | A of rootA
| B of rootB | B of rootB

View File

@ -10,8 +10,13 @@ sub poly { $^type_name }
my $l = @*ARGS[0].IO.lines; my $l = @*ARGS[0].IO.lines;
$l = $l.map(*.subst: /^\s+/, ""); $l = $l.map(*.subst: /^\s+/, "");
$l = $l.list.cache;
my $statement_re = /^((\(\*\s+)?(open|include)\s|\[\@\@\@warning\s)/;
my $statements = $l.grep($statement_re);
$l = $l.grep(none $statement_re);
$statements = $statements.map(*.subst(/^\(\*\s+/, '').subst(/\s+\*\)$/, ''));
$l = $l.cache.map(*.subst: /^type\s+/, "\nand "); $l = $l.cache.map(*.subst: /^type\s+/, "\nand ");
$l = $l.join("\n").split(/\nand\s+/).grep(/./); $l = $l.join("\n").subst(/\n+/, "\n").split(/\nand\s+/).grep(/./);
$l = $l.map(*.split("\n")); $l = $l.map(*.split("\n"));
$l = $l.map: { $l = $l.map: {
my $ll = $_; my $ll = $_;
@ -131,8 +136,10 @@ my $adts = (map -> (:$name , :$kind, :@ctorsOrFields) {
say "(* This is an auto-generated file. Do not edit. *)"; say "(* This is an auto-generated file. Do not edit. *)";
say ""; say "";
for $statements -> $statement {
say "$statement"
}
say "open $moduleName"; say "open $moduleName";
say "open {$moduleName}_utils";
say "module Adt_info = Generic.Adt_info"; say "module Adt_info = Generic.Adt_info";
say ""; say "";