From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: A trouble with different instantiations of generic packages Date: Wed, 29 Nov 2017 03:13:24 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: edFHTOfx8phAphItWrZ8cQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.14.10 X-Notice: Filtered by postfilter v. 0.8.2 Xref: reader02.eternal-september.org comp.lang.ada:49232 Date: 2017-11-29T03:13:24+02:00 List-Id: Yes, to use formal generic packages seems a solution. Victor Porton wrote: > This problem appears when I try to "parse" (that is analyze like an > abstract syntax tree) an RDF directed graph. I think similar problem would > appear with a regular file parser. > > I realize that I described the problem domain not very clearly, but I ask > a general question about generic packages, not about parsers specifically. > > I have the following basic generic packages: > > -- Parser for subnodes (identified by Predicate) of Node > generic > type Data_Type (<>) is private; > package Base_Predicate is > > type Base_Predicate_Parser is abstract tagged limited > record > Predicate: URI_Type; > end record; > > not overriding function Parse (Context: Parser_Context_Type'Class; > Parser: Base_Predicate_Parser; > Model: > Model_Type_Without_Finalize'Class; > Node: > Node_Type_Without_Finalize'Class) > return Data_Type is abstract; > > end Base_Predicate; > > -- Parser for a node > generic > type Data_Type (<>) is private; > package Base_Node is > > type Base_Node_Parser is abstract tagged limited > null record; > > not overriding function Parse (Context: Parser_Context_Type'Class; > Parser: Base_Node_Parser; > Model: > Model_Type_Without_Finalize'Class; > Node: > Node_Type_Without_Finalize'Class) > return Data_Type is abstract; > > end Base_Node; > > -- Parser which ensures a node has exactly one subnode (for Predicate) > generic > type Child_Type (<>) is private; > package One_Predicate is > package Node_Parser is new Base_Node(Child_Type); > package Predicate_Parser is new Base_Predicate(Child_Type); > type One_Predicate_Parser is new > Predicate_Parser.Base_Predicate_Parser with > record > Child_Parser: access Node_Parser.Base_Node_Parser'Class; > end record; > overriding function Parse (Context: Parser_Context_Type'Class; > Parser: One_Predicate_Parser; > Model: Model_Type_Without_Finalize'Class; > Node: Node_Type_Without_Finalize'Class) > return Child_Type; > end One_Predicate; > > Then I derive a specific parser like this: > > package Float_Node is new Base_Node(Long_Float); > > type Float_Literal_Parser is new Float_Node.Base_Node_Parser with null > record; > > overriding function Parse (Context: Parser_Context_Type'Class; > Parser: Float_Literal_Parser; > Model: Model_Type_Without_Finalize'Class; > Node: Node_Type_Without_Finalize'Class) > return Long_Float; > > But when I try to create an object of type One_Predicate_Parser with > Float_Literal_Parser child access, it fails because > Float_Node.Base_Node_Parser is not the same (a different instantiation) as > One_Predicate.Node_Parser.Base_Node_Parser. > > What to do? > > Maybe I should use in One_Predicate a package formal generic parameter > like: > > package Node_Parser is new Base_Node(Child_Type); > > ? > > Are there better ways? > -- Victor Porton - http://portonvictor.org