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: a07f3367d7,c689b55786a9f2bd X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!193.201.147.78.MISMATCH!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: for S'Image use Func?? Date: Thu, 20 May 2010 12:31:17 +0300 Organization: Tidorum Ltd Message-ID: <85kdr5FhtkU1@mid.individual.net> References: <4be417b4$0$6992$9b4e6d93@newsspool4.arcor-online.net> <1qcb6z4i20dyb.1dz2hd4c0vx69.dlg@40tude.net> <852u87Fr5cU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net 5polP4a+vuulJ1yGBdH5KgXt8ZFlMq3AXSpPqGRH3j/0JXcQGa Cancel-Lock: sha1:Sed99K+9ztia0idXag7d8UKeoc0= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: Xref: g2news2.google.com comp.lang.ada:11791 Date: 2010-05-20T12:31:17+03:00 List-Id: J-P. Rosen wrote: > Niklas Holsti a �crit : >>> And of course, you are welcome to have a look at my scanner in >>> AdaControl ;-) >> I did, and I even compiled and tried it, but since your scanner ignores >> and skips all line terminators (there is no "end of line" token kind), >> its operation does not illuminate the question of the "wart". >> > Huh? There is an At_EoL boolean, even if it is not a full fledged token... Ah yes, there is an At_Eol variable in the package body, and a like-named component in the private type Scanner_State, but those are not accessible to clients of the scanner. I modified your package Framework.Language.Scanner, to provide a function that queries At_Eol, and made a test program that calls Start_Scan and then calls Next_Token repeatedly, until it returns the Eof (end of file) token. After each call of Next_Token the program prints out the line number of Standard_Input, Current_Token.Kind, and the value of At_Eol. In my experiments, the output is exactly the same for a file that consists of just one line of text, as for a file that consists of this one line of text followed by a null line. A client of your scanner thus cannot detect that the input file has a final empty line, which is the "wart" that has been discussed in this thread. I have found a work-around for the wart, so it is possible to use Text_IO to detect final empty lines. The following program counts the number of lines in the input file, and works even for empty files (/dev/null) and for files with final null lines. The trick is to use an extra call of Skip_Line to see if there is a final line terminator (for a null line) before the file terminator: with Ada.Text_IO; use Ada.Text_IO; procedure Count_Lines is Lines : Natural := 0; begin while not End_Of_File loop -- A non-null line at this point, or a null line -- that is not immediately followed by end of file. -- Process the line in some way; omitted here. Lines := Lines + 1; Skip_Line; end loop; -- Here we are at End_Of_File, but there may -- still be a line terminator for a null line -- immediately before the true end of the file. begin Skip_Line; -- Skip_Line raises End_Error if there is no line -- terminator before the end of the file. Lines := Lines + 1; exception when End_Error => null; end; Put_Line ("Lines:" & Natural'Image (Lines)); end Count_Lines; -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .