AAda Compiler Token Position

17
Jan
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
81
82
83
84
85
86
87
88
89
90
91
-- Define the exact location where such and such token was found
with aada_vstrings;
 
package aada_compiler_token_position is
  -- most of the page sizes have a minimum and maximum
  page_size_limits_error: exception;
 
  -- page sizes
  type page_sizes_type is private;
  minimum_page_width: constant := 20;
  minimum_page_height: constant := 20;
  minimum_tab_size: constant := 2;
  -- maximum tab size is the page width/height divided by 2
  type page_sizes_field is (page_width, page_height, horizontal_tab, vertical_tab);
 
  -- token positions
  --
  -- each token has a position as defined by this type, the position
  -- includes the file name, line number, horizontal character position
  -- and corresponding page positions
  type position_type is range 0 .. 999_999_999;
  type token_position_type is private;
  type token_position_field is (character, line_character,
                                   line, page_line, page);
 
  -- page sizes functions
  procedure set_page_size(page_sizes: in out page_sizes_type;
                          page_width: in position_type;
                          page_height: in position_type;
                          horizontal_tab: in position_type;
                          vertical_tab: in position_type);
 
  function get_size(page_sizes: in page_sizes_type;
                    parameter: in page_sizes_field := horizontal_tab)
                                            return position_type;
 
  -- position functions
  procedure initialize_position(position: out token_position_type;
                                filename: in aada_vstrings.vstring);
 
  procedure next_page(page_sizes: in out page_sizes_type;
                      position: in out token_position_type);
 
  procedure next_line(page_sizes: in out page_sizes_type;
                      position: in out token_position_type;
                      count: in position_type := 1);
 
  procedure next_character(page_sizes: in out page_sizes_type;
                           position: in out token_position_type;
                           count: in position_type := 1);
 
  function get_position_filename(position: in token_position_type)
                                            return aada_vstrings.vstring;
 
  function get_position(position: in token_position_type;
                        parameter: in token_position_field := line)
                                            return position_type;
 
private
 
  type page_sizes_type is
    record
      page_width: position_type := 80;
      page_height: position_type := 120;
      horizontal_tab: position_type := 8;
      vertical_tab: position_type := 8;
    end record;
 
  type token_position_type is
    record
      filename: aada_vstrings.vstring;
 
      -- character count (exact character, all count as 1)
      character: position_type := 1;
 
      -- character count (WARNING: tabs (16#09#) realign the position to a multiple of 8)
      line_character: position_type := 1;
 
      -- line number (this is the exact text line position as per all code editor)
      line: position_type := 1;
 
      -- page line number (WARNING: vertical tabs (16#0B#) realign the position)
      page_line: position_type := 1;
 
      -- page number (WARNING: 16#0C#, 16#85# and "pragma page;" affect this position)
      page: position_type := 1;
    end record;
 
end aada_compiler_token_position;
 
-- vim: ts=2 sw=2 et syntax=ada
Project aada v1.0-338 (Project id #3)
Process Done (Last compiled on 2012/01/13 01:21:26)
Description Alexis Ada Compiler written in Ada (my first attempt was in C++ which is not correct for an Ada compiler.)
Syndicate content