| 1 |
package ARM_Input is |
| 2 |
|
| 3 |
-- |
| 4 |
-- Ada reference manual formatter (ARM_Form). |
| 5 |
-- |
| 6 |
-- This package contains the abstract definition of reading an input file |
| 7 |
-- or other entity, and routines to lex the input entities. |
| 8 |
-- |
| 9 |
-- --------------------------------------- |
| 10 |
-- Copyright 2000, 2002, 2004, 2011, 2019 |
| 11 |
-- AXE Consultants. All rights reserved. |
| 12 |
-- P.O. Box 1512, Madison WI 53701 |
| 13 |
-- E-Mail: [email protected] |
| 14 |
-- |
| 15 |
-- ARM_Form is free software: you can redistribute it and/or modify |
| 16 |
-- it under the terms of the GNU General Public License version 3 |
| 17 |
-- as published by the Free Software Foundation. |
| 18 |
-- |
| 19 |
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS" |
| 20 |
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, |
| 21 |
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL. |
| 22 |
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL, |
| 23 |
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, |
| 24 |
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 25 |
-- DAMAGES. |
| 26 |
-- |
| 27 |
-- A copy of the GNU General Public License is available in the file |
| 28 |
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool. |
| 29 |
-- Otherwise, see <http://www.gnu.org/licenses/>. |
| 30 |
-- |
| 31 |
-- If the GPLv3 license is not satisfactory for your needs, a commercial |
| 32 |
-- use license is available for this tool. Contact Randy at AXE Consultants |
| 33 |
-- for more information. |
| 34 |
-- |
| 35 |
-- --------------------------------------- |
| 36 |
-- |
| 37 |
-- Edit History: |
| 38 |
-- |
| 39 |
-- 5/15/00 - RLB - Created base package. |
| 40 |
-- 7/18/02 - RLB - Added Check_One_of_Parameter_Names. |
| 41 |
-- 12/06/04 - RLB - Expanded Check_One_of_Parameter_Names to take up to |
| 42 |
-- five names. |
| 43 |
-- 10/18/11 - RLB - Changed to GPLv3 license. |
| 44 |
-- 2/19/19 - RLB - Added Exit_On_Param_End to Skip_Until_Close_Char. |
| 45 |
|
| 46 |
type Input_Type is abstract tagged limited null record; |
| 47 |
|
| 48 |
MAX_RECORDING_SIZE : constant := 4000; |
| 49 |
|
| 50 |
Not_Valid_Error : exception; -- The Input_Object is not valid. |
| 51 |
|
| 52 |
-- procedure Open (Input_Object : in out Input_Type; |
| 53 |
-- -- Other parameters) is abstract; |
| 54 |
-- Open an input object for an entity. |
| 55 |
-- Each concrete type has its own Open routine, with possibly |
| 56 |
-- different parameters. |
| 57 |
|
| 58 |
procedure Close (Input_Object : in out Input_Type) is abstract; |
| 59 |
-- Close the input object (entity). |
| 60 |
-- May propagate exceptions from the underlying implementation |
| 61 |
-- (that is, I/O exceptions). |
| 62 |
|
| 63 |
procedure Get_Char (Input_Object : in out Input_Type; |
| 64 |
Char : out Character) is abstract; |
| 65 |
-- We represent end of line by Ascii.LF, and end of file by |
| 66 |
-- Ascii.SUB. |
| 67 |
-- Raises: Not_Valid_Error if Input_Object is not valid (open). |
| 68 |
|
| 69 |
procedure Replace_Char (Input_Object : in out Input_Type) is abstract; |
| 70 |
-- Replaces the last character read (with Get_Char); the next call |
| 71 |
-- to Get_Char will return it. |
| 72 |
-- Raises: Not_Valid_Error if Input_Object is not valid (open). |
| 73 |
|
| 74 |
function Line_String (Input_Object : in Input_Type) return String is abstract; |
| 75 |
-- Returns a string representing the line number and entity. |
| 76 |
-- Usually used in error messages. |
| 77 |
-- Raises: Not_Valid_Error if Input_Object is not valid (open). |
| 78 |
|
| 79 |
procedure Start_Recording (Input_Object : in out Input_Type) is abstract; |
| 80 |
-- Start recording all characters read into a local buffer. |
| 81 |
-- Use this when text needs to be formatted into the output |
| 82 |
-- file *and* be saved for future use. |
| 83 |
-- Raises: Not_Valid_Error if Input_Object is not valid (open). |
| 84 |
|
| 85 |
procedure Stop_Recording_and_Read_Result |
| 86 |
(Input_Object : in out Input_Type; Result : out String; |
| 87 |
Len : out Natural) is abstract; |
| 88 |
-- Stop recording characters read. Put the result into Result, |
| 89 |
-- and the number of characters written into Len. |
| 90 |
-- Raises: Not_Valid_Error if Input_Object is not valid (open). |
| 91 |
|
| 92 |
-- Lexical routines: |
| 93 |
|
| 94 |
subtype Command_Name_Type is String (1 .. 40); |
| 95 |
|
| 96 |
function Is_Open_Char (Open_Char : in Character) return Boolean; |
| 97 |
-- Return True if character is a parameter opening character |
| 98 |
-- ('<', '[', '{', '('), and False otherwise. |
| 99 |
|
| 100 |
function Get_Close_Char (Open_Char : in Character) return Character; |
| 101 |
-- Return the parameter closing character for an opening character. |
| 102 |
-- Raises Not_Valid_Error if Open_Char is not an opening character |
| 103 |
-- ('<', '[', '{', '('). |
| 104 |
|
| 105 |
function Get_Open_Char (Close_Char : in Character) return Character; |
| 106 |
-- Return the parameter opening character for an closing character. |
| 107 |
-- Raises Not_Valid_Error if Open_Char is not an closing character |
| 108 |
-- ('>', ']', '}', ')'). |
| 109 |
|
| 110 |
|
| 111 |
procedure Get_Name (Input_Object : in out Input_Type'Class; |
| 112 |
Name : out ARM_Input.Command_Name_Type; |
| 113 |
Null_Name_Allowed : in Boolean := False); |
| 114 |
-- Get a name from the Input_Object. "Names" are sequences of |
| 115 |
-- alphanumeric characters. If Null_Name_Allowed is False, |
| 116 |
-- an error is produced if no name is found. |
| 117 |
|
| 118 |
procedure Copy_to_String_until_Close_Char |
| 119 |
(Input_Object : in out Input_Type'Class; |
| 120 |
Close_Char : in Character; |
| 121 |
Buffer : out String; |
| 122 |
Len : out Natural); |
| 123 |
-- Copy text from Input_Object to Buffer until the matching |
| 124 |
-- Close_Char is found. Len is the number of characters copied. |
| 125 |
-- Use this when we only need a string; use recording when we |
| 126 |
-- need the string *and* we still must process the type. |
| 127 |
|
| 128 |
procedure Skip_until_Close_Char |
| 129 |
(Input_Object : in out Input_Type'Class; |
| 130 |
Close_Char : in Character; |
| 131 |
Exit_On_Para_End : in Boolean := True); |
| 132 |
-- Skip text from Input_Object until the matching Close_Char is found. |
| 133 |
-- Exit this early if there is a paragraph end in the middle if |
| 134 |
-- Exit_On_Para_End is True (otherwise, continue to the end). |
| 135 |
-- This parameter should set to False only for features which are |
| 136 |
-- never going to be part of the result document (like a comment); |
| 137 |
-- otherwise, we maya fail to count paragraphs properly. |
| 138 |
|
| 139 |
procedure Check_Parameter_Name (Input_Object : in out Input_Type'Class; |
| 140 |
Param_Name : in ARM_Input.Command_Name_Type; |
| 141 |
Is_First : in Boolean; |
| 142 |
Param_Close_Bracket : out Character); |
| 143 |
-- Check that the name of a parameter (if any) is Param_Name. |
| 144 |
-- This is the first parameter is Is_First is True; otherwise |
| 145 |
-- it is a later parameter. (For a later parameter, we'll skip |
| 146 |
-- the comma and any whitespace.) |
| 147 |
-- If the parameter has an argument, the opening character will |
| 148 |
-- be read, and the closing character will be returned in |
| 149 |
-- in Param_Close_Bracket. If the parameter wasn't found, an |
| 150 |
-- error message will be produced, and Param_Close_Bracket will |
| 151 |
-- be set to ' '. |
| 152 |
|
| 153 |
subtype Param_Num is Natural range 0 .. 5; |
| 154 |
procedure Check_One_of_Parameter_Names ( |
| 155 |
Input_Object : in out Input_Type'Class; |
| 156 |
Param_Name_1 : in ARM_Input.Command_Name_Type; |
| 157 |
Param_Name_2 : in ARM_Input.Command_Name_Type; |
| 158 |
Param_Name_3 : in ARM_Input.Command_Name_Type := (others => ' '); |
| 159 |
Param_Name_4 : in ARM_Input.Command_Name_Type := (others => ' '); |
| 160 |
Param_Name_5 : in ARM_Input.Command_Name_Type := (others => ' '); |
| 161 |
Is_First : in Boolean; |
| 162 |
Param_Close_Bracket : out Character; |
| 163 |
Param_Found : out Param_Num); |
| 164 |
-- Check that the name of a parameter (if any) is one of the given |
| 165 |
-- names. If the parameter is set to all blanks, it is not used. |
| 166 |
-- This is the first parameter is Is_First is True; |
| 167 |
-- otherwise it is a later parameter. (For a later parameter, we'll |
| 168 |
-- skip the comma and any whitespace.) |
| 169 |
-- Param_Found will be set to the number of the parameter that was |
| 170 |
-- found. |
| 171 |
-- If the parameter has an argument, the opening character will |
| 172 |
-- be read, and the closing character will be returned in |
| 173 |
-- in Param_Close_Bracket. If the parameter wasn't found, an |
| 174 |
-- error message will be produced, Param_Close_Bracket will |
| 175 |
-- be set to ' ', and Param_Found will be set to 0. |
| 176 |
|
| 177 |
end ARM_Input; |