Skip to content

Commit 4d0bcea

Browse files
authored
Merge pull request #600 from proux01/accumulate_db_from_file
Enable loading db from files
2 parents 363f4dc + 45bea50 commit 4d0bcea

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ In order to load Coq-Elpi use `From elpi Require Import elpi`.
181181
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands).
182182
- `Elpi Program <qname> <code>` lower level primitive letting one crate a
183183
command/tactic with a custom preamble `<code>`.
184-
- `From some.load.path Extra Dependency "filename" as <fname>`.
185-
- `Elpi Accumulate [<qname>] [<code>|File <fname>|Db <dbname>]`
186-
adds code to the current program (or `<qname>` if specified).
184+
- `From some.load.path Extra Dependency <filename> as <fname>`.
185+
- `Elpi Accumulate [<dbname>|<qname>] [<code>|File <fname>|Db <dbname>]`
186+
adds code to the current program (or `<dbname>` or `<qname>` if specified).
187187
The code can be verbatim, from a file or a Db.
188+
File names `<fname>` must have been previously declared with the above command.
188189
It understands the `#[skip="rex"]` and `#[only="rex"]` which make the command
189190
a no op if the Coq version is matched (or not) by the given regular expression.
190-
File names `<fname>` must have been previously declared with the above command.
191191
It understands the `#[phase]` attribute, see [synterp-vs-interp](README.md#separation-of-parsing-from-execution-of-vernacular-commands)
192192
- `Elpi Typecheck [<qname>]` typechecks the current program (or `<qname>` if
193193
specified).

src/coq_elpi_vernacular.ml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,31 @@ let run_in_program ?(program = current_program ()) ?(st_setup=fun x -> x) (loc,
318318
str" is unknown; please add a directive like 'From .. Extra Dependency .. as " ++
319319
Names.Id.print id ++ str"'.")) in
320320
try
321-
let new_src_ast = List.map (fun fname ->
322-
File {
323-
fname;
324-
fast = P.unit_from_file ~elpi fname;
325-
}) s in
321+
let new_src_ast = List.map (fun fname -> P.unit_from_file ~elpi fname) s in
322+
if P.db_exists program then
323+
P.accumulate_to_db program new_src_ast [] ~scope:Coq_elpi_utils.Regular
324+
else
325+
let new_src_ast = List.map2 (fun fname funit ->
326+
File {
327+
fname;
328+
fast = funit;
329+
}) s new_src_ast in
326330
P.accumulate program new_src_ast
327331
with Failure s -> CErrors.user_err Pp.(str s)
328332
let accumulate_extra_deps ~atts:(only,ph) ?program ids = skip ~only ~ph (accumulate_extra_deps ?program) ids
329333

330334
let accumulate_files ?(program=current_program()) s =
331335
let elpi = P.ensure_initialized () in
332336
try
333-
let new_src_ast = List.map (fun fname ->
334-
File {
335-
fname;
336-
fast = P.unit_from_file ~elpi fname;
337-
}) s in
337+
let new_src_ast = List.map (fun fname -> P.unit_from_file ~elpi fname) s in
338+
if P.db_exists program then
339+
P.accumulate_to_db program new_src_ast [] ~scope:Coq_elpi_utils.Regular
340+
else
341+
let new_src_ast = List.map2 (fun fname funit ->
342+
File {
343+
fname;
344+
fast = funit;
345+
}) s new_src_ast in
338346
P.accumulate program new_src_ast
339347
with Failure s -> CErrors.user_err Pp.(str s)
340348
let accumulate_files ~atts:(only,ph) ?program s = skip ~only ~ph (accumulate_files ?program) s

0 commit comments

Comments
 (0)