diff --git a/src/stages/adt_generator/amodule.ml b/src/stages/adt_generator/amodule.ml index 8de6bdb5e..ad8035380 100644 --- a/src/stages/adt_generator/amodule.ml +++ b/src/stages/adt_generator/amodule.ml @@ -1,3 +1,5 @@ +(* open Amodule_utils *) + type root = | A of rootA | B of rootB diff --git a/src/stages/adt_generator/generator.raku b/src/stages/adt_generator/generator.raku index 71ab1286e..f3a5ec6ca 100644 --- a/src/stages/adt_generator/generator.raku +++ b/src/stages/adt_generator/generator.raku @@ -10,8 +10,13 @@ sub poly { $^type_name } my $l = @*ARGS[0].IO.lines; $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.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: { my $ll = $_; @@ -131,8 +136,10 @@ my $adts = (map -> (:$name , :$kind, :@ctorsOrFields) { say "(* This is an auto-generated file. Do not edit. *)"; say ""; +for $statements -> $statement { + say "$statement" +} say "open $moduleName"; -say "open {$moduleName}_utils"; say "module Adt_info = Generic.Adt_info"; say "";