There's something about polymorphism in Ada that I don't understand. (Or maybe it's the package naming?) I'm trying to parse an XML file using xmlada
library and I followed the example I found in tests for this library that uses Debug_Reader
. Below is the problematic code:
-- cog_cli-xml.adb
with Ada.Strings.Unbounded;
with Sax.Readers;
with Input_Sources.Strings;
with Unicode.CES.Basic_8bit;
with Cog_Cli.Xml_Reader;
with Cog_Cli_Doc;
package body Cog_Cli.Xml is
package Asu renames Ada.Strings.Unbounded;
package Ccxr renames Cog_Cli.Xml_Reader;
package Sr renames Sax.Readers;
package Iss renames Input_Sources.Strings;
package Ccd renames Cog_Cli_Doc;
package U8bit renames Unicode.CES.Basic_8bit;
function Cli_Help (Command : String) return String is
Doc_Reader : Ccxr.Reader;
Input : Iss.String_Input;
Cli_Help : constant Ccd.Content_Type := Ccd.Get_Content ("cli.xml");
begin
Iss.Open (Cli_Help.Content.all,
Encoding => U8bit.Basic_8bit_Encoding,
Input => Input);
Ccxr.Set_Command (Doc_Reader, Command);
Sr.Set_Feature (Doc_Reader, Sr.Namespace_Prefixes_Feature, False);
Sr.Set_Feature (Doc_Reader, Sr.Namespace_Feature, False);
Sr.Set_Feature (Doc_Reader, Sr.Validation_Feature, False);
Sr.Parse (Doc_Reader, Input);
Iss.Close (Input);
return Asu.To_String (Doc_Reader.Help);
end Cli_Help;
end Cog_Cli.Xml;
-- cog_cli-xml_reader.ads
with Sax.Readers;
with Unicode.CES;
with Sax.Attributes;
with Ada.Strings.Unbounded;
package Cog_Cli.Xml_Reader is
package Asu renames Ada.Strings.Unbounded;
type Reader is new Sax.Readers.Reader with private;
procedure Start_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class);
procedure End_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "");
procedure Characters
(Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence);
procedure Set_Command (Handler : in out Reader; Command : String);
procedure Set_Help (Handler : in out Reader; Help : String);
private
type Reader is new Sax.Readers.Reader with record
Command : Asu.Unbounded_String;
Help : Asu.Unbounded_String;
end record;
end Cog_Cli.Xml_Reader;
with Ada.Text_IO;
with Ada.Strings.Unbounded;
package body Cog_Cli.Xml_Reader is
package Ati renames Ada.Text_IO;
package Asu renames with Ada.Strings.Unbounded;
procedure Start_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "";
Atts : Sax.Attributes.Attributes'Class) is
begin
null;
end Start_Element;
procedure Characters
(Handler : in out Reader;
Ch : Unicode.CES.Byte_Sequence) is
begin
null;
end Characters;
procedure End_Element
(Handler : in out Reader;
Namespace_URI : Unicode.CES.Byte_Sequence := "";
Local_Name : Unicode.CES.Byte_Sequence := "";
Qname : Unicode.CES.Byte_Sequence := "") is
begin
null;
end End_Element;
procedure Set_Command (Handler : in out Reader; Command : String) is
begin
Handler.Command := Asu.To_Unbounded_String (Command);
end Set_Command;
procedure Set_Help (Handler : in out Reader; Help : String) is
begin
Handler.Help := Asu.To_Unbounded_String (Help);
end Set_Help;
end Cog_Cli.Xml_Reader;
The problem is that Sr.Set_Feature
doesn't believe that Doc_Reader
is the right type... I have no idea why. The literal error I'm getting is:
cog_cli-xml.adb:27:09: error: no candidate interpretations match the actuals:
cog_cli-xml.adb:27:23: error: expected private type "Readers.Reader" defined at sax-readers.ads:778
cog_cli-xml.adb:27:23: error: found private type "Xml_Reader.Reader" defined at cog_cli-xml_reader.ads:10