1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * anjuta
4  * Copyright (C) Eran Ifrah (Main file for CodeLite www.codelite.org/ )
5  * Copyright (C) Massimo Cora' 2009 <maxcvs@email.it> (Customizations for Anjuta)
6  *
7  * anjuta is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * anjuta is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 //////////////////////////////////////////////////////////////////////////////
22 //////////////////////////////////////////////////////////////////////////////
23 //
24 // copyright            : (C) 2008 by Eran Ifrah
25 // file name            : FlexLexer.h
26 //
27 // -------------------------------------------------------------------------
28 // A
29 //              _____           _      _     _ _
30 //             /  __ \         | |    | |   (_) |
31 //             | /  \/ ___   __| | ___| |    _| |_ ___
32 //             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
33 //             | \__/\ (_) | (_| |  __/ |___| | ||  __/
34 //              \____/\___/ \__,_|\___\_____/_|\__\___|
35 //
36 //                                                  F i l e
37 //
38 //    This program is free software; you can redistribute it and/or modify
39 //    it under the terms of the GNU General Public License as published by
40 //    the Free Software Foundation; either version 2 of the License, or
41 //    (at your option) any later version.
42 //
43 //////////////////////////////////////////////////////////////////////////////
44 //////////////////////////////////////////////////////////////////////////////
45  // $Header: /CVS/wxUS/wxXtudio/Apps/USClient/FlexLexer.h,v 1.2 2006/02/08 14:30:12 eran Exp $
46 
47 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
48 //		  by flex
49 
50 // Copyright (c) 1993 The Regents of the University of California.
51 // All rights reserved.
52 //
53 // This code is derived from software contributed to Berkeley by
54 // Kent Williams and Tom Epperly.
55 //
56 // Redistribution and use in source and binary forms with or without
57 // modification are permitted provided that: (1) source distributions retain
58 // this entire copyright notice and comment, and (2) distributions including
59 // binaries display the following acknowledgement:  ``This product includes
60 // software developed by the University of California, Berkeley and its
61 // contributors'' in the documentation or other materials provided with the
62 // distribution and in all advertising materials mentioning features or use
63 // of this software.  Neither the name of the University nor the names of
64 // its contributors may be used to endorse or promote products derived from
65 // this software without specific prior written permission.
66 
67 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
68 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
69 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
70 
71 // This file defines FlexLexer, an abstract class which specifies the
72 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
73 // which defines a particular lexer class.
74 //
75 // If you want to create multiple lexer classes, you use the -P flag
76 // to rename each yyFlexLexer to some other xxFlexLexer.  You then
77 // include <FlexLexer.h> in your other sources once per lexer class:
78 //
79 //	#undef yyFlexLexer
80 //	#define yyFlexLexer xxFlexLexer
81 //	#include <FlexLexer.h>
82 //
83 //	#undef yyFlexLexer
84 //	#define yyFlexLexer zzFlexLexer
85 //	#include <FlexLexer.h>
86 //	...
87 
88 #ifndef CODELITE_FLEX_LEXER_H
89 // Never included before - need to define base class.
90 #define CODELITE_FLEX_LEXER_H
91 #include <string>
92 #include <iostream>
93 #include <stdio.h>
94 
95 //extern "C++" {
96 
97 using namespace std;
98 
99 namespace flex
100 {
101 
102 struct yy_buffer_state;
103 typedef int yy_state_type;
104 
105 class FlexLexer {
106 public:
~FlexLexer()107 	virtual ~FlexLexer()	{ }
108 
YYText()109 	const char* YYText()	{ return yytext; }
YYLeng()110 	int YYLeng()		{ return yyleng; }
111 
112 	virtual void
113 		yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
114 	virtual struct yy_buffer_state*
115 		yy_create_buffer( std::istream* s, int size ) = 0;
116 	virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
117 	virtual void yyrestart( std::istream* s ) = 0;
118 
119 	virtual int yylex() = 0;
120 
121 	/// Call yylex with new input/output sources.
122 	int yylex( std::istream* new_in, std::ostream* new_out = 0 )
123 		{
124 		switch_streams( new_in, new_out );
125 		return yylex();
126 		}
127 
128 	/// Switch to new input/output streams.  A nil stream pointer
129 	/// indicates "keep the current one".
130 	virtual void switch_streams( std::istream* new_in = 0,
131 					std::ostream* new_out = 0 ) = 0;
132 
lineno()133 	int lineno() const		{ return yylineno; }
134 
debug()135 	int debug() const		{ return yy_flex_debug; }
set_debug(int flag)136 	void set_debug( int flag )	{ yy_flex_debug = flag; }
137 
138 protected:
139 	char* yytext;
140 	int yyleng;
141 	int yylineno;		///< only maintained if you use %option yylineno
142 	int yy_flex_debug;	///< only has effect with -d or "%option debug"
143 
144 	/// Hack for keeping comments from the lexer
145 	string m_comment;
146 	int  m_keepComments;
147 	int  m_returnWhite;
148 };
149 
150 //}
151 
152 #endif
153 
154 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
155 // Either this is the first time through (yyFlexLexerOnce not defined),
156 // or this is a repeated include to define a different flavor of
157 // yyFlexLexer, as discussed in the flex man page.
158 #define yyFlexLexerOnce
159 
160 class yyFlexLexer : public FlexLexer {
161 public:
162 	/// arg_yyin and arg_yyout default to the cin and cout, but we
163 	/// only make that assignment when initializing in yylex().
164 	yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 );
165 
166 	virtual ~yyFlexLexer();
167 
168 	void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
169 	struct yy_buffer_state* yy_create_buffer( std::istream* s, int size );
170 	void yy_delete_buffer( struct yy_buffer_state* b );
171 	void yyrestart( std::istream* s );
172 
173 	virtual int yylex();
174 	virtual void switch_streams( std::istream* new_in, std::ostream* new_out );
175 
176 protected:
177 	virtual int LexerInput( char* buf, int max_size );
178 	virtual void LexerOutput( const char* buf, int size );
179 	virtual void LexerError( const char* msg );
180 
181 	void yyunput( int c, char* buf_ptr );
182 	int yyinput();
183 
184 	void yy_load_buffer_state();
185 	void yy_init_buffer( struct yy_buffer_state* b, std::istream* s );
186 	void yy_flush_buffer( struct yy_buffer_state* b );
187 
188 	int yy_start_stack_ptr;
189 	int yy_start_stack_depth;
190 	int* yy_start_stack;
191 
192 	void yy_push_state( int new_state );
193 	void yy_pop_state();
194 	int yy_top_state();
195 
196 	yy_state_type yy_get_previous_state();
197 	yy_state_type yy_try_NUL_trans( yy_state_type current_state );
198 	int yy_get_next_buffer();
199 
200 	std::istream* yyin;	    ///< input source for default LexerInput
201 	std::ostream* yyout;    ///< output sink for default LexerOutput
202 
203 	struct yy_buffer_state* yy_current_buffer;
204 
205 	/// yy_hold_char holds the character lost when yytext is formed.
206 	char yy_hold_char;
207 
208 	/// Number of characters read into yy_ch_buf.
209 	int yy_n_chars;
210 
211 	/// Points to current character in buffer.
212 	char* yy_c_buf_p;
213 
214 	int yy_init;		///< whether we need to initialize
215 	int yy_start;		///< start state number
216 
217 	/// Flag which is used to allow yywrap()'s to do buffer switches
218 	/// instead of setting up a fresh yyin.  A bit of a hack ...
219 	int yy_did_buffer_switch_on_eof;
220 
221 	// The following are not always needed, but may be depending
222 	// on use of certain flex features (like REJECT or yymore()).
223 
224 	yy_state_type yy_last_accepting_state;
225 	char* yy_last_accepting_cpos;
226 
227 	yy_state_type* yy_state_buf;
228 	yy_state_type* yy_state_ptr;
229 
230 	char* yy_full_match;
231 	int* yy_full_state;
232 	int yy_full_lp;
233 
234 	int yy_lp;
235 	int yy_looking_for_trail_begin;
236 
237 	int yy_more_flag;
238 	int yy_more_len;
239 	int yy_more_offset;
240 	int yy_prev_more_offset;
241 };
242 
243 } // namespace flex
244 
245 #endif // CODELITE_FLEX_LEXER_H
246