Debian Codegraph @

theories/Ltac2/Printf.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 Require Import Ltac2.Message.
12
13 (** This file defines a printf notation for easiness of writing messages *)
14
15 (**
16
17 The built-in "format" notation scope can be used to create well-typed variadic
18 printing commands following a printf-like syntax. The "format" scope parses
19 quoted strings which contain either raw string data or printing
20 specifications. Raw strings will be output verbatim as if they were passed
21 to Ltac2.Message.of_string.
22
23 Printing specifications are of the form
24
25 << '%' type >>
26
27 where the type value defines which kind of arguments will be accepted and
28 how they will be printed. They can take the following values.
29
30 - << i >>: takes an argument of type int and behaves as Message.of_int
31 - << I >>: takes an argument of type ident and behaves as Message.of_ident
32 - << s >>: takes an argument of type string and behaves as Message.of_string
33 - << m >>: takes an argument of type message and prints it unmodified
34 - << t >>: takes an argument of type constr and behaves as Message.of_constr
35 - << a >>: takes two arguments << f >> of type << (unit -> 'a -> message) >>
36 and << x >> of type << 'a >> and behaves as << f () x >>
37 - << A >>: takes two arguments << f >> of type << ('a -> message) >>
38 and << x >> of type << 'a >> and behaves as << f x >>
39 - << % >>: outputs << % >> verbatim
40
41 TODO: add printing modifiers.
42
43 *)
44
45 Ltac2 printf fmt := Format.kfprintf print fmt.
46 Ltac2 fprintf fmt := Format.kfprintf (fun x => x) fmt.
47
48 (** The two following notations are made available when this module is imported.
49
50 - printf will parse a format and generate a function taking the
51 corresponding arguments ant printing the resulting message as per
52 Message.print. In particular when fully applied it has type unit.
53 - fprintf behaves similarly but return the message as a value instead of
54 printing it.
55
56 *)
57
58 Ltac2 Notation "printf" fmt(format) := printf fmt.
59 Ltac2 Notation "fprintf" fmt(format) := fprintf fmt.