| 1 |
-- |
| 2 |
-- Ada reference manual formatter (ARM_Form). |
| 3 |
-- |
| 4 |
-- This subprogram is part of the command processor. |
| 5 |
-- |
| 6 |
-- We use dispatching calls to call the formatter, so the details of |
| 7 |
-- formatting are insulated from the code that reads the source and |
| 8 |
-- determines the details of the text. |
| 9 |
-- |
| 10 |
-- --------------------------------------- |
| 11 |
-- Copyright 2000, 2002, 2004, 2005, 2006, 2007, 2009, 2011, 2019, 2020 |
| 12 |
-- AXE Consultants. All rights reserved. |
| 13 |
-- P.O. Box 1512, Madison WI 53701 |
| 14 |
-- E-Mail: [email protected] |
| 15 |
-- |
| 16 |
-- ARM_Form is free software: you can redistribute it and/or modify |
| 17 |
-- it under the terms of the GNU General Public License version 3 |
| 18 |
-- as published by the Free Software Foundation. |
| 19 |
-- |
| 20 |
-- AXE CONSULTANTS MAKES THIS TOOL AND SOURCE CODE AVAILABLE ON AN "AS IS" |
| 21 |
-- BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, |
| 22 |
-- CAPABILITY, EFFICIENCY, MERCHANTABILITY, OR FUNCTIONING OF THIS TOOL. |
| 23 |
-- IN NO EVENT WILL AXE CONSULTANTS BE LIABLE FOR ANY GENERAL, |
| 24 |
-- CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, |
| 25 |
-- EVEN IF AXE CONSULTANTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 26 |
-- DAMAGES. |
| 27 |
-- |
| 28 |
-- A copy of the GNU General Public License is available in the file |
| 29 |
-- gpl-3-0.txt in the standard distribution of the ARM_Form tool. |
| 30 |
-- Otherwise, see <http://www.gnu.org/licenses/>. |
| 31 |
-- |
| 32 |
-- If the GPLv3 license is not satisfactory for your needs, a commercial |
| 33 |
-- use license is available for this tool. Contact Randy at AXE Consultants |
| 34 |
-- for more information. |
| 35 |
-- |
| 36 |
-- --------------------------------------- |
| 37 |
-- |
| 38 |
-- Edit History: |
| 39 |
-- |
| 40 |
-- 2/10/06 - RLB - Split from base package. |
| 41 |
-- 9/22/06 - RLB - Revised to use Clause_Number_Type, and to support |
| 42 |
-- Subsubclauses. |
| 43 |
-- 10/16/06 - RLB - Added definition of old non-terminals for NT linking. |
| 44 |
-- 2/16/07 - RLB - Added missing code to handle comments here. |
| 45 |
-- 7/31/07 - RLB - Added code to detect duplicated titles. |
| 46 |
-- 12/18/07 - RLB - Added Plain_Annex and associated commands. |
| 47 |
-- 5/06/09 - RLB - Added Labeled_Deleted_xxx. |
| 48 |
-- 5/07/09 - RLB - Changed above to load dead clauses. |
| 49 |
-- 10/18/11 - RLB - Changed to GPLv3 license. |
| 50 |
-- 5/07/20 - RLB - Added additional tracing. |
| 51 |
|
| 52 |
separate(ARM_Format) |
| 53 |
procedure Scan (Format_Object : in out Format_Type; |
| 54 |
File_Name : in String; |
| 55 |
Section_Number : in ARM_Contents.Section_Number_Type; |
| 56 |
Starts_New_Section : in Boolean) is |
| 57 |
-- Scans the contents for File_Name, determining the table of contents |
| 58 |
-- for the section. The results are written to the contents package. |
| 59 |
-- Starts_New_Section is True if the file starts a new section. |
| 60 |
-- Section_Number is the number (or letter) of the section. |
| 61 |
|
| 62 |
type Items is record |
| 63 |
Command : Command_Type; |
| 64 |
Close_Char : Character; -- Ought to be }, ], >, or ). |
| 65 |
Open_Line : String(1..12); -- For debugging only. |
| 66 |
end record; |
| 67 |
Nesting_Stack : array (1 .. 60) of Items; |
| 68 |
Nesting_Stack_Ptr : Natural := 0; |
| 69 |
Saw_a_Section_Header : Boolean := False; |
| 70 |
|
| 71 |
Input_Object : ARM_File.File_Input_Type; |
| 72 |
|
| 73 |
procedure Set_Nesting_for_Command (Command : in Command_Type; |
| 74 |
Param_Ch : in Character) is |
| 75 |
-- Push the command onto the nesting stack. |
| 76 |
begin |
| 77 |
if Nesting_Stack_Ptr < Nesting_Stack'Last then |
| 78 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr + 1; |
| 79 |
Nesting_Stack (Nesting_Stack_Ptr) := |
| 80 |
(Command => Command, |
| 81 |
Close_Char => ARM_Input.Get_Close_Char (Param_Ch), |
| 82 |
Open_Line => (1..12 => ' ')); -- Set below. |
| 83 |
--Ada.Text_IO.Put_Line (" &Stack (" & Command_Type'Image(Command) & "); Close-Char=" & |
| 84 |
-- Nesting_Stack(Nesting_Stack_Ptr).Close_Char); |
| 85 |
Ada.Strings.Fixed.Move (Target => Nesting_Stack (Nesting_Stack_Ptr).Open_Line, |
| 86 |
Source => ARM_File.Line_String (Input_Object), |
| 87 |
Drop => Ada.Strings.Right); |
| 88 |
else |
| 89 |
Ada.Text_IO.Put_Line ("** Nesting stack overflow on line" & ARM_File.Line_String (Input_Object)); |
| 90 |
for I in reverse Nesting_Stack'range loop |
| 91 |
Ada.Text_IO.Put_Line ("-- Command at" & Natural'Image(I) & " has a close char of '" & |
| 92 |
Nesting_Stack (Nesting_Stack_Ptr).Close_Char & "' for " & Command_Type'Image(Nesting_Stack (Nesting_Stack_Ptr).Command)); |
| 93 |
end loop; |
| 94 |
raise Program_Error; |
| 95 |
end if; |
| 96 |
end Set_Nesting_for_Command; |
| 97 |
|
| 98 |
|
| 99 |
procedure Scan_Command_with_Parameter is |
| 100 |
-- Scan the start of a command with a parameter. |
| 101 |
-- The parameter character has been scanned, and |
| 102 |
-- a stack item pushed. |
| 103 |
Title : ARM_Contents.Title_Type; |
| 104 |
Title_Length : Natural; |
| 105 |
|
| 106 |
procedure Get_Change_Version (Is_First : in Boolean; |
| 107 |
Version : out ARM_Contents.Change_Version_Type) is |
| 108 |
-- Get a parameter named "Version", containing a character |
| 109 |
-- representing the version number. |
| 110 |
Ch, Close_Ch : Character; |
| 111 |
begin |
| 112 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 113 |
Param_Name => "Version" & (8..ARM_Input.Command_Name_Type'Last => ' '), |
| 114 |
Is_First => Is_First, |
| 115 |
Param_Close_Bracket => Close_Ch); |
| 116 |
if Close_Ch /= ' ' then |
| 117 |
-- Get the version character: |
| 118 |
ARM_File.Get_Char (Input_Object, Ch); |
| 119 |
Version := ARM_Contents.Change_Version_Type(Ch); |
| 120 |
ARM_File.Get_Char (Input_Object, Ch); |
| 121 |
if Ch /= Close_Ch then |
| 122 |
Ada.Text_IO.Put_Line (" ** Bad close for change version on line " & ARM_File.Line_String (Input_Object)); |
| 123 |
ARM_File.Replace_Char (Input_Object); |
| 124 |
end if; |
| 125 |
-- else no parameter. Weird. |
| 126 |
end if; |
| 127 |
end Get_Change_Version; |
| 128 |
|
| 129 |
begin |
| 130 |
case Nesting_Stack(Nesting_Stack_Ptr).Command is |
| 131 |
when Labeled_Section | Labeled_Section_No_Break | |
| 132 |
Labeled_Annex | Labeled_Informative_Annex | |
| 133 |
Labeled_Normative_Annex | Labeled_Clause | |
| 134 |
Labeled_Subclause | Labeled_Subsubclause => |
| 135 |
-- Load the title into the Title string: |
| 136 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 137 |
Input_Object, |
| 138 |
Nesting_Stack(Nesting_Stack_Ptr).Close_Char, |
| 139 |
Title, Title_Length); |
| 140 |
Title(Title_Length+1 .. Title'Last) := |
| 141 |
(others => ' '); |
| 142 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Subclause then |
| 143 |
Format_Object.Clause_Number := |
| 144 |
(Section => Format_Object.Clause_Number.Section, |
| 145 |
Clause => Format_Object.Clause_Number.Clause, |
| 146 |
Subclause => Format_Object.Clause_Number.Subclause + 1, |
| 147 |
Subsubclause => 0); |
| 148 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Subsubclause then |
| 149 |
Format_Object.Clause_Number.Subsubclause := |
| 150 |
Format_Object.Clause_Number.Subsubclause + 1; |
| 151 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Clause then |
| 152 |
Format_Object.Clause_Number := |
| 153 |
(Section => Format_Object.Clause_Number.Section, |
| 154 |
Clause => Format_Object.Clause_Number.Clause + 1, |
| 155 |
Subclause => 0, Subsubclause => 0); |
| 156 |
elsif Saw_a_Section_Header then |
| 157 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 158 |
ARM_File.Line_String (Input_Object)); |
| 159 |
else |
| 160 |
Saw_a_Section_Header := True; |
| 161 |
Format_Object.Clause_Number := |
| 162 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 163 |
Clause => 0, |
| 164 |
Subclause => 0, Subsubclause => 0); |
| 165 |
end if; |
| 166 |
|
| 167 |
begin |
| 168 |
declare |
| 169 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 170 |
begin |
| 171 |
-- If we get here, this title is already defined. Oops. |
| 172 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 173 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 174 |
ARM_File.Line_String (Input_Object)); |
| 175 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 176 |
end; |
| 177 |
exception |
| 178 |
when ARM_Contents.Not_Found_Error => |
| 179 |
-- OK, not previously defined. |
| 180 |
|
| 181 |
-- Load the title into the contents package: |
| 182 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Subclause then |
| 183 |
ARM_Contents.Add (Title, ARM_Contents.Subclause, |
| 184 |
Format_Object.Clause_Number); |
| 185 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Subsubclause then |
| 186 |
ARM_Contents.Add (Title, ARM_Contents.Subsubclause, |
| 187 |
Format_Object.Clause_Number); |
| 188 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Clause then |
| 189 |
ARM_Contents.Add (Title, ARM_Contents.Clause, |
| 190 |
Format_Object.Clause_Number); |
| 191 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Section or else |
| 192 |
Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Section_No_Break then |
| 193 |
ARM_Contents.Add (Title, ARM_Contents.Section, |
| 194 |
Format_Object.Clause_Number); |
| 195 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Annex then |
| 196 |
ARM_Contents.Add (Title, ARM_Contents.Plain_Annex, |
| 197 |
Format_Object.Clause_Number); |
| 198 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Normative_Annex then |
| 199 |
ARM_Contents.Add (Title, ARM_Contents.Normative_Annex, |
| 200 |
Format_Object.Clause_Number); |
| 201 |
else |
| 202 |
ARM_Contents.Add (Title, ARM_Contents.Informative_Annex, |
| 203 |
Format_Object.Clause_Number); |
| 204 |
end if; |
| 205 |
end; |
| 206 |
|
| 207 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 208 |
--Ada.Text_IO.Put_Line (" &Unstack (Header)"); |
| 209 |
|
| 210 |
when Unnumbered_Section => |
| 211 |
-- Load the title into the Title string: |
| 212 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 213 |
Input_Object, |
| 214 |
Nesting_Stack(Nesting_Stack_Ptr).Close_Char, |
| 215 |
Title, Title_Length); |
| 216 |
Title(Title_Length+1 .. Title'Last) := |
| 217 |
(others => ' '); |
| 218 |
Format_Object.Unnumbered_Section := |
| 219 |
Format_Object.Unnumbered_Section + 1; |
| 220 |
-- This section will be numbered 0.Unnumbered_Section: |
| 221 |
Format_Object.Clause_Number := |
| 222 |
(Section => 0, |
| 223 |
Clause => Format_Object.Unnumbered_Section, |
| 224 |
Subclause => 0, Subsubclause => 0); |
| 225 |
|
| 226 |
begin |
| 227 |
declare |
| 228 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 229 |
begin |
| 230 |
-- If we get here, this title is already defined. Oops. |
| 231 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 232 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 233 |
ARM_File.Line_String (Input_Object)); |
| 234 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 235 |
end; |
| 236 |
exception |
| 237 |
when ARM_Contents.Not_Found_Error => |
| 238 |
-- OK, not previously defined. |
| 239 |
|
| 240 |
-- Load the title into the contents package: |
| 241 |
ARM_Contents.Add (Title, ARM_Contents.Unnumbered_Section, |
| 242 |
Format_Object.Clause_Number); |
| 243 |
end; |
| 244 |
|
| 245 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 246 |
--Ada.Text_IO.Put_Line (" &Unstack (Header)"); |
| 247 |
|
| 248 |
when Labeled_Revised_Annex | |
| 249 |
Labeled_Revised_Informative_Annex | |
| 250 |
Labeled_Revised_Normative_Annex | |
| 251 |
Labeled_Revised_Section | |
| 252 |
Labeled_Revised_Clause | |
| 253 |
Labeled_Revised_Subclause | |
| 254 |
Labeled_Revised_Subsubclause => |
| 255 |
declare |
| 256 |
Old_Title : ARM_Contents.Title_Type; |
| 257 |
Old_Title_Length : Natural; |
| 258 |
Close_Ch : Character; |
| 259 |
Version : ARM_Contents.Change_Version_Type := '0'; |
| 260 |
Initial_Version : ARM_Contents.Change_Version_Type := '0'; |
| 261 |
begin |
| 262 |
Get_Change_Version (Is_First => True, |
| 263 |
Version => Version); |
| 264 |
|
| 265 |
-- Check for the optional "InitialVersion" parameter, |
| 266 |
-- stopping when we reach "New": |
| 267 |
declare |
| 268 |
Which_Param : ARM_Input.Param_Num; |
| 269 |
Ch : Character; |
| 270 |
begin |
| 271 |
-- If there is no InitialVersion command, use the same |
| 272 |
-- version of the rest of the command. |
| 273 |
loop |
| 274 |
ARM_Input.Check_One_of_Parameter_Names (Input_Object, |
| 275 |
Param_Name_1 => "InitialVersion" & (15..ARM_Input.Command_Name_Type'Last => ' '), |
| 276 |
Param_Name_2 => "New" & (4..ARM_Input.Command_Name_Type'Last => ' '), |
| 277 |
Is_First => False, |
| 278 |
Param_Found => Which_Param, |
| 279 |
Param_Close_Bracket => Close_Ch); |
| 280 |
|
| 281 |
if Which_Param = 1 and then Close_Ch /= ' ' then |
| 282 |
-- Found InitialVersion |
| 283 |
ARM_File.Get_Char (Input_Object, Ch); |
| 284 |
Initial_Version := Ch; |
| 285 |
ARM_File.Get_Char (Input_Object, Ch); |
| 286 |
if Ch /= Close_Ch then |
| 287 |
Ada.Text_IO.Put_Line (" ** Bad close for InitialVersion parameter on line " & |
| 288 |
ARM_File.Line_String (Input_Object)); |
| 289 |
ARM_File.Replace_Char (Input_Object); |
| 290 |
end if; |
| 291 |
else -- We found "New" (or an error) |
| 292 |
exit; -- Handling of New is below. |
| 293 |
end if; |
| 294 |
end loop; |
| 295 |
end; |
| 296 |
|
| 297 |
if Close_Ch /= ' ' then |
| 298 |
-- There is a parameter: |
| 299 |
-- Load the new title into the Title string: |
| 300 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 301 |
Input_Object, |
| 302 |
Close_Ch, |
| 303 |
Title, Title_Length); |
| 304 |
Title(Title_Length+1 .. Title'Last) := |
| 305 |
(others => ' '); |
| 306 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 307 |
Param_Name => "Old" & (4..ARM_Input.Command_Name_Type'Last => ' '), |
| 308 |
Is_First => False, |
| 309 |
Param_Close_Bracket => Close_Ch); |
| 310 |
if Close_Ch /= ' ' then |
| 311 |
-- There is a parameter: |
| 312 |
-- Load the new title into the Title string: |
| 313 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 314 |
Input_Object, |
| 315 |
Close_Ch, |
| 316 |
Old_Title, Old_Title_Length); |
| 317 |
Old_Title(Old_Title_Length+1 .. Old_Title'Last) := |
| 318 |
(others => ' '); |
| 319 |
end if; |
| 320 |
end if; |
| 321 |
ARM_File.Get_Char (Input_Object, Close_Ch); |
| 322 |
if Close_Ch /= Nesting_Stack(Nesting_Stack_Ptr).Close_Char then |
| 323 |
Ada.Text_IO.Put_Line (" ** Bad close for Labeled_Revised_(SubClause|Annex) on line " & ARM_File.Line_String (Input_Object)); |
| 324 |
ARM_File.Replace_Char (Input_Object); |
| 325 |
end if; |
| 326 |
|
| 327 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Subclause then |
| 328 |
Format_Object.Clause_Number := |
| 329 |
(Section => Format_Object.Clause_Number.Section, |
| 330 |
Clause => Format_Object.Clause_Number.Clause, |
| 331 |
Subclause => Format_Object.Clause_Number.Subclause + 1, |
| 332 |
Subsubclause => 0); |
| 333 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Subsubclause then |
| 334 |
Format_Object.Clause_Number.Subsubclause := |
| 335 |
Format_Object.Clause_Number.Subsubclause + 1; |
| 336 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Clause then |
| 337 |
Format_Object.Clause_Number := |
| 338 |
(Section => Format_Object.Clause_Number.Section, |
| 339 |
Clause => Format_Object.Clause_Number.Clause + 1, |
| 340 |
Subclause => 0, Subsubclause => 0); |
| 341 |
elsif Saw_a_Section_Header then |
| 342 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 343 |
ARM_File.Line_String (Input_Object)); |
| 344 |
else |
| 345 |
Saw_a_Section_Header := True; |
| 346 |
Format_Object.Clause_Number := |
| 347 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 348 |
Clause => 0, |
| 349 |
Subclause => 0, Subsubclause => 0); |
| 350 |
end if; |
| 351 |
|
| 352 |
begin |
| 353 |
declare |
| 354 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 355 |
begin |
| 356 |
-- If we get here, this title is already defined. Oops. |
| 357 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 358 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 359 |
ARM_File.Line_String (Input_Object)); |
| 360 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 361 |
end; |
| 362 |
exception |
| 363 |
when ARM_Contents.Not_Found_Error => |
| 364 |
-- OK, not previously defined. |
| 365 |
|
| 366 |
-- Load the title into the contents package: |
| 367 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Subclause then |
| 368 |
ARM_Contents.Add (Title, ARM_Contents.Subclause, |
| 369 |
Format_Object.Clause_Number, |
| 370 |
Version => Version); |
| 371 |
ARM_Contents.Add_Old (Old_Title, |
| 372 |
ARM_Contents.Subclause, |
| 373 |
Format_Object.Clause_Number, |
| 374 |
Version => Initial_Version); |
| 375 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Subsubclause then |
| 376 |
ARM_Contents.Add (Title, ARM_Contents.Subsubclause, |
| 377 |
Format_Object.Clause_Number, |
| 378 |
Version => Version); |
| 379 |
ARM_Contents.Add_Old (Old_Title, |
| 380 |
ARM_Contents.Subsubclause, |
| 381 |
Format_Object.Clause_Number, |
| 382 |
Version => Initial_Version); |
| 383 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Clause then |
| 384 |
ARM_Contents.Add (Title, ARM_Contents.Clause, |
| 385 |
Format_Object.Clause_Number, |
| 386 |
Version => Version); |
| 387 |
ARM_Contents.Add_Old (Old_Title, |
| 388 |
ARM_Contents.Clause, |
| 389 |
Format_Object.Clause_Number, |
| 390 |
Version => Initial_Version); |
| 391 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Section then |
| 392 |
ARM_Contents.Add (Title, ARM_Contents.Section, |
| 393 |
Format_Object.Clause_Number, |
| 394 |
Version => Version); |
| 395 |
ARM_Contents.Add_Old (Old_Title, |
| 396 |
ARM_Contents.Section, |
| 397 |
Format_Object.Clause_Number, |
| 398 |
Version => Initial_Version); |
| 399 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Annex then |
| 400 |
ARM_Contents.Add (Title, |
| 401 |
ARM_Contents.Plain_Annex, |
| 402 |
Format_Object.Clause_Number, |
| 403 |
Version => Version); |
| 404 |
ARM_Contents.Add_Old (Old_Title, |
| 405 |
ARM_Contents.Plain_Annex, |
| 406 |
Format_Object.Clause_Number, |
| 407 |
Version => Initial_Version); |
| 408 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Normative_Annex then |
| 409 |
ARM_Contents.Add (Title, |
| 410 |
ARM_Contents.Normative_Annex, |
| 411 |
Format_Object.Clause_Number, |
| 412 |
Version => Version); |
| 413 |
ARM_Contents.Add_Old (Old_Title, |
| 414 |
ARM_Contents.Normative_Annex, |
| 415 |
Format_Object.Clause_Number, |
| 416 |
Version => Initial_Version); |
| 417 |
else -- Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Revised_Informative_Annex then |
| 418 |
ARM_Contents.Add (Title, |
| 419 |
ARM_Contents.Informative_Annex, |
| 420 |
Format_Object.Clause_Number, |
| 421 |
Version => Version); |
| 422 |
ARM_Contents.Add_Old (Old_Title, |
| 423 |
ARM_Contents.Informative_Annex, |
| 424 |
Format_Object.Clause_Number, |
| 425 |
Version => Initial_Version); |
| 426 |
end if; |
| 427 |
end; |
| 428 |
|
| 429 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 430 |
--Ada.Text_IO.Put_Line (" &Unstack (Header)"); |
| 431 |
end; |
| 432 |
|
| 433 |
when Labeled_Added_Annex | |
| 434 |
Labeled_Added_Informative_Annex | |
| 435 |
Labeled_Added_Normative_Annex | |
| 436 |
Labeled_Added_Section | |
| 437 |
Labeled_Added_Clause | |
| 438 |
Labeled_Added_Subclause | |
| 439 |
Labeled_Added_Subsubclause => |
| 440 |
declare |
| 441 |
Ch : Character; |
| 442 |
Version : ARM_Contents.Change_Version_Type := '0'; |
| 443 |
How : ARM_Output.Change_Type; |
| 444 |
use type ARM_Output.Change_Type; |
| 445 |
begin |
| 446 |
Get_Change_Version (Is_First => True, |
| 447 |
Version => Version); |
| 448 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 449 |
Param_Name => "Name" & (5..ARM_Input.Command_Name_Type'Last => ' '), |
| 450 |
Is_First => False, |
| 451 |
Param_Close_Bracket => Ch); |
| 452 |
if Ch /= ' ' then |
| 453 |
-- There is a parameter: |
| 454 |
-- Load the new title into the Title string: |
| 455 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 456 |
Input_Object, |
| 457 |
Ch, |
| 458 |
Title, Title_Length); |
| 459 |
Title(Title_Length+1 .. Title'Last) := |
| 460 |
(others => ' '); |
| 461 |
end if; |
| 462 |
ARM_File.Get_Char (Input_Object, Ch); |
| 463 |
if Ch /= Nesting_Stack(Nesting_Stack_Ptr).Close_Char then |
| 464 |
Ada.Text_IO.Put_Line (" ** Bad close for Labeled_Added_(Sub)Clause on line " & ARM_File.Line_String (Input_Object)); |
| 465 |
ARM_File.Replace_Char (Input_Object); |
| 466 |
end if; |
| 467 |
|
| 468 |
-- Determine the insertion state for this label: |
| 469 |
Calc_Change_Disposition (Format_Object, |
| 470 |
Version => Version, |
| 471 |
Operation => ARM_Output.Insertion, |
| 472 |
Text_Kind => How); |
| 473 |
|
| 474 |
if How = Do_Not_Display_Text then |
| 475 |
null; -- Nothing to display, so we do *not* number it |
| 476 |
-- or insert it into the contents database. |
| 477 |
else |
| 478 |
begin |
| 479 |
declare |
| 480 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 481 |
begin |
| 482 |
-- If we get here, this title is already defined. Oops. |
| 483 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 484 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 485 |
ARM_File.Line_String (Input_Object)); |
| 486 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 487 |
end; |
| 488 |
exception |
| 489 |
when ARM_Contents.Not_Found_Error => |
| 490 |
-- OK, not previously defined. |
| 491 |
|
| 492 |
-- Load the title into the contents package: |
| 493 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Subclause then |
| 494 |
Format_Object.Clause_Number := |
| 495 |
(Section => Format_Object.Clause_Number.Section, |
| 496 |
Clause => Format_Object.Clause_Number.Clause, |
| 497 |
Subclause => Format_Object.Clause_Number.Subclause + 1, |
| 498 |
Subsubclause => 0); |
| 499 |
ARM_Contents.Add (Title, ARM_Contents.Subclause, |
| 500 |
Format_Object.Clause_Number, |
| 501 |
Version => Version); |
| 502 |
ARM_Contents.Add_Old ((others => ' '), |
| 503 |
ARM_Contents.Subclause, |
| 504 |
Format_Object.Clause_Number); |
| 505 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Subsubclause then |
| 506 |
Format_Object.Clause_Number.Subsubclause := |
| 507 |
Format_Object.Clause_Number.Subsubclause + 1; |
| 508 |
ARM_Contents.Add (Title, ARM_Contents.Subsubclause, |
| 509 |
Format_Object.Clause_Number, |
| 510 |
Version => Version); |
| 511 |
ARM_Contents.Add_Old ((others => ' '), |
| 512 |
ARM_Contents.Subsubclause, |
| 513 |
Format_Object.Clause_Number); |
| 514 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Clause then |
| 515 |
Format_Object.Clause_Number := |
| 516 |
(Section => Format_Object.Clause_Number.Section, |
| 517 |
Clause => Format_Object.Clause_Number.Clause + 1, |
| 518 |
Subclause => 0, Subsubclause => 0); |
| 519 |
ARM_Contents.Add (Title, ARM_Contents.Clause, |
| 520 |
Format_Object.Clause_Number, |
| 521 |
Version => Version); |
| 522 |
ARM_Contents.Add_Old ((others => ' '), |
| 523 |
ARM_Contents.Clause, |
| 524 |
Format_Object.Clause_Number); |
| 525 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Section then |
| 526 |
if Saw_a_Section_Header then |
| 527 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 528 |
ARM_File.Line_String (Input_Object)); |
| 529 |
end if; |
| 530 |
Saw_a_Section_Header := True; |
| 531 |
Format_Object.Clause_Number := |
| 532 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 533 |
Clause => 0, |
| 534 |
Subclause => 0, Subsubclause => 0); |
| 535 |
ARM_Contents.Add (Title, |
| 536 |
ARM_Contents.Section, |
| 537 |
Format_Object.Clause_Number, |
| 538 |
Version => Version); |
| 539 |
ARM_Contents.Add_Old ((others => ' '), |
| 540 |
ARM_Contents.Section, |
| 541 |
Format_Object.Clause_Number); |
| 542 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Annex then |
| 543 |
if Saw_a_Section_Header then |
| 544 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 545 |
ARM_File.Line_String (Input_Object)); |
| 546 |
end if; |
| 547 |
Saw_a_Section_Header := True; |
| 548 |
Format_Object.Clause_Number := |
| 549 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 550 |
Clause => 0, |
| 551 |
Subclause => 0, Subsubclause => 0); |
| 552 |
ARM_Contents.Add (Title, |
| 553 |
ARM_Contents.Plain_Annex, |
| 554 |
Format_Object.Clause_Number, |
| 555 |
Version => Version); |
| 556 |
ARM_Contents.Add_Old ((others => ' '), |
| 557 |
ARM_Contents.Plain_Annex, |
| 558 |
Format_Object.Clause_Number); |
| 559 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Normative_Annex then |
| 560 |
if Saw_a_Section_Header then |
| 561 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 562 |
ARM_File.Line_String (Input_Object)); |
| 563 |
end if; |
| 564 |
Saw_a_Section_Header := True; |
| 565 |
Format_Object.Clause_Number := |
| 566 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 567 |
Clause => 0, |
| 568 |
Subclause => 0, Subsubclause => 0); |
| 569 |
ARM_Contents.Add (Title, |
| 570 |
ARM_Contents.Normative_Annex, |
| 571 |
Format_Object.Clause_Number, |
| 572 |
Version => Version); |
| 573 |
ARM_Contents.Add_Old ((others => ' '), |
| 574 |
ARM_Contents.Normative_Annex, |
| 575 |
Format_Object.Clause_Number); |
| 576 |
else -- Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Added_Informative_Annex then |
| 577 |
if Saw_a_Section_Header then |
| 578 |
Ada.Text_IO.Put_Line (" ** Multiple section headers in a file, line " & |
| 579 |
ARM_File.Line_String (Input_Object)); |
| 580 |
end if; |
| 581 |
Saw_a_Section_Header := True; |
| 582 |
Format_Object.Clause_Number := |
| 583 |
(Section => Format_Object.Clause_Number.Section, -- Will be set elsewhere. |
| 584 |
Clause => 0, |
| 585 |
Subclause => 0, Subsubclause => 0); |
| 586 |
ARM_Contents.Add (Title, |
| 587 |
ARM_Contents.Informative_Annex, |
| 588 |
Format_Object.Clause_Number, |
| 589 |
Version => Version); |
| 590 |
ARM_Contents.Add_Old ((others => ' '), |
| 591 |
ARM_Contents.Informative_Annex, |
| 592 |
Format_Object.Clause_Number); |
| 593 |
end if; |
| 594 |
end; |
| 595 |
end if; |
| 596 |
|
| 597 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 598 |
--Ada.Text_IO.Put_Line (" &Unstack (Header)"); |
| 599 |
end; |
| 600 |
|
| 601 |
when Labeled_Deleted_Clause | |
| 602 |
Labeled_Deleted_Subclause | |
| 603 |
Labeled_Deleted_Subsubclause => |
| 604 |
declare |
| 605 |
Ch : Character; |
| 606 |
Version : ARM_Contents.Change_Version_Type := '0'; |
| 607 |
How : ARM_Output.Change_Type; |
| 608 |
use type ARM_Output.Change_Type; |
| 609 |
begin |
| 610 |
Get_Change_Version (Is_First => True, |
| 611 |
Version => Version); |
| 612 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 613 |
Param_Name => "Name" & (5..ARM_Input.Command_Name_Type'Last => ' '), |
| 614 |
Is_First => False, |
| 615 |
Param_Close_Bracket => Ch); |
| 616 |
if Ch /= ' ' then |
| 617 |
-- There is a parameter: |
| 618 |
-- Load the new title into the Title string: |
| 619 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 620 |
Input_Object, |
| 621 |
Ch, |
| 622 |
Title, Title_Length); |
| 623 |
Title(Title_Length+1 .. Title'Last) := |
| 624 |
(others => ' '); |
| 625 |
end if; |
| 626 |
ARM_File.Get_Char (Input_Object, Ch); |
| 627 |
if Ch /= Nesting_Stack(Nesting_Stack_Ptr).Close_Char then |
| 628 |
Ada.Text_IO.Put_Line (" ** Bad close for Labeled_Deleted_(Sub)Clause on line " & ARM_File.Line_String (Input_Object)); |
| 629 |
ARM_File.Replace_Char (Input_Object); |
| 630 |
end if; |
| 631 |
|
| 632 |
-- Determine the insertion state for this label: |
| 633 |
Calc_Change_Disposition (Format_Object, |
| 634 |
Version => Version, |
| 635 |
Operation => ARM_Output.Deletion, |
| 636 |
Text_Kind => How); |
| 637 |
|
| 638 |
--Ada.Text_IO.Put_Line ("Labeled_Deleted disp: " & ARM_Output.Change_Type'Image(How)); |
| 639 |
if How = ARM_Output.None then |
| 640 |
-- Normal text, number normally. |
| 641 |
begin |
| 642 |
declare |
| 643 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 644 |
begin |
| 645 |
-- If we get here, this title is already defined. Oops. |
| 646 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 647 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 648 |
ARM_File.Line_String (Input_Object)); |
| 649 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 650 |
end; |
| 651 |
exception |
| 652 |
when ARM_Contents.Not_Found_Error => |
| 653 |
-- OK, not previously defined. |
| 654 |
|
| 655 |
-- Load the title into the contents package: |
| 656 |
if Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Deleted_Subclause then |
| 657 |
Format_Object.Clause_Number := |
| 658 |
(Section => Format_Object.Clause_Number.Section, |
| 659 |
Clause => Format_Object.Clause_Number.Clause, |
| 660 |
Subclause => Format_Object.Clause_Number.Subclause + 1, |
| 661 |
Subsubclause => 0); |
| 662 |
ARM_Contents.Add (Title, ARM_Contents.Subclause, |
| 663 |
Format_Object.Clause_Number, |
| 664 |
Version => '0'); -- Version here is an insertion version, and this was available from the beginning. |
| 665 |
ARM_Contents.Add_Old ((others => ' '), |
| 666 |
ARM_Contents.Subclause, |
| 667 |
Format_Object.Clause_Number); |
| 668 |
elsif Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Deleted_Subsubclause then |
| 669 |
Format_Object.Clause_Number.Subsubclause := |
| 670 |
Format_Object.Clause_Number.Subsubclause + 1; |
| 671 |
ARM_Contents.Add (Title, ARM_Contents.Subsubclause, |
| 672 |
Format_Object.Clause_Number, |
| 673 |
Version => '0'); |
| 674 |
ARM_Contents.Add_Old ((others => ' '), |
| 675 |
ARM_Contents.Subsubclause, |
| 676 |
Format_Object.Clause_Number); |
| 677 |
else -- Nesting_Stack(Nesting_Stack_Ptr).Command = Labeled_Deleted_Clause then |
| 678 |
Format_Object.Clause_Number := |
| 679 |
(Section => Format_Object.Clause_Number.Section, |
| 680 |
Clause => Format_Object.Clause_Number.Clause + 1, |
| 681 |
Subclause => 0, Subsubclause => 0); |
| 682 |
ARM_Contents.Add (Title, ARM_Contents.Clause, |
| 683 |
Format_Object.Clause_Number, |
| 684 |
Version => '0'); |
| 685 |
ARM_Contents.Add_Old ((others => ' '), |
| 686 |
ARM_Contents.Clause, |
| 687 |
Format_Object.Clause_Number); |
| 688 |
end if; |
| 689 |
end; |
| 690 |
elsif How = ARM_Output.Insertion then |
| 691 |
-- Huh? We're deleting here. |
| 692 |
raise Program_Error; |
| 693 |
elsif How = ARM_Output.Deletion then |
| 694 |
-- We'll just display the header without a number. |
| 695 |
-- But we need to insert it so that x-refs don't |
| 696 |
-- fail. |
| 697 |
begin |
| 698 |
declare |
| 699 |
Ref : constant String := ARM_Contents.Lookup_Clause_Number (Title); |
| 700 |
begin |
| 701 |
-- If we get here, this title is already defined. Oops. |
| 702 |
Ada.Text_IO.Put_Line (" ** Title """ & |
| 703 |
Title(1..Title_Length) & """ is multiply defined on line " & |
| 704 |
ARM_File.Line_String (Input_Object)); |
| 705 |
Ada.Text_IO.Put_Line (" Initial use is for clause " & Ref); |
| 706 |
end; |
| 707 |
exception |
| 708 |
when ARM_Contents.Not_Found_Error => |
| 709 |
-- OK, not previously defined. |
| 710 |
|
| 711 |
-- Load the title into the contents package as a dead clause: |
| 712 |
ARM_Contents.Add (Title, ARM_Contents.Dead_Clause, |
| 713 |
(Section => 0, |
| 714 |
Clause => 1, |
| 715 |
Subclause => 0, |
| 716 |
Subsubclause => 0), |
| 717 |
Version => '0'); |
| 718 |
ARM_Contents.Add_Old ((others => ' '), |
| 719 |
ARM_Contents.Dead_Clause, |
| 720 |
(Section => 0, |
| 721 |
Clause => 1, |
| 722 |
Subclause => 0, |
| 723 |
Subsubclause => 0)); |
| 724 |
end; |
| 725 |
|
| 726 |
elsif How = Do_Not_Display_Text then |
| 727 |
null; -- Nothing to display/number. |
| 728 |
end if; |
| 729 |
|
| 730 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 731 |
--Ada.Text_IO.Put_Line (" &Unstack (Header)"); |
| 732 |
end; |
| 733 |
|
| 734 |
when Syntax_Rule | Added_Syntax_Rule | Deleted_Syntax_Rule => |
| 735 |
-- @Syn{[Tabs=<Tabset>, ]LHS=<Non-terminal>, RHS=<Production>} |
| 736 |
-- @AddedSyn{Version=[<Version>],[Tabs=<Tabset>, ]LHS=<Non-terminal>, RHS=<Production>} |
| 737 |
-- @DeletedSyn{Version=[<Version>],[Tabs=<Tabset>, ]LHS=<Non-terminal>, RHS=<Production>} |
| 738 |
-- We need to index the non-terminal, so we can link to it |
| 739 |
-- later. (If we didn't do this here, we wouldn't be able |
| 740 |
-- to handle forward references.) |
| 741 |
-- We only care about the non-terminal, so we skip the other |
| 742 |
-- parts. |
| 743 |
declare |
| 744 |
Close_Ch, Ch : Character; |
| 745 |
Seen_First_Param : Boolean := False; |
| 746 |
Non_Terminal : String (1..120); |
| 747 |
NT_Len : Natural := 0; |
| 748 |
begin |
| 749 |
if Nesting_Stack(Nesting_Stack_Ptr).Command /= Syntax_Rule then |
| 750 |
-- Get and skip the Version parameter. |
| 751 |
Seen_First_Param := True; |
| 752 |
Get_Change_Version (Is_First => True, |
| 753 |
Version => Ch); |
| 754 |
end if; |
| 755 |
|
| 756 |
-- Peek to see if Tabs parmeter is present, and skip it if |
| 757 |
-- it is: |
| 758 |
ARM_File.Get_Char (Input_Object, Ch); |
| 759 |
ARM_File.Replace_Char (Input_Object); |
| 760 |
if Ch = 'T' or else Ch = 't' then |
| 761 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 762 |
Param_Name => "Tabs" & (5..ARM_Input.Command_Name_Type'Last => ' '), |
| 763 |
Is_First => (not Seen_First_Param), |
| 764 |
Param_Close_Bracket => Close_Ch); |
| 765 |
Seen_First_Param := True; |
| 766 |
if Close_Ch /= ' ' then |
| 767 |
-- Grab the tab string: |
| 768 |
ARM_Input.Skip_until_Close_Char ( |
| 769 |
Input_Object, |
| 770 |
Close_Ch); |
| 771 |
-- else no parameter. Weird. |
| 772 |
end if; |
| 773 |
end if; |
| 774 |
|
| 775 |
-- Get the LHS parameter and save it: |
| 776 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 777 |
Param_Name => "LHS" & (4..ARM_Input.Command_Name_Type'Last => ' '), |
| 778 |
Is_First => (not Seen_First_Param), |
| 779 |
Param_Close_Bracket => Close_Ch); |
| 780 |
if Close_Ch /= ' ' then |
| 781 |
-- Copy over the non-terminal: |
| 782 |
ARM_Input.Copy_to_String_until_Close_Char ( |
| 783 |
Input_Object, |
| 784 |
Close_Ch, |
| 785 |
Non_Terminal, |
| 786 |
NT_Len); |
| 787 |
-- else no parameter. Weird. |
| 788 |
end if; |
| 789 |
|
| 790 |
-- Skip the RHS parameter: |
| 791 |
ARM_Input.Check_Parameter_Name (Input_Object, |
| 792 |
Param_Name => "RHS" & (4..ARM_Input.Command_Name_Type'Last => ' '), |
| 793 |
Is_First => False, |
| 794 |
Param_Close_Bracket => Close_Ch); |
| 795 |
Seen_First_Param := True; |
| 796 |
if Close_Ch /= ' ' then |
| 797 |
-- Grab the tab string: |
| 798 |
ARM_Input.Skip_until_Close_Char ( |
| 799 |
Input_Object, |
| 800 |
Close_Ch); |
| 801 |
-- else no parameter. Weird. |
| 802 |
end if; |
| 803 |
|
| 804 |
declare |
| 805 |
The_Non_Terminal : constant String := |
| 806 |
Ada.Characters.Handling.To_Lower ( |
| 807 |
Get_Current_Item (Format_Object, Input_Object, |
| 808 |
Non_Terminal(1..NT_Len))); -- Handle embedded @Chg. |
| 809 |
The_Old_Non_Terminal : constant String := |
| 810 |
Ada.Characters.Handling.To_Lower ( |
| 811 |
Get_Old_Item (Format_Object, Input_Object, |
| 812 |
Non_Terminal(1..NT_Len))); -- Handle embedded @Chg. |
| 813 |
begin |
| 814 |
if Ada.Strings.Fixed.Index (The_Non_Terminal, "@") /= 0 then |
| 815 |
-- Still embedded commands, do not register. |
| 816 |
Ada.Text_IO.Put_Line ("** Saw Non-Terminal with embedded commands: " & |
| 817 |
Non_Terminal(1..NT_Len) & " in " & Clause_String (Format_Object)); |
| 818 |
elsif The_Non_Terminal = "" then |
| 819 |
null; -- Deleted Non-Terminal, nothing to do. |
| 820 |
else |
| 821 |
-- Save the non-terminal: |
| 822 |
declare |
| 823 |
Link_Target : ARM_Syntax.Target_Type; |
| 824 |
begin |
| 825 |
ARM_Syntax.Add_Non_Terminal |
| 826 |
(NT_Name => The_Non_Terminal, |
| 827 |
For_Clause => Clause_String (Format_Object), |
| 828 |
Link_Target => Link_Target); |
| 829 |
end; |
| 830 |
--Ada.Text_IO.Put_Line ("%% Saw simple Non-Terminal: " & The_Non_Terminal & " in " |
| 831 |
-- & Clause_String (Format_Object)); |
| 832 |
end if; |
| 833 |
if The_Old_Non_Terminal = "" then |
| 834 |
null; -- No old Non-Terminal, nothing to do. |
| 835 |
elsif ARM_Syntax.Non_Terminal_Clause (The_Old_Non_Terminal) /= "" then |
| 836 |
null; -- This non-terminal is already defined; |
| 837 |
-- that presumably is a *new* definition, |
| 838 |
-- we'll use that instead of this one. |
| 839 |
else |
| 840 |
-- Save the non-terminal: |
| 841 |
declare |
| 842 |
Link_Target : ARM_Syntax.Target_Type; |
| 843 |
begin |
| 844 |
ARM_Syntax.Add_Non_Terminal |
| 845 |
(NT_Name => The_Old_Non_Terminal, |
| 846 |
For_Clause => Clause_String (Format_Object), |
| 847 |
Link_Target => Link_Target); |
| 848 |
end; |
| 849 |
--Ada.Text_IO.Put_Line ("%% Saw simple old Non-Terminal: " & The_Old_Non_Terminal & " in " |
| 850 |
-- & Clause_String (Format_Object)); |
| 851 |
end if; |
| 852 |
end; |
| 853 |
end; |
| 854 |
|
| 855 |
when Comment => |
| 856 |
--Ada.Text_IO.Put_Line("Comment with Close=" & Nesting_Stack(Nesting_Stack_Ptr).Close_Char & |
| 857 |
-- " on line " & ARM_File.Line_String (Input_Object)); |
| 858 |
-- Skip the contents of this command. |
| 859 |
ARM_Input.Skip_until_Close_Char (Input_Object, |
| 860 |
Nesting_Stack(Nesting_Stack_Ptr).Close_Char, |
| 861 |
Exit_on_Para_End => False); |
| 862 |
ARM_File.Replace_Char (Input_Object); -- Put the close character back. |
| 863 |
--Ada.Text_IO.Put_Line("Comment done"); |
| 864 |
|
| 865 |
when others => |
| 866 |
null; -- Not in scanner. |
| 867 |
end case; |
| 868 |
end Scan_Command_with_Parameter; |
| 869 |
|
| 870 |
|
| 871 |
procedure Handle_End_of_Command is |
| 872 |
-- Unstack and handle the end of Commands. |
| 873 |
begin |
| 874 |
case Nesting_Stack(Nesting_Stack_Ptr).Command is |
| 875 |
when others => |
| 876 |
-- No special handling needed. |
| 877 |
null; |
| 878 |
end case; |
| 879 |
--Ada.Text_IO.Put_Line (" &Unstack (Normal-"& Command_Type'Image(Nesting_Stack(Nesting_Stack_Ptr).Command) & ")"); |
| 880 |
Nesting_Stack_Ptr := Nesting_Stack_Ptr - 1; |
| 881 |
end Handle_End_of_Command; |
| 882 |
|
| 883 |
|
| 884 |
procedure Scan_Special is |
| 885 |
-- Scan a special command/macro/tab. |
| 886 |
-- These all start with '@'. |
| 887 |
-- @xxxx is a command. It may have parameters delimited by |
| 888 |
-- (), {}, [], or <>. There does not appear to be an escape, so |
| 889 |
-- we don't have to worry about '}' being used in {} brackets, |
| 890 |
-- for example. (Must be a pain to write, though.) |
| 891 |
Command_Name : ARM_Input.Command_Name_Type; |
| 892 |
Ch : Character; |
| 893 |
begin |
| 894 |
ARM_File.Get_Char (Input_Object, Ch); |
| 895 |
if Ch = '\' then |
| 896 |
-- This represents a tab (or the end of centered text). We're |
| 897 |
-- done here. |
| 898 |
return; |
| 899 |
elsif Ch = '=' then |
| 900 |
-- This marks the beginning of centered text. |
| 901 |
-- We're done here. |
| 902 |
return; |
| 903 |
elsif Ch = '^' then |
| 904 |
-- This represented a tab stop (these should have been |
| 905 |
-- deleted from the input). We're done here. |
| 906 |
return; |
| 907 |
elsif Ch = '@' then |
| 908 |
-- This represents @ in the text. We're done here. |
| 909 |
return; |
| 910 |
elsif Ch = ' ' then |
| 911 |
-- This represents a hard space in the text. We're done here. |
| 912 |
return; |
| 913 |
elsif Ch = ';' then |
| 914 |
-- This seems to be an end of command (or substitution) marker. |
| 915 |
-- For instance, it is used in Section 1: |
| 916 |
-- .. the distinction between @ResolutionName@;s and ... |
| 917 |
-- This converts to: |
| 918 |
-- .. the distinction between Name Resolution Rules and ... |
| 919 |
-- Without it, the 's' would append to the command name, and |
| 920 |
-- we would get the wrong command. Thus, it itself does nothing |
| 921 |
-- at all, so we're done here. |
| 922 |
return; |
| 923 |
elsif Ch = '-' then |
| 924 |
-- This represents a subscript. It has an argument. |
| 925 |
ARM_File.Get_Char (Input_Object, Ch); |
| 926 |
if ARM_Input.Is_Open_Char (Ch) then -- Start parameter: |
| 927 |
Set_Nesting_for_Command |
| 928 |
(Command => Unknown, |
| 929 |
Param_Ch => Ch); |
| 930 |
else -- No parameter. Weird. |
| 931 |
ARM_File.Replace_Char (Input_Object); |
| 932 |
end if; |
| 933 |
return; |
| 934 |
elsif Ch = '+' then |
| 935 |
-- This represents a superscript. It has an argument. |
| 936 |
ARM_File.Get_Char (Input_Object, Ch); |
| 937 |
if ARM_Input.Is_Open_Char (Ch) then -- Start parameter: |
| 938 |
Set_Nesting_for_Command |
| 939 |
(Command => Unknown, |
| 940 |
Param_Ch => Ch); |
| 941 |
else -- No parameter. Weird. |
| 942 |
ARM_File.Replace_Char (Input_Object); |
| 943 |
end if; |
| 944 |
return; |
| 945 |
elsif Ch = ':' then |
| 946 |
-- This is a period type marker. We're done here. |
| 947 |
return; |
| 948 |
elsif Ch = '*' then |
| 949 |
-- This is a line break. We're done here. |
| 950 |
return; |
| 951 |
elsif Ch = '|' then |
| 952 |
-- This is a soft line break. We're done here. |
| 953 |
return; |
| 954 |
elsif Ch = '!' then |
| 955 |
-- This is a soft hyphen break. We're done here. |
| 956 |
return; |
| 957 |
elsif Ch = Ascii.LF then |
| 958 |
-- Stand alone '@'. |
| 959 |
-- I now believe this is an error. It appears in |
| 960 |
-- Infosys.MSS, and seems to have something to do with formatting. |
| 961 |
return; |
| 962 |
end if; |
| 963 |
ARM_File.Replace_Char (Input_Object); |
| 964 |
Arm_Input.Get_Name (Input_Object, Command_Name); |
| 965 |
--Ada.Text_IO.Put_Line("Command=" & Command_Name & " Nesting=" & Natural'Image(Nesting_Stack_Ptr)); |
| 966 |
|
| 967 |
ARM_File.Get_Char (Input_Object, Ch); |
| 968 |
if ARM_Input.Is_Open_Char (Ch) then -- Start parameter: |
| 969 |
Set_Nesting_for_Command |
| 970 |
(Command => Command (Ada.Characters.Handling.To_Lower (Command_Name)), |
| 971 |
Param_Ch => Ch); |
| 972 |
Scan_Command_with_Parameter; |
| 973 |
else |
| 974 |
ARM_File.Replace_Char (Input_Object); |
| 975 |
-- We're not interested in commands with no parameters. |
| 976 |
end if; |
| 977 |
end Scan_Special; |
| 978 |
|
| 979 |
begin |
| 980 |
Ada.Text_IO.Put_Line ("-- Scanning " & File_Name); |
| 981 |
begin |
| 982 |
Arm_File.Open (Input_Object, File_Name); |
| 983 |
exception |
| 984 |
when others => |
| 985 |
Ada.Text_IO.Put_Line ("** Unable to open file " & File_Name); |
| 986 |
raise; |
| 987 |
end; |
| 988 |
if Starts_New_Section then |
| 989 |
Format_Object.Clause_Number := (Section => Section_Number, others => 0); |
| 990 |
end if; |
| 991 |
loop |
| 992 |
declare |
| 993 |
Char : Character; |
| 994 |
begin |
| 995 |
ARM_File.Get_Char (Input_Object, Char); |
| 996 |
--Ada.Text_IO.Put_Line("Char=" & Char & " Nesting=" & Natural'Image(Nesting_Stack_Ptr)); |
| 997 |
case Char is |
| 998 |
when '@' => |
| 999 |
Scan_Special; |
| 1000 |
when Ascii.SUB => |
| 1001 |
exit; -- End of file. |
| 1002 |
when others => |
| 1003 |
if Nesting_Stack_Ptr /= 0 and then |
| 1004 |
Nesting_Stack (Nesting_Stack_Ptr).Close_Char /= ' ' and then |
| 1005 |
Nesting_Stack (Nesting_Stack_Ptr).Close_Char = Char then |
| 1006 |
-- Closing a command, remove it from the stack. |
| 1007 |
Handle_End_of_Command; |
| 1008 |
else |
| 1009 |
null; -- Ordinary characters, nothing to do. |
| 1010 |
end if; |
| 1011 |
end case; |
| 1012 |
end; |
| 1013 |
end loop; |
| 1014 |
-- Reached end of the file. |
| 1015 |
Ada.Text_IO.Put_Line (" Lines scanned: " & |
| 1016 |
ARM_File.Line_String (Input_Object)); |
| 1017 |
ARM_File.Close (Input_Object); |
| 1018 |
if Nesting_Stack_Ptr /= 0 then |
| 1019 |
Ada.Text_IO.Put_Line (" ** Unfinished commands detected."); |
| 1020 |
for I in reverse 1 .. Nesting_Stack_Ptr loop |
| 1021 |
Ada.Text_IO.Put_Line (" Open command=" & |
| 1022 |
Nesting_Stack(I).Command'Image & "; Close_Char=" & |
| 1023 |
Nesting_Stack(I).Close_Char & "; Line=" & |
| 1024 |
Nesting_Stack(I).Open_Line); |
| 1025 |
end loop; |
| 1026 |
end if; |
| 1027 |
end Scan; |
| 1028 |
|