-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrejuvenation-pretty_print.ads
80 lines (67 loc) · 3.41 KB
/
rejuvenation-pretty_print.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
with Rejuvenation.Text_Rewrites; use Rejuvenation.Text_Rewrites;
package Rejuvenation.Pretty_Print is
-- TODO: what if we only want to insert (append/prepend) code that
-- should be pretty printed?
-- In that case we have no node (yet) to surround
-- with pretty print section!
-- This functionality support the following flow
-- 1. Enter flags to specify exactly those sections that should be
-- affected by pretty printing.
-- 2. Enter flag at the start of the file to turn pretty printing
-- initially off.
-- 3. Pretty print the sections in the file
-- 4. Remove the flags related to this functionality
--
-- Note: Nesting of pretty print sections is allowed (unlike by GNATpp).
--
-- Note: Since the file might already contain user defined
-- pretty print sections, the provided flags are made unique
-- for this functionality.
--
-- See https://gt3-prod-1.adacore.com/#/tickets/U722-009 :
-- GNATpp requires that the flags must appear on a line by themselves, with
-- nothing preceding except spaces
--
-- To ensure that the pretty print flags appear on a line by themselves,
-- with nothing preceding except spaces,
-- users can't access the flags directly.
procedure Surround_Node_By_Pretty_Print_Section
(T_R : in out Text_Rewrite'Class; Node : Ada_Node'Class);
-- Execute step 1: Surround Node by Pretty Print Section.
-- This function can be called multiple times to surrounded
-- multiple nodes by pretty print sections.
procedure Turn_Pretty_Printing_Initially_Off
(T_R : in out Text_Rewrite_Unit);
-- Execute step 2: Turn pretty print off at start of Text Rewrite
-- A Turn_Pretty_Printing_Initially_Off function should be
-- called exactly once.
procedure Turn_Pretty_Printing_Initially_Off (Filename : String);
-- Execute step 2: Turn pretty print off at start of file
-- A Turn_Pretty_Printing_Initially_Off function should be
-- called exactly once.
procedure Pretty_Print_Sections (Filename : String);
-- Execute step 3: Pretty print sections between the pretty print flags
-- Use the default pretty print options.
-- A Pretty_Print_Sections function should be called exactly once.
procedure Pretty_Print_Sections (Filename : String; Projectname : String);
-- Execute step 3: Pretty print sections between the pretty print flags
-- Use the pretty print options as specified by the project.
-- A Pretty_Print_Sections function should be called exactly once.
procedure Remove_Pretty_Print_Flags (Filename : String);
-- Execute step 4: Remove pretty print flags
-- This function should be called exactly once.
private
Preemable : constant String := "--";
Flag_On : constant String := "!rej_on";
Flag_Off : constant String := "!rej_off";
Lf : constant String := (1 => ASCII.LF);
Pretty_Print_On : constant String := Preemable & Flag_On & Lf;
-- flag to turn PRETTY PRINT on
Pretty_Print_Off : constant String := Preemable & Flag_Off & Lf;
-- flag to turn PRETTY PRINT off
-- needed to work around bugs in gnatpp:
-- an alternative postamble using Cr_Lf iso Lf
Cr_Lf : constant String := ASCII.CR & ASCII.LF;
Alt_Pretty_Print_On : constant String := Preemable & Flag_On & Cr_Lf;
Alt_Pretty_Print_Off : constant String := Preemable & Flag_Off & Cr_Lf;
end Rejuvenation.Pretty_Print;