1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package contains a generic lexical analyzer. This is used
28 -- for scanning Ada source files or text files with an Ada-like syntax,
29 -- such as project files. It is instantiated in Scn and Prj.Err.
31 with Casing
; use Casing
;
33 with Types
; use Types
;
36 with procedure Post_Scan
;
37 -- Procedure called by Scan for the following tokens:
38 -- Tok_Char_Literal, Tok_Identifier, Tok_Real_Literal, Tok_Real_Literal,
39 -- Tok_Integer_Literal, Tok_String_Literal, Tok_Operator_Symbol.
41 with procedure Error_Msg
(Msg
: String; Flag_Location
: Source_Ptr
);
42 -- Output a message at specified location
44 with procedure Error_Msg_S
(Msg
: String);
45 -- Output a message at current scan pointer location
47 with procedure Error_Msg_SC
(Msg
: String);
48 -- Output a message at the start of the current token
50 with procedure Error_Msg_SP
(Msg
: String);
51 -- Output a message at the start of the previous token
53 with procedure Obsolescent_Check
(S
: Source_Ptr
);
54 -- Called when one of the obsolescent character replacements is
55 -- used with S pointing to the character in question.
57 with package Style
is new Styleg
58 (Error_Msg
, Error_Msg_S
, Error_Msg_SC
, Error_Msg_SP
);
59 -- Instantiation of Styleg with the same error reporting routines
63 procedure Initialize_Scanner
64 (Unit
: Unit_Number_Type
;
65 Index
: Source_File_Index
);
66 -- Initialize lexical scanner for scanning a new file. The caller has
67 -- completed the construction of the Units.Table entry for the specified
68 -- Unit and Index references the corresponding source file. A special
69 -- case is when Unit = No_Unit_Number, and Index corresponds to the
70 -- source index for reading the configuration pragma file.
71 -- Initialize_Scanner does not call Scan.
74 -- Scan scans out the next token, and advances the scan state accordingly
75 -- (see package Scan_State for details). If the scan encounters an illegal
76 -- token, then an error message is issued pointing to the bad character,
77 -- and Scan returns a reasonable substitute token of some kind.
78 -- For tokens Char_Literal, Identifier, Real_Literal, Integer_Literal,
79 -- String_Literal and Operator_Symbol, Post_Scan is called after scanning.
81 function Determine_Token_Casing
return Casing_Type
;
82 pragma Inline
(Determine_Token_Casing
);
83 -- Determines the casing style of the current token, which is
84 -- either a keyword or an identifier. See also package Casing.
86 procedure Set_Special_Character
(C
: Character);
87 -- Indicate that one of the following character '#', '$', '?', '@', '`',
88 -- '\', '^', '_' or '~', when found is a Special token.
90 procedure Reset_Special_Characters
;
91 -- Indicate that there is no characters that are Special tokens., which
94 procedure Set_End_Of_Line_As_Token
(Value
: Boolean);
95 -- Indicate if End_Of_Line is a token or not.
96 -- By default, End_Of_Line is not a token.
98 procedure Set_Comment_As_Token
(Value
: Boolean);
99 -- Indicate if a comment is a token or not.
100 -- By default, a comment is not a token.
102 function Set_Start_Column
return Column_Number
;
103 -- This routine is called with Scan_Ptr pointing to the first character
104 -- of a line. On exit, Scan_Ptr is advanced to the first non-blank
105 -- character of this line (or to the terminating format effector if the
106 -- line contains no non-blank characters), and the returned result is the
107 -- column number of this non-blank character (zero origin), which is the
108 -- value to be stored in the Start_Column scan variable.