1 (* M2LexBuf.def provides a buffer for m2.lex.
3 Copyright (C) 2001-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
22 DEFINITION MODULE M2LexBuf ;
27 System : UNIX (GNU Modula-2)
28 Date : Fri Jul 27 12:42:13 2001
29 Description: provides a buffer for the all the tokens created by m2.lex.
32 FROM SYSTEM IMPORT ADDRESS ;
33 FROM M2Reserved IMPORT toktype ;
34 FROM DynamicStrings IMPORT String ;
35 FROM m2linemap IMPORT location_t ;
36 FROM NameKey IMPORT Name ;
38 EXPORT QUALIFIED OpenSource, CloseSource, ReInitialize, GetToken, InsertToken,
39 InsertTokenAndRewind, GetPreviousTokenLineNo, GetLineNo,
40 GetColumnNo, GetTokenNo, TokenToLineNo, TokenToColumnNo,
41 TokenToLocation, GetTokenName,
42 FindFileNameFromToken, GetFileName,
44 currenttoken, currentstring, currentinteger,
45 AddTok, AddTokCharStar, AddTokInteger, MakeVirtualTok,
46 SetFile, PushFile, PopFile,
47 PrintTokenNo, DisplayToken, DumpTokens,
48 BuiltinTokenNo, UnknownTokenNo ;
55 currenttoken : toktype ;
56 currentstring : ADDRESS ;
57 currentcolumn : CARDINAL ;
58 currentinteger: INTEGER ;
62 OpenSource - Attempts to open the source file, s.
63 The success of the operation is returned.
66 PROCEDURE OpenSource (s: String) : BOOLEAN ;
70 CloseSource - closes the current open file.
73 PROCEDURE CloseSource ;
77 ReInitialize - re-initialize the all the data structures.
80 PROCEDURE ReInitialize ;
84 ResetForNewPass - reset the buffer pointers to the beginning ready for
88 PROCEDURE ResetForNewPass ;
92 GetToken - gets the next token into currenttoken.
99 InsertToken - inserts a symbol, token, infront of the current token
100 ready for the next pass.
103 PROCEDURE InsertToken (token: toktype) ;
107 InsertTokenAndRewind - inserts a symbol, token, infront of the current token
108 and then moves the token stream back onto the inserted token.
111 PROCEDURE InsertTokenAndRewind (token: toktype) ;
115 GetPreviousTokenLineNo - returns the line number of the previous token.
118 PROCEDURE GetPreviousTokenLineNo () : CARDINAL ;
122 GetLineNo - returns the current line number where the symbol occurs in
126 PROCEDURE GetLineNo () : CARDINAL ;
130 GetTokenNo - returns the current token number.
133 PROCEDURE GetTokenNo () : CARDINAL ;
137 GetTokenName - returns the token name given the tokenno.
140 PROCEDURE GetTokenName (tokenno: CARDINAL) : Name ;
144 TokenToLineNo - returns the line number of the current file for the
145 TokenNo. The depth refers to the include depth.
146 A depth of 0 is the current file, depth of 1 is the file
147 which included the current file. Zero is returned if the
148 depth exceeds the file nesting level.
151 PROCEDURE TokenToLineNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
155 GetColumnNo - returns the current column where the symbol occurs in
159 PROCEDURE GetColumnNo () : CARDINAL ;
163 TokenToColumnNo - returns the column number of the current file for the
164 TokenNo. The depth refers to the include depth.
165 A depth of 0 is the current file, depth of 1 is the file
166 which included the current file. Zero is returned if the
167 depth exceeds the file nesting level.
170 PROCEDURE TokenToColumnNo (TokenNo: CARDINAL; depth: CARDINAL) : CARDINAL ;
174 TokenToLocation - returns the location_t corresponding to, TokenNo.
177 PROCEDURE TokenToLocation (TokenNo: CARDINAL) : location_t ;
181 FindFileNameFromToken - returns the complete FileName for the appropriate
182 source file yields the token number, TokenNo.
183 The, Depth, indicates the include level: 0..n
184 Level 0 is the current. NIL is returned if n+1
188 PROCEDURE FindFileNameFromToken (TokenNo: CARDINAL; depth: CARDINAL) : String ;
192 GetFileName - returns a String defining the current file.
195 PROCEDURE GetFileName () : String ;
199 MakeVirtualTok - creates and return a new tokenno which is created from
200 tokenno range1 and range2.
203 PROCEDURE MakeVirtualTok (caret, left, right: CARDINAL) : CARDINAL ;
206 (* ***********************************************************************
208 * These functions allow m2.lex to deliver tokens into the buffer
210 ************************************************************************* *)
213 AddTok - adds a token to the buffer.
216 PROCEDURE AddTok (t: toktype) ;
220 AddTokCharStar - adds a token to the buffer and an additional string, s.
221 A copy of string, s, is made.
224 PROCEDURE AddTokCharStar (t: toktype; s: ADDRESS) ;
228 AddTokInteger - adds a token and an integer to the buffer.
231 PROCEDURE AddTokInteger (t: toktype; i: INTEGER) ;
235 SetFile - sets the current filename to, filename.
238 PROCEDURE SetFile (filename: ADDRESS) ;
242 PushFile - indicates that, filename, has just been included.
245 PROCEDURE PushFile (filename: ADDRESS) ;
249 PopFile - indicates that we are returning to, filename, having finished
253 PROCEDURE PopFile (filename: ADDRESS) ;
257 PrintTokenNo - displays token and the location of the token.
260 PROCEDURE PrintTokenNo (tokenno: CARDINAL) ;
264 DisplayToken - display the token name using printf0 no newline is emitted.
267 PROCEDURE DisplayToken (tok: toktype) ;
271 DumpTokens - developer debugging aid.
274 PROCEDURE DumpTokens ;