opentoken_6.0.3_b278f6ad/Test/test_html_lexer_safe.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
--  Abstract :
--
--  Test HTML_Lexer
--
--  Copyright (C) 2003, 2009 Stephen Leake.  All Rights Reserved.
--
--  This program is free software; you can redistribute it and/or
--  modify it under terms of the GNU General Public License as
--  published by the Free Software Foundation; either version 3, or (at
--  your option) any later version. This program is distributed in the
--  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
--  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
--  PURPOSE. See the GNU General Public License for more details. You
--  should have received a copy of the GNU General Public License
--  distributed with this program; see file COPYING. If not, write to
--  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
--  MA 02111-1307, USA.

with Ada.Command_Line;
with Ada.Strings.Unbounded;
with Ada.Strings.Fixed;
with Ada.Text_IO;
with HTML_Lexer.Task_Safe;
with OpenToken.Text_Feeder.Text_IO;
procedure Test_HTML_Lexer_Safe
is
   procedure Put_Usage
   is begin
      Ada.Text_IO.Put_Line (Ada.Text_IO.Standard_Error, "usage: test_html_lexer file");
   end Put_Usage;

   File_Name   : Ada.Strings.Unbounded.Unbounded_String;
   File        : aliased Ada.Text_IO.File_Type;
   Lexer       : HTML_Lexer.Task_Safe.Lexer_Type;
   Text_Feeder : aliased OpenToken.Text_Feeder.Text_IO.Instance;

   procedure Put_Token (Token : in HTML_Lexer.HTML_Token)
   is
      use Ada.Strings;
      use Ada.Strings.Unbounded;
      use Ada.Strings.Fixed;
      use HTML_Lexer;
   begin
      Ada.Text_IO.Put_Line
        (To_String (File_Name) &
           ":" &
           Trim (Natural'Image (Line (Token)), Both) &
           ":" &
           Trim (Natural'Image (Column (Token)), Both) &
           ": " &
           Token_Name'Image (Name (Token)) & ": " & Lexeme (Token));
   end Put_Token;

   procedure Parse_File
   is
      use HTML_Lexer;
      Token : HTML_Token;
   begin
      loop
         HTML_Lexer.Task_Safe.Next_Token (Lexer, Token);
         Put_Token (Token);

         exit when Name (Token) = End_Of_File;
      end loop;
   end Parse_File;

begin
   if Ada.Command_Line.Argument_Count = 1 then
      Ada.Text_IO.Open (File, Ada.Text_IO.In_File, Ada.Command_Line.Argument (1));
   else
      Put_Usage;
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;

   File_Name := Ada.Strings.Unbounded.To_Unbounded_String (Ada.Command_Line.Argument (1));

   Text_Feeder := OpenToken.Text_Feeder.Text_IO.Create (File'Unchecked_Access);
   HTML_Lexer.Task_Safe.Initialize (Lexer, Text_Feeder'Unchecked_Access);

   Parse_File;

end Test_HTML_Lexer_Safe;