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,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45c34f37f4dc2347,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-26 10:55:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: "Vincent Smeets" Newsgroups: comp.lang.ada Subject: Overloading one instance of a dispatching function Date: Thu, 26 Sep 2002 19:52:42 +0200 Organization: T-Online Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 1033062855 04 4953 MMfybA1SS8FzzO 020926 17:54:15 X-Complaints-To: abuse@t-online.com X-Sender: 05931805-0008@t-dialin.net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:29359 Date: 2002-09-26T19:52:42+02:00 List-Id: Hallo, I am trying to make an implementation of the ABNF syntax defined in RFC2234. It defines rules for parsing mail messages. Here are some examples: BIT = "0" / "1" ; Character "0" or character "1" CRLF = CR LF ; Rule CR followed by rule LF X = BIT / CRLF ; Rule BIT or rule CRLF I have added my source code so far. A rule is implemented as an tagged type, a character rule as a Character_Set and an alternation of rules by a record with class wide pointers. The "or"-operation for two rules works OK, but I want to optimize the case that the "or"-opration is used for two Character_Set's. This case can produce a new Character_Set with the characters from both Character_Set's. I have tryed to solve this problem by adding a function to the specification: function "or" (Left, Right : in Character_Set) return Character_Set; This gives a problem at the place where I am using the "or"-operator. The compiler can't resolve which "or"-operator has to be used because both "or"-operators match by type. I would suspect (and hoped) that an exact type (like Character_Set) had an higher precedance than a class wide type (like Rule'Class), but it isn't. :-( How can I solve this problem? I would like to optimize the "or" for two Character_Set's but don't want to require that the user has to classify which "or" he will use. Thanks, Vincent PS: This is no homework. See news:ajrisv$lc9$03$1@news.t-online.com ---------------------------------------------------------------------------- with Ada.Finalization; with Ada.Strings.Maps; with Ada.Strings.Unbounded; package ABNF is type Rule is abstract tagged private; type Alternative is abstract new Rule with private; function "or" (Left, Right : in Rule'Class) return Alternative'Class; type Character_Set is new Alternative with private; function "or" (Left, Right : in Character_Set) return Character_Set; function To_Rule (Item : in Character) return Character_Set; type Concatination is new Rule with private; function "and" (Left, Right : in Rule'Class) return Concatination; private type Rule is abstract new Ada.Finalization.Controlled with null record; type Rule_Access is access Rule'Class; type Alternative is abstract new Rule with null record; type Alternative_Rule is new Alternative with record Left, Right : Rule_Access; end record; -- procedure Adjust (Item : in out Alternative_Rule); -- procedure Finalize (Item : in out Alternative_Rule); type Character_Set is new Alternative with record Set : Ada.Strings.Maps.Character_Set; end record; type Concatination is new Rule with record Left, Right : Rule_Access; end record; -- procedure Adjust (Item : in out Concatination); -- procedure Finalize (Item : in out Concatination); end ABNF; ---------------------------------------------------------------------------- with ABNF; pragma Elaborate_All (ABNF); procedure Forward_PGP is use ABNF; A : constant ABNF.Rule'Class := ABNF.To_Rule ('a') or ABNF.To_Rule ('A'); AB : constant ABNF.Rule'Class := A and ABNF.To_Rule ('b'); AC : constant ABNF.Rule'Class := A and ABNF.To_Rule ('C'); AB_AC : constant ABNF.Rule'Class := AB or AC; begin null; end Forward_PGP;