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=0.8 required=5.0 tests=BAYES_00,MSGID_RANDY, PLING_QUERY,WEIRD_QUOTING autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6c764748730dd2c1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-12-12 22:03:16 PST Path: supernews.google.com!sn-xit-02!supernews.com!216.218.236.179.MISMATCH!news!news.he.net!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: Ted Dennison Newsgroups: comp.lang.ada Subject: Re: gnathtml in Ada ? (LONG!) Date: Wed, 13 Dec 2000 05:54:03 GMT Organization: Deja.com Message-ID: <9172tp$sfk$1@nnrp1.deja.com> References: <3A351287.8628BCFA@dpqwd.zblf> <913mhp$4oh$1@nnrp1.deja.com> <000d01c063d0$1e0d7640$0502a8c0@db2000> NNTP-Posting-Host: 38.195.186.125 X-Article-Creation-Date: Wed Dec 13 05:54:03 2000 GMT X-Http-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; m18) Gecko/20001108 Netscape6/6.0 X-Http-Proxy: 1.1 x60.deja.com:80 (Squid/1.1.22) for client 38.195.186.125 X-MyDeja-Info: XMYDJUIDtedennison Xref: supernews.google.com comp.lang.ada:3045 Date: 2000-12-13T05:54:03+00:00 List-Id: In article <000d01c063d0$1e0d7640$0502a8c0@db2000>, comp.lang.ada@ada.eu.org wrote: > > Without that feature, the whole thing could be done quite trivially > > using OpenToken... > > I assume this means you have volunteered for the task. Well, I got bored this evening, so attached is my first wag at it (sans headers). It took me all of 1 hour to write (most of that time spent learning what HTML is supposed to like these days. Its been a while...). It is only 54 lines of code, but it would actually be much shorter if I hadn't designed it for later expansion. I should also mention that it requires a recent version of OpenToken to compile. As far as an official release, it (or a later version) will be included in the next distribution of OpenToken. Good points: Its generates strictly HTML 4 compliant output. I colorizes the same way emacs Ada mode does. It should be compiler-agnostic. Its 100% Ada source. Bad points: It doesn't do anything yet besides colorizing comments and keywords. Its only been tested on my Win2k-gnat system. The latest OpenToken has known incompatabilites with some compilers. As usual, my apologies ahead of time for what deja may do with the formatting: --- with Ada.Command_Line; with Ada.Text_IO; with HTML_Compiler; ------------------------------------------------------------------------------- -- This routine provides for converting Ada source files into HTML. ------------------------------------------------------------------------------- procedure HTMLify is ---------------------------------------------------------------------------- -- Print a description of the proper usage of this program ---------------------------------------------------------------------------- procedure Print_Usage is begin Ada.Text_IO.Put_Line ("usage: " & Ada.Command_Line.Command_Name & " filename"); Ada.Text_IO.New_Line; end Print_Usage; begin -- Verify the arguments if Ada.Command_Line.Argument_Count = 0 or else Ada.Command_Line.Argument(1) = "--help" then Print_Usage; return; end if; for File_Index in 1..Ada.Command_Line.Argument_Count loop HTML_Compiler.Compile (Ada.Command_Line.Argument(File_Index)); end loop; end HTMLify; ----------------------------------------------------------------------------- -- -- This package provides for compiling the given Ada source file into an HTML -- file. ----------------------------------------------------------------------------- -- package HTML_Compiler is ---------------------------------------------------------------------------- -- Open the given Ada file and compile it into HTML source. The HTML file -- will be given the same name as the Source_File, with ".html" on the end. ---------------------------------------------------------------------------- procedure Compile (Source_File : in String); end HTML_Compiler; -- Ada units with Ada.Text_IO; -- Standard OpenToken units with OpenToken; with OpenToken.Text_Feeder.Text_IO; -- The lexer with Ada_Lexer; use type Ada_Lexer.Ada_Token; ------------------------------------------------------------------------------- -- This package provides for compiling the given Ada source file into an HTML -- file. ------------------------------------------------------------------------------- package body HTML_Compiler is ---------------------------------------------------------------------------- -- Parse an Ada token into normal text HTML on the given file. ---------------------------------------------------------------------------- procedure Parse_Text (Destination : in out Ada.Text_IO.File_Type) is begin Ada.Text_IO.Put (File => Destination, Item => Ada_Lexer.Tokenizer.Lexeme (Ada_Lexer.Analyzer) ); Ada_Lexer.Tokenizer.Find_Next (Ada_Lexer.Analyzer); end Parse_Text; ---------------------------------------------------------------------------- -- Parse an Ada comment token into HTML on the given file. ---------------------------------------------------------------------------- procedure Parse_Comment (Destination : in out Ada.Text_IO.File_Type) is begin Ada.Text_IO.Put (File => Destination, Item => "" & Ada_Lexer.Tokenizer.Lexeme (Ada_Lexer.Analyzer) & "" ); Ada_Lexer.Tokenizer.Find_Next (Ada_Lexer.Analyzer); end Parse_Comment; ---------------------------------------------------------------------------- -- Parse an Ada keyword token into HTML on the given file. ---------------------------------------------------------------------------- procedure Parse_Keyword (Destination : in out Ada.Text_IO.File_Type) is begin Ada.Text_IO.Put (File => Destination, Item => "" & Ada_Lexer.Tokenizer.Lexeme (Ada_Lexer.Analyzer) & "" ); Ada_Lexer.Tokenizer.Find_Next (Ada_Lexer.Analyzer); end Parse_Keyword; ---------------------------------------------------------------------------- -- Parse a block of Ada code into HTML on the given file. ---------------------------------------------------------------------------- procedure Parse_Block (Destination : in out Ada.Text_IO.File_Type) is begin case Ada_Lexer.Tokenizer.ID (Ada_Lexer.Analyzer) is when Ada_Lexer.Comment_T => Parse_Comment (Destination); when Ada_Lexer.Abort_T..Ada_Lexer.Xor_T => Parse_Keyword (Destination); when others => Parse_Text (Destination); end case; end Parse_Block; ---------------------------------------------------------------------------- -- Open the given Ada file and compile it into HTML source. The HTML file -- will be given the same name as the Source_File, with ".html" on the end. ---------------------------------------------------------------------------- procedure Compile (Source_File : in String) is Ada_File : aliased Ada.Text_Io.File_Type; HTML_File : Ada.Text_Io.File_Type; begin -- Turn on Ada whitespace reporting Ada_Lexer.Syntax(Ada_Lexer.Whitespace_T).Recognizer.Report := True; Ada_Lexer.Syntax(Ada_Lexer.Comment_T).Recognizer.Report := True; -- Open the Ada file Ada.Text_Io.Open (File => Ada_File, Mode => Ada.Text_Io.In_File, Name => Source_File); Ada_Lexer.Tokenizer.Input_Feeder := OpenToken.Text_Feeder.Text_IO.Create (Ada_File'Unchecked_Access); -- Open the target HTML file, and put its name and header information in. Ada.Text_IO.Create (File => HTML_File, Mode => Ada.Text_IO.Out_File, Name => Source_File & ".html"); Ada.Text_IO.Put_Line (File => HTML_File, Item => "" ); Ada.Text_IO.Put_Line (File => HTML_File, Item => "" & Source_File & "" ); Ada.Text_IO.Put_Line (File => HTML_File, Item => "

" & Source_File & "


"
         );

      Ada_Lexer.Tokenizer.Find_Next (Ada_Lexer.Analyzer);

      while Ada_Lexer.Tokenizer.ID (Ada_Lexer.Analyzer) /=
Ada_Lexer.End_Of_File_T loop
         Parse_Block (HTML_File);
      end loop;

      Ada.Text_IO.Put_Line
        (File => HTML_File,
         Item => "
" ); Ada.Text_IO.Close (HTML_File); Ada.Text_IO.Close (Ada_File); end Compile; end HTML_Compiler; --- -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/