| 1 |
From elpi.apps.NES.elpi Extra Dependency "nes_synterp.elpi" as nes_synterp. |
| 2 |
From elpi.apps.NES.elpi Extra Dependency "nes_interp.elpi" as nes_interp. |
| 3 |
|
| 4 |
From elpi Require Import elpi. |
| 5 |
|
| 6 |
#[phase="both"] Elpi Db NES.db lp:{{ |
| 7 |
|
| 8 |
typeabbrev path (list string). |
| 9 |
|
| 10 |
:index (2) |
| 11 |
pred ns o:list string, o:modpath. |
| 12 |
|
| 13 |
}}. |
| 14 |
|
| 15 |
#[synterp] Elpi Accumulate NES.db lp:{{ |
| 16 |
|
| 17 |
pred open-ns o:string, o:list string. |
| 18 |
:name "open-ns:begin" |
| 19 |
open-ns _ _ :- fail. |
| 20 |
|
| 21 |
}}. |
| 22 |
|
| 23 |
Elpi Command NES.Status. |
| 24 |
#[synterp] Elpi Accumulate Db NES.db. |
| 25 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 26 |
#[synterp] Elpi Accumulate lp:{{ |
| 27 |
|
| 28 |
main _ :- |
| 29 |
coq.say "NES: current namespace" {nes.current-path}, |
| 30 |
std.findall (ns Y_ Z_) NS, |
| 31 |
coq.say "NES: registered namespaces" NS. |
| 32 |
|
| 33 |
}}. |
| 34 |
|
| 35 |
Elpi Export NES.Status. |
| 36 |
|
| 37 |
Elpi Command NES.Begin. |
| 38 |
#[phase="both"] Elpi Accumulate Db NES.db. |
| 39 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 40 |
#[interp] Elpi Accumulate File nes_interp. |
| 41 |
#[synterp] Elpi Accumulate lp:{{ |
| 42 |
|
| 43 |
main [str NS] :- !, nes.begin-path {nes.string->non-empty-ns NS} _. |
| 44 |
main _ :- coq.error "usage: NES.Begin <DotSeparatedPath>". |
| 45 |
|
| 46 |
}}. |
| 47 |
#[interp] Elpi Accumulate lp:{{ main _ :- nes.begin-path. }}. |
| 48 |
|
| 49 |
Elpi Export NES.Begin. |
| 50 |
|
| 51 |
Elpi Command NES.End. |
| 52 |
#[phase="both"] Elpi Accumulate Db NES.db. |
| 53 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 54 |
#[interp] Elpi Accumulate File nes_interp. |
| 55 |
#[synterp] Elpi Accumulate lp:{{ |
| 56 |
|
| 57 |
main [str NS] :- nes.end-path {nes.string->non-empty-ns NS} _. |
| 58 |
main _ :- coq.error "usage: NES.End <DotSeparatedPath>". |
| 59 |
|
| 60 |
}}. |
| 61 |
#[interp] Elpi Accumulate lp:{{ main _ :- nes.end-path. }}. |
| 62 |
|
| 63 |
Elpi Export NES.End. |
| 64 |
|
| 65 |
|
| 66 |
Elpi Command NES.Open. |
| 67 |
#[phase="both"] Elpi Accumulate Db NES.db. |
| 68 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 69 |
#[interp] Elpi Accumulate File nes_interp. |
| 70 |
#[synterp] Elpi Accumulate lp:{{ |
| 71 |
|
| 72 |
main [str NS] :- nes.open-path {nes.resolve NS}. |
| 73 |
main _ :- coq.error "usage: NES.Open <DotSeparatedPath>". |
| 74 |
|
| 75 |
}}. |
| 76 |
#[interp] Elpi Accumulate lp:{{ main _ :- nes.open-path. }}. |
| 77 |
|
| 78 |
Elpi Export NES.Open. |
| 79 |
|
| 80 |
(* List the contents a namespace *) |
| 81 |
Elpi Command NES.List. |
| 82 |
#[phase="both"] Elpi Accumulate Db NES.db. |
| 83 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 84 |
#[interp] Elpi Accumulate File nes_interp. |
| 85 |
#[synterp] Elpi Accumulate lp:{{ |
| 86 |
main-synterp [str NS] (pr DB Path) :- nes.resolve NS Path, std.findall (ns O_ P_) DB. |
| 87 |
}}. |
| 88 |
#[interp] Elpi Accumulate lp:{{ |
| 89 |
pred pp-gref i:gref, o:coq.pp. |
| 90 |
pp-gref GR PP :- coq.term->pp (global GR) PP. |
| 91 |
|
| 92 |
main-interp [str _] (pr DB Path) :- DB => nes.print-path Path pp-gref. |
| 93 |
main _ :- coq.error "usage: NES.List <DotSeparatedPath>". |
| 94 |
|
| 95 |
}}. |
| 96 |
|
| 97 |
Elpi Export NES.List. |
| 98 |
|
| 99 |
(* NES.List with types *) |
| 100 |
Elpi Command NES.Print. |
| 101 |
#[phase="both"] Elpi Accumulate Db NES.db. |
| 102 |
#[synterp] Elpi Accumulate File nes_synterp. |
| 103 |
#[interp] Elpi Accumulate File nes_interp. |
| 104 |
#[synterp] Elpi Accumulate lp:{{ |
| 105 |
main-synterp [str NS] (pr DB Path) :- nes.resolve NS Path, std.findall (ns O_ P_) DB. |
| 106 |
}}. |
| 107 |
Elpi Accumulate lp:{{ |
| 108 |
pred pp-gref i:gref, o:coq.pp. |
| 109 |
pp-gref GR PP :- std.do! [ |
| 110 |
coq.env.typeof GR Ty, |
| 111 |
PP = coq.pp.box (coq.pp.hov 2) [ |
| 112 |
{coq.term->pp (global GR)}, coq.pp.str " :", coq.pp.spc, |
| 113 |
{coq.term->pp Ty}, |
| 114 |
], |
| 115 |
]. |
| 116 |
|
| 117 |
main-interp [str _] (pr DB Path) :- DB => nes.print-path Path pp-gref. |
| 118 |
main _ :- coq.error "usage: NES.Print <DotSeparatedPath>". |
| 119 |
|
| 120 |
}}. |
| 121 |
|
| 122 |
Elpi Export NES.Print. |