| 1 |
namespace nes { |
| 2 |
|
| 3 |
% Print a namespace |
| 4 |
func print-path list string, (pred i:gref, o:coq.pp). |
| 5 |
print-path Path PP :- std.do! [ |
| 6 |
std.map {std.findall (ns Path _)} (p\ mp\ p = ns _ mp) MPs, |
| 7 |
print.pp-list MPs (print.pp-module Path PP) Out, |
| 8 |
coq.say {coq.pp->string Out}, |
| 9 |
]. |
| 10 |
|
| 11 |
func begin-path. |
| 12 |
begin-path :- coq.replay-synterp-action-group "nes.begin-path". |
| 13 |
|
| 14 |
func end-path. |
| 15 |
end-path :- coq.replay-synterp-action-group "nes.end-path". |
| 16 |
|
| 17 |
func open-path. |
| 18 |
open-path :- coq.replay-synterp-action-group "nes.open-path". |
| 19 |
|
| 20 |
namespace print { |
| 21 |
|
| 22 |
func pp-list list A, (pred i:A, o:coq.pp) -> coq.pp. |
| 23 |
pp-list L F Out :- std.do! [ |
| 24 |
std.map-filter L F PPs, |
| 25 |
Out = coq.pp.box (coq.pp.v 0) {std.intersperse (coq.pp.brk 0 0) PPs}, |
| 26 |
]. |
| 27 |
|
| 28 |
kind context type. |
| 29 |
type context |
| 30 |
list string -> % readable path |
| 31 |
int -> % length of full path |
| 32 |
(pred i:gref, o:coq.pp) -> |
| 33 |
context. |
| 34 |
|
| 35 |
% Hides `aux` modules |
| 36 |
func readable-path context, list string -> list string. |
| 37 |
readable-path (context Prefix N _) FullPath Path :- std.do! [ |
| 38 |
std.drop N FullPath RelPath, |
| 39 |
std.append Prefix RelPath Path, |
| 40 |
]. |
| 41 |
|
| 42 |
func module-context list string, modpath, (pred i:gref, o:coq.pp) -> context. |
| 43 |
module-context Prefix MP PP Ctx :- std.do! [ |
| 44 |
coq.modpath->path MP FullPath, |
| 45 |
Ctx = context Prefix {std.length FullPath} PP, |
| 46 |
]. |
| 47 |
|
| 48 |
func submodule-context context, modpath -> context. |
| 49 |
submodule-context (context _ _ PP as Ctx) MP Ctx' :- std.do! [ |
| 50 |
coq.modpath->path MP FullPath, |
| 51 |
readable-path Ctx FullPath Path, |
| 52 |
Ctx' = context Path {std.length FullPath} PP, |
| 53 |
]. |
| 54 |
|
| 55 |
func pp-module list string, (pred i:gref, o:coq.pp), modpath -> coq.pp. |
| 56 |
pp-module Prefix PP MP Out :- std.do! [ |
| 57 |
pp-module-items {module-context Prefix MP PP} {coq.env.module MP} Out, |
| 58 |
]. |
| 59 |
|
| 60 |
func pp-module-items context, list module-item -> coq.pp. |
| 61 |
pp-module-items Ctx Items Out :- |
| 62 |
pp-list Items (pp-module-item Ctx) Out. |
| 63 |
|
| 64 |
func pp-module-item context, module-item -> coq.pp. |
| 65 |
pp-module-item (context _ _ PP) (gref GR) Out :- PP GR Out, !. |
| 66 |
pp-module-item Ctx (submodule MP Items) Out :- std.do! [ |
| 67 |
pp-module-items {submodule-context Ctx MP} Items Out, |
| 68 |
]. |
| 69 |
pp-module-item Ctx (module-type MTP) Out :- pp-modtypath Ctx MTP Out. |
| 70 |
pp-module-item Ctx (module-type-functor MTP _) Out :- pp-modtypath Ctx MTP Out. |
| 71 |
pp-module-item Ctx (module-functor MP _) Out :- pp-modpath Ctx MP Out. |
| 72 |
|
| 73 |
func pp-path context, string, list string -> coq.pp. |
| 74 |
pp-path Ctx What FullPath Out :- std.do! [ |
| 75 |
readable-path Ctx FullPath Path, |
| 76 |
Out = coq.pp.box coq.pp.h [ |
| 77 |
coq.pp.str What, coq.pp.spc, |
| 78 |
coq.pp.str {std.string.concat "." Path}, |
| 79 |
], |
| 80 |
]. |
| 81 |
|
| 82 |
func pp-modtypath context, modtypath -> coq.pp. |
| 83 |
pp-modtypath Ctx MTP Out :- std.do! [ |
| 84 |
pp-path Ctx "Module Type" {coq.modtypath->path MTP} Out, |
| 85 |
]. |
| 86 |
|
| 87 |
func pp-modpath context, modpath -> coq.pp. |
| 88 |
pp-modpath Ctx MP Out :- std.do! [ |
| 89 |
pp-path Ctx "Module" {coq.modpath->path MP} Out, |
| 90 |
]. |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
} |