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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,50e705cdf2767cc6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Parser interface design Date: Wed, 6 Apr 2011 19:36:01 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1302136566 18545 69.95.181.76 (7 Apr 2011 00:36:06 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 7 Apr 2011 00:36:06 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Path: g2news2.google.com!news4.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feed.ac-versailles.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!jacob-sparre.dk!ada-dk.org!.POSTED!not-for-mail Xref: g2news2.google.com comp.lang.ada:19675 Date: 2011-04-06T19:36:01-05:00 List-Id: "Natasha Kerensikova" wrote in message news:slrnipof32.2fnq.lithiumcat@sigil.instinctive.eu... ... > The problem on which I want your opinion is designing the interface > between the parser and the renderer. The point is to be able to "plug" > may renderer into the parser, and thereby obtain a different kind of > output, with as little code rewrite as possible (hence the idea of > refactoring the "parser" into a re-usable part). The tool that creates the formatted versions of the Ada Standard (and other documents) has pretty much this same problem. It had to take source files coded for an obsolete tool (Scribe) and convert them to modern (in 2000) formats. I defined a pair of abstract tagged types to serve as the bottom of the hierarchy, Input_Type and Output_Type, and then defined a set of operations for each. There then are multiple concrete implementations of each (file and buffer for Input, Text, HTML, and RTF for Output). There is a central part of the code that uses dispatching calls to each to implement the actual command set of the source text files. (Note that in my design, the meaning of the text is fixed, only the source of the text changes, while you want a bit more flexibility in the parsing -- which could be accomplished by putting more of the parsing into the Input object. In hindsight, I probably should have done that as well.) You can find the entire source code to the tool at http://www.ada-auth.org/arm.html (look for the formatting tool about halfway down the page). Note that this was a "working" program not necessarily designed for use as an example, so it is pretty large. Randy.