CVS difference for arm/progs/arm_frm.adb

Differences between 1.41 and version 1.42
Log of other versions for file arm/progs/arm_frm.adb

--- arm/progs/arm_frm.adb	2006/02/19 06:44:40	1.41
+++ arm/progs/arm_frm.adb	2006/06/23 04:27:20	1.42
@@ -213,6 +213,7 @@
     --			hyphens.
     --		- RLB - Fixed glossary entries to not display insertions if
     --			the mode would prevent that.
+    --  6/22/06 - RLB - Added non-terminal linking.
 
     type Command_Kind_Type is (Normal, Begin_Word, Parameter);
 
@@ -370,6 +371,7 @@
 		      Display_Index_Entries : in Boolean;
 		      Include_Annotations : in Boolean;
 		      Include_ISO : in Boolean;
+		      Link_Non_Terminals : in Boolean;
 		      Number_Paragraphs : in Boolean;
 		      Examples_Font : in ARM_Output.Font_Family_Type) is
 	-- Initialize an input object. Changes and Change_Version determine
@@ -380,6 +382,8 @@
 	-- text) will be included in the output; otherwise it will not be.
 	-- If Include_ISO is True, ISOOnly text will be included in the output
 	-- (and NotISO text will not); otherwise the reverse is true.
+	-- If Link_Non_Terminals is True, links will be generated for
+	-- each Non_Terminal, linking it to its definition.
 	-- If Number_Paragraphs is true, paragraphs will be numbered (per
 	-- subclause); otherwise they will not be.
 	-- Example_Font specifies the font that examples will be set in.
@@ -389,6 +393,7 @@
 	Format_Object.Display_Index_Entries := Display_Index_Entries;
 	Format_Object.Include_Annotations := Include_Annotations;
 	Format_Object.Include_ISO := Include_ISO;
+	Format_Object.Link_Non_Terminals := Link_Non_Terminals;
 	Format_Object.Number_Paragraphs := Number_Paragraphs;
 	Format_Object.Examples_Font := Examples_Font;
 
@@ -4056,6 +4061,24 @@
 				   Key => Key);
 		    ARM_Output.Index_Target (Output_Object, Key);
 
+		    -- Save the non-terminal:
+		    declare
+			Link_Target : ARM_Syntax.Target_Type;
+		    begin
+			-- Note: This really needs to be done in the *first*
+			-- pass; otherwise forward references don't work.
+			ARM_Syntax.Add_Non_Terminal
+			    (NT_Name => Get_NT,
+			     For_Clause => Clause_String,
+			     Link_Target => Link_Target);
+			if Format_Object.Link_Non_Terminals then
+		            ARM_Output.Local_Target (Output_Object,
+			        Text => "",
+			        Target => Link_Target);
+			-- else don't link.
+			end if;
+		    end;
+
 		    -- Set the font for the "::=". Note that we use @s{}
 		    -- above, so that any font changes in the Non-Terminal
 		    -- (as in a @Chg command) are respected.
@@ -4282,19 +4305,6 @@
 					    Location => Format_Object.Location);
 		    Format_Object.Is_Bold := True;
 
-		when Non_Terminal =>
-		    Check_Paragraph;
-		    ARM_Output.Text_Format (Output_Object,
-					    Bold => Format_Object.Is_Bold,
-					    Italic => Format_Object.Is_Italic,
-					    Font => ARM_Output.Swiss,
-					    Size => Format_Object.Size,
-					    Change => Format_Object.Change,
-				            Version => Format_Object.Current_Change_Version,
-				            Added_Version => Format_Object.Current_Old_Change_Version,
-					    Location => Format_Object.Location);
-		    Format_Object.Font := ARM_Output.Swiss;
-
 		when Example_Text =>
 		    Check_Paragraph;
 		    ARM_Output.Text_Format (Output_Object,
@@ -4355,6 +4365,78 @@
 			end;
 		    end if;
 
+		when Non_Terminal =>
+		    -- @nt{text}
+		    -- This *was* simple, until we added linking.
+		    declare
+			Name : String(1..120);
+			Len : Natural;
+		    begin
+		        ARM_Input.Copy_to_String_until_Close_Char (
+			    Input_Object,
+			    Format_State.Nesting_Stack(Format_State.Nesting_Stack_Ptr).Close_Char,
+			    Name, Len);
+
+		        -- Set the appropriate style:
+		        Check_Paragraph;
+		        ARM_Output.Text_Format (Output_Object,
+					        Bold => Format_Object.Is_Bold,
+					        Italic => Format_Object.Is_Italic,
+					        Font => ARM_Output.Swiss,
+					        Size => Format_Object.Size,
+					        Change => Format_Object.Change,
+				                Version => Format_Object.Current_Change_Version,
+				                Added_Version => Format_Object.Current_Old_Change_Version,
+					        Location => Format_Object.Location);
+			if Ada.Strings.Fixed.Index (Name(1..Len), "@") /= 0 then
+			    -- Embedded commands. Can't make a link here.
+			    -- (Might want to try to handle some of the
+			    -- cases someday, especially @Chg{New=[xxx],....)
+			    declare
+				Org_Font : ARM_Output.Font_Family_Type :=
+				    Format_Object.Font;
+			    begin
+				Format_Object.Font := ARM_Output.Swiss;
+			        ARM_Format.Format (Format_Object,
+					           Name(1..Len),
+					           Output_Object,
+					           Text_Name => "@nt{}",
+					           No_Annotations => False);
+				Format_Object.Font := Org_Font;
+			    end;
+			elsif Format_Object.Link_Non_Terminals then
+			    declare
+				Clause : constant String :=
+				    ARM_Syntax.Non_Terminal_Clause (Name(1..Len));
+				Target : constant ARM_Syntax.Target_Type :=
+				    ARM_Syntax.Non_Terminal_Link_Target (Name(1..Len));
+			    begin
+				if Clause = "" then -- Not found. No link, but error message:
+				    Ada.Text_IO.Put_Line ("  ?? Unknown non-terminal " &
+					Name(1..Len) & " on line " & ARM_Input.Line_String (Input_Object));
+				    ARM_Output.Ordinary_Text (Output_Object, Name(1..Len));
+				else
+				    ARM_Output.Local_Link (Output_Object, Text => Name(1..Len),
+					Target => Target, Clause_Number => Clause);
+				end if;
+			    end;
+			else
+			    ARM_Output.Ordinary_Text (Output_Object, Name(1..Len));
+			end if;
+		        ARM_Output.Text_Format (Output_Object,
+					        Bold => Format_Object.Is_Bold,
+					        Italic => Format_Object.Is_Italic,
+					        Font => Format_Object.Font,
+					        Size => Format_Object.Size,
+					        Change => Format_Object.Change,
+				                Version => Format_Object.Current_Change_Version,
+				                Added_Version => Format_Object.Current_Old_Change_Version,
+					        Location => Format_Object.Location);
+			Format_Object.Last_Non_Space := True;
+		    end;
+		    Format_State.Nesting_Stack_Ptr := Format_State.Nesting_Stack_Ptr - 1;
+--Ada.Text_IO.Put_Line (" &Unstack (Nonterminal)");
+
 		-- Tables:
 		when Table =>
 			-- @table(Columns=<number>,
@@ -5768,7 +5850,25 @@
 				                Version => Format_Object.Current_Change_Version,
 				                Added_Version => Format_Object.Current_Old_Change_Version,
 					        Location => Format_Object.Location);
-			ARM_Output.Ordinary_Text (Output_Object, Name(1..Len));
+			if Format_Object.Link_Non_Terminals then
+			    declare
+				Clause : constant String :=
+				    ARM_Syntax.Non_Terminal_Clause (Name(1..Len));
+				Target : constant ARM_Syntax.Target_Type :=
+				    ARM_Syntax.Non_Terminal_Link_Target (Name(1..Len));
+			    begin
+				if Clause = "" then -- Not found. No link, but error message:
+				    Ada.Text_IO.Put_Line ("  ?? Unknown non-terminal " &
+					Name(1..Len) & " on line " & ARM_Input.Line_String (Input_Object));
+				    ARM_Output.Ordinary_Text (Output_Object, Name(1..Len));
+				else
+				    ARM_Output.Local_Link (Output_Object, Text => Name(1..Len),
+					Target => Target, Clause_Number => Clause);
+				end if;
+			    end;
+			else
+			    ARM_Output.Ordinary_Text (Output_Object, Name(1..Len));
+			end if;
 		        ARM_Output.Text_Format (Output_Object,
 					        Bold => Format_Object.Is_Bold,
 					        Italic => Format_Object.Is_Italic,

Questions? Ask the ACAA Technical Agent