Natools

Check-in [dd030195a1]
Login
Overview
Comment:s_expressions-enumeration_io; new package providing tools to help I/O of enumerations in S-expressions
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dd030195a1c290e7e76db4fed125f9d01e45a59f
User & Date: nat on 2015-05-12 20:52:50
Other Links: manifest | tags
Context
2015-05-13
17:46
s_expressions-enumeration_io-tests: new test suite for S-expression I/O for enumeration values check-in: ef378b3624 user: nat tags: trunk
2015-05-12
20:52
s_expressions-enumeration_io; new package providing tools to help I/O of enumerations in S-expressions check-in: dd030195a1 user: nat tags: trunk
2015-05-03
16:22
s_expressions-printers-tests: use the new Append_String procedure to keep full ocoverage check-in: 3b7e398512 user: nat tags: trunk
Changes

Modified README.md from [50d67b54d8] to [085ee40216].

29
30
31
32
33
34
35

36
37
38
39
40
41
42
      - `Atom_Refs`: common reference-counted atoms
      - `Conditionals`: S-expression boolean expressions about some object
          - `Generic_Evaluate`: Generic boolean expression evaluation framework
          - `Strings`: Boolean expressions on standard strings
      - `Dynamic_Interpreters`: S-expression interpreter with mutable
        commands and callbacks
      - `Encodings`: translators to and from official S-expression encodings

      - `File_Readers`: objects reading a file to an atom or a S-expression
      - `File_Writers`: file-backed S-expression printer
      - `Generic_Caches`: memory container for S-expressions
      - `Interpeter_Loop`: inner loop of S-expression interpreters,
        typically used in static interpreters
      - `Interpreters`: callback-based S-expressions interpreter
      - `Lockable`: interface for S-expressions descriptors that can be







>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
      - `Atom_Refs`: common reference-counted atoms
      - `Conditionals`: S-expression boolean expressions about some object
          - `Generic_Evaluate`: Generic boolean expression evaluation framework
          - `Strings`: Boolean expressions on standard strings
      - `Dynamic_Interpreters`: S-expression interpreter with mutable
        commands and callbacks
      - `Encodings`: translators to and from official S-expression encodings
      - `Enumeration_IO`: tools to help I/O of enumerations in S-expressions
      - `File_Readers`: objects reading a file to an atom or a S-expression
      - `File_Writers`: file-backed S-expression printer
      - `Generic_Caches`: memory container for S-expressions
      - `Interpeter_Loop`: inner loop of S-expression interpreters,
        typically used in static interpreters
      - `Interpreters`: callback-based S-expressions interpreter
      - `Lockable`: interface for S-expressions descriptors that can be

Added src/natools-s_expressions-enumeration_io.adb version [c829293ba9].





































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2015, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

with Ada.Characters.Handling;
with Ada.Strings.Fixed;

package body Natools.S_Expressions.Enumeration_IO is

   function To_Atom (Enumeration_Image : in String) return Atom is
      Result : Atom := S_Expressions.To_Atom (Ada.Strings.Fixed.Translate
        (Enumeration_Image,
         Ada.Characters.Handling.To_Lower'Access));
   begin
      for I in Result'Range loop
         if Result (I) = Character'Pos ('_') then
            Result (I) := Character'Pos ('-');
         end if;
      end loop;

      return Result;
   end To_Atom;


   function To_Image (Data : in Atom) return String is
      Result : String := Ada.Strings.Fixed.Translate
        (To_String (Data),
         Ada.Characters.Handling.To_Upper'Access);
   begin
      for I in Result'Range loop
         if Result (I) = '-' then
            Result (I) := '_';
         end if;
      end loop;

      return Result;
   end To_Image;


   package body Typed_IO is

      function Image (T : Enum) return Atom is
      begin
         return To_Atom (Enum'Image (T));
      end Image;

      function Value (Data : Atom) return Enum is
      begin
         return Enum'Value (To_Image (Data));
      end Value;

   end Typed_IO;

end Natools.S_Expressions.Enumeration_IO;

Added src/natools-s_expressions-enumeration_io.ads version [5a8174aa31].





























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
------------------------------------------------------------------------------
-- Copyright (c) 2015, Natacha Porté                                        --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR  --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES   --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN    --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF  --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.           --
------------------------------------------------------------------------------

------------------------------------------------------------------------------
-- Natools.S_Expressions.Enumeration_IO provides subprograms to help with   --
-- I/O of enumerated type values. It involves mostly the conversion between --
-- Ada-style names (underscore-separated uppercase words) and S-expression  --
-- style (hyphen-separated lowercase words).                                --
------------------------------------------------------------------------------

package Natools.S_Expressions.Enumeration_IO is
   pragma Preelaborate;

   function To_Atom (Enumeration_Image : in String) return Atom;
      --  Convert the output of a 'Image function into a S-expression atom

   function To_Image (Data : in Atom) return String;
      --  Convert an atom into a string similar to 'Image output


   generic
      type Enum is (<>);
   package Typed_IO is

      function Image (T : Enum) return Atom;
         --  Convert an enumeration value into an atom

      function Value (Data : Atom) return Enum;
         --  Convert an atom into an enumeration value

   end Typed_IO;

end Natools.S_Expressions.Enumeration_IO;