comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Parser interface design
Date: Thu, 7 Apr 2011 22:52:27 +0200
Date: 2011-04-07T22:52:27+02:00	[thread overview]
Message-ID: <33xzyg535kh2$.d718j0i28nn8$.dlg@40tude.net> (raw)
In-Reply-To: slrnips50m.2fnq.lithiumcat@sigil.instinctive.eu

On Thu, 7 Apr 2011 19:44:22 +0000 (UTC), Natasha Kerensikova wrote:

> The direct transposition of my C implementation would be something like
> 
>    type Renderer_Callbacks is record
>       Emphasis:    access function (Contents: String) return String;
>       Normal_Text: access function (Contents: String) return String;
>       Paragraph:   access function (Contents: String) return String;
>    end record;
> 
>    function Parser (Renderer: Renderer_Callbacks; Input: String)
>      return String;

An OO approach:

   type Abstract_Context is abstract
       new Ada.Finalization.Limited_Controlled with private;
   procedure On_Emphasis
             (  Context : in out Abstract_Context;
                Token   : String
             )  is null;
   ...

   type Abstract_Source is abstract ...;
   function Get_Next_Line (Source : in out Abstract_Source)
       return String is abstract;
   ...

   type Parser is ... -- Abstract if many parsing methods to coexist
   procedure Parse
             (  Object  : in out Parser;
                Source  : in out Abstract_Source'Class;
                Context : in out Abstract_Context'Class
             );

or using mix-in:

   type Parser
        (  Source  : not null access Abstract_Source'Class;
           Context : not null access Abstract_Context'Class
        )  is ...; 
   procedure Parse (Object : in out Parser);

A renderer may directly implement Abstract_Context, but usually one makes
it mix-in in order to have an ability for many different renderers to have
a hierarchy of their own independently on any parsing issues. This is what
I suppose Georg's example of Print procedure should illustrate.

[ Abstract_Context may render, generate AST, interperet. Abstract_Source
may encapsulate a text file, text stream, string, XML-ish garbage etc. ]

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-04-07 20:52 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-06 10:11 Parser interface design Natasha Kerensikova
2011-04-06 12:17 ` Georg Bauhaus
2011-04-07 18:56   ` Natasha Kerensikova
2011-04-08 11:49     ` Stephen Leake
2011-04-06 12:20 ` Dmitry A. Kazakov
2011-04-07 19:14   ` Natasha Kerensikova
2011-04-07 20:31     ` Dmitry A. Kazakov
2011-04-08 13:51       ` Natasha Kerensikova
2011-04-08 14:21         ` Dmitry A. Kazakov
2011-04-12 15:58           ` Natasha Kerensikova
2011-04-12 17:14             ` Dmitry A. Kazakov
2011-04-06 15:51 ` Georg Bauhaus
2011-04-07 19:44   ` Natasha Kerensikova
2011-04-07 20:52     ` Dmitry A. Kazakov [this message]
2011-04-07 22:09     ` Simon Wright
2011-04-08 14:03       ` Natasha Kerensikova
2011-04-08 19:06         ` Jeffrey Carter
2011-04-08 19:59         ` Simon Wright
2011-04-12 16:13           ` Natasha Kerensikova
2011-04-12 17:22             ` Dmitry A. Kazakov
2011-04-12 19:02               ` Simon Wright
2011-04-13  8:20                 ` Natasha Kerensikova
2011-04-13  8:37                   ` Dmitry A. Kazakov
2011-04-13 11:06                     ` Georg Bauhaus
2011-04-13 12:46                       ` Dmitry A. Kazakov
2011-04-13 22:33                   ` Randy Brukardt
2011-04-14  6:55                     ` Natasha Kerensikova
2011-04-15  0:22                       ` Randy Brukardt
2011-04-12 21:54               ` Randy Brukardt
2011-04-07 22:13     ` Georg Bauhaus
2011-04-08 15:30       ` Natasha Kerensikova
2011-04-07  0:36 ` Randy Brukardt
2011-04-08 11:16 ` Brian Drummond
2011-04-19  9:08 ` Natasha Kerensikova
2011-04-19 12:35   ` Ludovic Brenta
2011-04-20 10:44     ` Brian Drummond
2011-04-19 17:28   ` Jeffrey Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox