Natools

Check-in [b0204e546f]
Login
Overview
Comment:s_expressions-templates-generic_integers: add prefixes and suffixes to rendered numbers
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b0204e546fc637768752e6d046530cbad2b69faf
User & Date: nat on 2014-09-26 21:13:42
Other Links: manifest | tags
Context
2014-09-27
16:30
s_expressions-templates-generic_integers: change prefix and suffix syntax to make shared values clearer check-in: 0c604fe54e user: nat tags: trunk
2014-09-26
21:13
s_expressions-templates-generic_integers: add prefixes and suffixes to rendered numbers check-in: b0204e546f user: nat tags: trunk
2014-09-25
21:29
s_expressions-templates-generic_integers: use ranges instead of discrete values for image maps check-in: c0da1058a5 user: nat tags: trunk
Changes

Modified generated/natools-static_maps-s_expressions-templates-integers-mc.adb from [f99aedd664] to [5ddf184b54].

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
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








-
+


-
+

-
-
-
-
+
+
+
+










-
-
+
+

-
+



with Interfaces; use Interfaces;

package body Natools.Static_Maps.S_Expressions.Templates.Integers.MC is

   P : constant array (0 .. 4) of Natural :=
     (1, 2, 5, 6, 9);

   T1 : constant array (0 .. 4) of Unsigned_8 :=
     (15, 31, 41, 38, 11);
     (0, 40, 7, 12, 15);

   T2 : constant array (0 .. 4) of Unsigned_8 :=
     (10, 33, 15, 23, 26);
     (31, 48, 43, 13, 1);

   G : constant array (0 .. 44) of Unsigned_8 :=
     (0, 0, 0, 0, 5, 17, 14, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 13, 21,
      0, 0, 0, 11, 18, 7, 0, 16, 4, 2, 9, 0, 0, 15, 0, 0, 0, 2, 3, 7, 13, 0,
      1);
   G : constant array (0 .. 48) of Unsigned_8 :=
     (0, 14, 0, 0, 0, 0, 0, 18, 0, 17, 10, 5, 0, 18, 0, 0, 18, 8, 0, 16, 18,
      0, 0, 0, 0, 15, 23, 0, 1, 4, 13, 0, 0, 0, 0, 3, 5, 17, 0, 2, 0, 14, 6,
      0, 10, 21, 0, 0, 0);

   function Hash (S : String) return Natural is
      F : constant Natural := S'First - 1;
      L : constant Natural := S'Length;
      F1, F2 : Natural := 0;
      J : Natural;
   begin
      for K in P'Range loop
         exit when L < P (K);
         J  := Character'Pos (S (P (K) + F));
         F1 := (F1 + Natural (T1 (K)) * J) mod 45;
         F2 := (F2 + Natural (T2 (K)) * J) mod 45;
         F1 := (F1 + Natural (T1 (K)) * J) mod 49;
         F2 := (F2 + Natural (T2 (K)) * J) mod 49;
      end loop;
      return (Natural (G (F1)) + Natural (G (F2))) mod 22;
      return (Natural (G (F1)) + Natural (G (F2))) mod 24;
   end Hash;

end Natools.Static_Maps.S_Expressions.Templates.Integers.MC;

Modified generated/natools-static_maps-s_expressions-templates-integers-t.adb from [dd1c4e859a] to [855c639862].

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







--  Generated at 2014-09-23 18:25:16 +0000 by Natools.Static_Hash_Maps
--  Generated at 2014-09-26 17:52:14 +0000 by Natools.Static_Hash_Maps
--  from src/natools-s_expressions-templates-generic_integers-maps.sx

with Natools.Static_Maps.S_Expressions.Templates.Integers.MC;
with Natools.Static_Maps.S_Expressions.Templates.Integers.AC;
function Natools.Static_Maps.S_Expressions.Templates.Integers.T
  return Boolean is
begin

Modified generated/natools-static_maps-s_expressions-templates-integers-t.ads from [ef4bea0b49] to [a8f540c7ee].

1

2
3
4
5
6

1
2
3
4
5
6
-
+





--  Generated at 2014-09-23 18:25:16 +0000 by Natools.Static_Hash_Maps
--  Generated at 2014-09-26 17:52:14 +0000 by Natools.Static_Hash_Maps
--  from src/natools-s_expressions-templates-generic_integers-maps.sx

function Natools.Static_Maps.S_Expressions.Templates.Integers.T
  return Boolean;
pragma Pure (Natools.Static_Maps.S_Expressions.Templates.Integers.T);

Modified generated/natools-static_maps-s_expressions-templates-integers.adb from [4e1b059c67] to [80f3affc01].

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







--  Generated at 2014-09-23 18:25:16 +0000 by Natools.Static_Hash_Maps
--  Generated at 2014-09-26 17:52:14 +0000 by Natools.Static_Hash_Maps
--  from src/natools-s_expressions-templates-generic_integers-maps.sx

with Natools.Static_Maps.S_Expressions.Templates.Integers.MC;
with Natools.Static_Maps.S_Expressions.Templates.Integers.AC;

package body Natools.Static_Maps.S_Expressions.Templates.Integers is

Modified generated/natools-static_maps-s_expressions-templates-integers.ads from [136f2e7fb6] to [ae0ea47a08].

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

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
-
+
















+

+







--  Generated at 2014-09-23 18:25:16 +0000 by Natools.Static_Hash_Maps
--  Generated at 2014-09-26 17:52:14 +0000 by Natools.Static_Hash_Maps
--  from src/natools-s_expressions-templates-generic_integers-maps.sx

package Natools.Static_Maps.S_Expressions.Templates.Integers is
   pragma Pure;

   type Main_Command is
     (Error,
      Align,
      Align_Center,
      Align_Left,
      Align_Right,
      Base,
      Images,
      Padding,
      Padding_Left,
      Padding_Right,
      Prefix,
      Sign,
      Suffix,
      Width,
      Width_Max,
      Width_Min);

   type Align_Command is (Unknown_Align, Set_Left, Set_Center, Set_Right);

   function Main (Key : String) return Main_Command;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52










53
54
55
56
57
58
59
40
41
42
43
44
45
46








47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







   Map_1_Key_8 : aliased constant String := "image";
   Map_1_Key_9 : aliased constant String := "images";
   Map_1_Key_10 : aliased constant String := "padding";
   Map_1_Key_11 : aliased constant String := "padding-left";
   Map_1_Key_12 : aliased constant String := "left-padding";
   Map_1_Key_13 : aliased constant String := "padding-right";
   Map_1_Key_14 : aliased constant String := "right-padding";
   Map_1_Key_15 : aliased constant String := "sign";
   Map_1_Key_16 : aliased constant String := "signs";
   Map_1_Key_17 : aliased constant String := "width";
   Map_1_Key_18 : aliased constant String := "width-max";
   Map_1_Key_19 : aliased constant String := "max-width";
   Map_1_Key_20 : aliased constant String := "width-min";
   Map_1_Key_21 : aliased constant String := "min-width";
   Map_1_Keys : constant array (0 .. 21) of access constant String
   Map_1_Key_15 : aliased constant String := "prefix";
   Map_1_Key_16 : aliased constant String := "sign";
   Map_1_Key_17 : aliased constant String := "signs";
   Map_1_Key_18 : aliased constant String := "suffix";
   Map_1_Key_19 : aliased constant String := "width";
   Map_1_Key_20 : aliased constant String := "width-max";
   Map_1_Key_21 : aliased constant String := "max-width";
   Map_1_Key_22 : aliased constant String := "width-min";
   Map_1_Key_23 : aliased constant String := "min-width";
   Map_1_Keys : constant array (0 .. 23) of access constant String
     := (Map_1_Key_0'Access,
         Map_1_Key_1'Access,
         Map_1_Key_2'Access,
         Map_1_Key_3'Access,
         Map_1_Key_4'Access,
         Map_1_Key_5'Access,
         Map_1_Key_6'Access,
67
68
69
70
71
72
73
74
75




76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92

93
94
95
96
97
98
99
71
72
73
74
75
76
77


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107







-
-
+
+
+
+















+


+







         Map_1_Key_14'Access,
         Map_1_Key_15'Access,
         Map_1_Key_16'Access,
         Map_1_Key_17'Access,
         Map_1_Key_18'Access,
         Map_1_Key_19'Access,
         Map_1_Key_20'Access,
         Map_1_Key_21'Access);
   Map_1_Elements : constant array (0 .. 21) of Main_Command
         Map_1_Key_21'Access,
         Map_1_Key_22'Access,
         Map_1_Key_23'Access);
   Map_1_Elements : constant array (0 .. 23) of Main_Command
     := (Align,
         Align_Center,
         Align_Center,
         Align_Left,
         Align_Left,
         Align_Right,
         Align_Right,
         Base,
         Images,
         Images,
         Padding,
         Padding_Left,
         Padding_Left,
         Padding_Right,
         Padding_Right,
         Prefix,
         Sign,
         Sign,
         Suffix,
         Width,
         Width_Max,
         Width_Max,
         Width_Min,
         Width_Min);

   Map_2_Key_0 : aliased constant String := "left";

Modified src/natools-s_expressions-templates-generic_integers-maps.sx from [55e2d235de] to [7f19af6f94].

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
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







+

+




















+

+











      Align_Left,
      Align_Right,
      Base,
      Images,
      Padding,
      Padding_Left,
      Padding_Right,
      Prefix,
      Sign,
      Suffix,
      Width,
      Width_Max,
      Width_Min);

   type Align_Command is (Unknown_Align, Set_Left, Set_Center, Set_Right);")

   (Main_Command
      (hash-package Natools.Static_Maps.S_Expressions.Templates.Integers.MC)
      (function Main)
      (not-found Error)
      (nodes
         (Align          align)
         (Align_Center   align-center centered)
         (Align_Left     align-left left-align)
         (Align_Right    align-right right-align)
         (Base           base)
         (Images         image images)
         (Padding        padding)
         (Padding_Left   padding-left left-padding)
         (Padding_Right  padding-right right-padding)
         (Prefix         prefix)
         (Sign           sign signs)
         (Suffix         suffix)
         (Width          width)
         (Width_Max      width-max max-width)
         (Width_Min      width-min min-width)))
   (Align_Command
      (hash-package Natools.Static_Maps.S_Expressions.Templates.Integers.AC)
      (function To_Align_Command)
      (not-found Unknown_Align)
      (nodes
         (Set_Left   left)
         (Set_Center center)
         (Set_Right  right))))

Modified src/natools-s_expressions-templates-generic_integers.adb from [d3dad2b3da] to [449cf22008].

131
132
133
134
135
136
137



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153



154
155
156
157
158
159
160
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166







+
+
+
















+
+
+







            case Arguments.Current_Event is
               when Events.Add_Atom =>
                  State.Set_Right_Padding (Arguments.Current_Atom);
               when others =>
                  null;
            end case;

         when Commands.Prefix =>
            Parse (State.Prefix, Arguments);

         when Commands.Sign =>
            case Arguments.Current_Event is
               when Events.Add_Atom =>
                  State.Set_Positive_Sign (Arguments.Current_Atom);
               when others =>
                  return;
            end case;

            Arguments.Next (Event);
            case Event is
               when Events.Add_Atom =>
                  State.Set_Negative_Sign (Arguments.Current_Atom);
               when others =>
                  null;
            end case;

         when Commands.Suffix =>
            Parse (State.Suffix, Arguments);

         when Commands.Width =>
            case Arguments.Current_Event is
               when Events.Add_Atom =>
                  declare
                     New_Width : constant Width
                       := Width'Value (To_String (Arguments.Current_Atom));
                  begin
544
545
546
547
548
549
550
551
552
553
554
555
556






















557
558
559
560
561
562
563
550
551
552
553
554
555
556


557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589







-
-




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







         if not Template.Positive_Sign.Is_Empty then
            Output.Append (Template.Positive_Sign.Query.Data.all);
         else
            Has_Sign := False;
         end if;
      end if;

      Output.Invert;

      if Has_Sign then
         Length := Length + 1;
      end if;

      Add_Prefix :
      declare
         Cursor : constant Atom_Maps.Cursor
           := Template.Prefix.Find ((Value, Value));
      begin
         if Atom_Maps.Has_Element (Cursor) then
            Output.Append_Reverse (Atom_Maps.Element (Cursor).Query.Data.all);
         end if;
      end Add_Prefix;

      Output.Invert;

      Add_Suffix :
      declare
         Cursor : constant Atom_Maps.Cursor
           := Template.Suffix.Find ((Value, Value));
      begin
         if Atom_Maps.Has_Element (Cursor) then
            Output.Append (Atom_Maps.Element (Cursor).Query.Data.all);
         end if;
      end Add_Suffix;

      if Length > Template.Maximum_Width then
         return Safe_Atom (Template.Overflow_Message, "");
      end if;

      if Length < Template.Minimum_Width then
         declare
            Needed : constant Width := Template.Minimum_Width - Length;
638
639
640
641
642
643
644
































645
646
647
648
649
650
651
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









   procedure Remove_Image (Object : in out Format; Value : in T) is
   begin
      Exclude (Object.Images, (Value, Value));
   end Remove_Image;


   procedure Remove_Prefix
     (Object : in out Format;
      Value : in T) is
   begin
      Remove_Prefix (Object, (Value, Value));
   end Remove_Prefix;


   procedure Remove_Prefix
     (Object : in out Format;
      Values : in Interval) is
   begin
      Set_Prefix (Object, Values, Atom_Refs.Null_Immutable_Reference);
   end Remove_Prefix;


   procedure Remove_Suffix
     (Object : in out Format;
      Value : in T) is
   begin
      Remove_Suffix (Object, (Value, Value));
   end Remove_Suffix;


   procedure Remove_Suffix
     (Object : in out Format;
      Values : in Interval) is
   begin
      Set_Suffix (Object, Values, Atom_Refs.Null_Immutable_Reference);
   end Remove_Suffix;


   procedure Set_Align (Object : in out Format; Value : in Alignment) is
   begin
      Object.Align := Value;
   end Set_Align;


746
747
748
749
750
751
752








































753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768








































769
770
771
772
773
774
775
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







   procedure Set_Positive_Sign
     (Object : in out Format;
      Sign : in Atom) is
   begin
      Set_Positive_Sign (Object, Create (Sign));
   end Set_Positive_Sign;


   procedure Set_Prefix
     (Object : in out Format;
      Value : in T;
      Prefix : in Atom_Refs.Immutable_Reference) is
   begin
      Set_Prefix (Object, (Value, Value), Prefix);
   end Set_Prefix;


   procedure Set_Prefix
     (Object : in out Format;
      Value : in T;
      Prefix : in Atom) is
   begin
      Set_Prefix (Object, Value, Create (Prefix));
   end Set_Prefix;


   procedure Set_Prefix
     (Object : in out Format;
      Values : in Interval;
      Prefix : in Atom_Refs.Immutable_Reference) is
   begin
      if Prefix.Is_Empty then
         Exclude (Object.Prefix, Values);
      else
         Include (Object.Prefix, Values, Prefix);
      end if;
   end Set_Prefix;


   procedure Set_Prefix
     (Object : in out Format;
      Values : in Interval;
      Prefix : in Atom) is
   begin
      Set_Prefix (Object, Values, Create (Prefix));
   end Set_Prefix;


   procedure Set_Right_Padding
     (Object : in out Format;
      Symbol : in Atom_Refs.Immutable_Reference) is
   begin
      Object.Right_Padding := Symbol;
   end Set_Right_Padding;


   procedure Set_Right_Padding
     (Object : in out Format;
      Symbol : in Atom) is
   begin
      Set_Right_Padding (Object, Create (Symbol));
   end Set_Right_Padding;


   procedure Set_Suffix
     (Object : in out Format;
      Value : in T;
      Suffix : in Atom_Refs.Immutable_Reference) is
   begin
      Set_Suffix (Object, (Value, Value), Suffix);
   end Set_Suffix;


   procedure Set_Suffix
     (Object : in out Format;
      Value : in T;
      Suffix : in Atom) is
   begin
      Set_Suffix (Object, Value, Create (Suffix));
   end Set_Suffix;


   procedure Set_Suffix
     (Object : in out Format;
      Values : in Interval;
      Suffix : in Atom_Refs.Immutable_Reference) is
   begin
      if Suffix.Is_Empty then
         Exclude (Object.Suffix, Values);
      else
         Include (Object.Suffix, Values, Suffix);
      end if;
   end Set_Suffix;


   procedure Set_Suffix
     (Object : in out Format;
      Values : in Interval;
      Suffix : in Atom) is
   begin
      Set_Suffix (Object, Values, Create (Suffix));
   end Set_Suffix;


   procedure Set_Symbols
     (Object : in out Format;
      Symbols : in Atom_Arrays.Immutable_Reference) is
   begin
      if not Symbols.Is_Empty and then Symbols.Query.Data.all'Length >= 2 then
         Object.Symbols := Symbols;

Modified src/natools-s_expressions-templates-generic_integers.ads from [2f1d14a3f5] to [82529a82fc].

22
23
24
25
26
27
28

29
30

31
32
33
34
35
36
37
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39







+


+







--   (base "symbol 0" "symbol 1" "symbol 2" ...)                            --
--   (left-padding "symbol")                                                --
--   (image (0 "symbol 0") (2 "symbol 2") ...)                              --
--   (max-width "max width" ["overflow text"])                              --
--   (min-width "min width")                                                --
--   (padding "left-symbol" "right-symbol")                                 --
--   (padding "symbol")                                                     --
--   (prefix (0 "prefix 0") (2 "prefix 2") ...)                             --
--   (right-padding "symbol")                                               --
--   (sign "plus sign" ["minus sign"])                                      --
--   (suffix (0 "suffix 0") (2 "suffix 2") ...)                             --
--   (width "fixed width")                                                  --
--   (width "min width" "max width" ["overflow text"])                      --
-- Top-level atoms are taken as the image for the next number.              --
------------------------------------------------------------------------------

with Ada.Containers.Ordered_Maps;
with Ada.Streams;
197
198
199
200
201
202
203























204
205
206
207
208
209
210























211
212
213
214
215
216
217
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








   procedure Set_Positive_Sign
     (Object : in out Format;
      Sign : in Atom_Refs.Immutable_Reference);
   procedure Set_Positive_Sign
     (Object : in out Format;
      Sign : in Atom);

   procedure Remove_Prefix
     (Object : in out Format;
      Value : in T);
   procedure Set_Prefix
     (Object : in out Format;
      Value : in T;
      Prefix : in Atom_Refs.Immutable_Reference);
   procedure Set_Prefix
     (Object : in out Format;
      Value : in T;
      Prefix : in Atom);
   procedure Remove_Prefix
     (Object : in out Format;
      Values : in Interval);
   procedure Set_Prefix
     (Object : in out Format;
      Values : in Interval;
      Prefix : in Atom_Refs.Immutable_Reference);
   procedure Set_Prefix
     (Object : in out Format;
      Values : in Interval;
      Prefix : in Atom);

   procedure Set_Right_Padding
     (Object : in out Format;
      Symbol : in Atom_Refs.Immutable_Reference);
   procedure Set_Right_Padding
     (Object : in out Format;
      Symbol : in Atom);

   procedure Remove_Suffix
     (Object : in out Format;
      Value : in T);
   procedure Set_Suffix
     (Object : in out Format;
      Value : in T;
      Suffix : in Atom_Refs.Immutable_Reference);
   procedure Set_Suffix
     (Object : in out Format;
      Value : in T;
      Suffix : in Atom);
   procedure Remove_Suffix
     (Object : in out Format;
      Values : in Interval);
   procedure Set_Suffix
     (Object : in out Format;
      Values : in Interval;
      Suffix : in Atom_Refs.Immutable_Reference);
   procedure Set_Suffix
     (Object : in out Format;
      Values : in Interval;
      Suffix : in Atom);

   procedure Set_Symbols
     (Object : in out Format;
      Symbols : in Atom_Arrays.Immutable_Reference);
   procedure Set_Symbols
     (Object : in out Format;
      Expression : in out S_Expressions.Descriptor'Class);
240
241
242
243
244
245
246


247
248
249
288
289
290
291
292
293
294
295
296
297
298
299







+
+



      Left_Padding : Atom_Refs.Immutable_Reference;
      Right_Padding : Atom_Refs.Immutable_Reference;

      Maximum_Width : Width := Width'Last;
      Overflow_Message : Atom_Refs.Immutable_Reference;

      Images : Atom_Maps.Map;
      Prefix : Atom_Maps.Map;
      Suffix : Atom_Maps.Map;
   end record;

end Natools.S_Expressions.Templates.Generic_Integers;