1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Lexical-Scanner.html
27  * outPack = glib
28  * outFile = ScannerG
29  * strct   = GScanner
30  * realStrct=
31  * ctorStrct=
32  * clss    = ScannerG
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_scanner_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gtkc.Loader
48  * 	- gtkc.paths
49  * structWrap:
50  * 	- GScanner* -> ScannerG
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module glib.ScannerG;
57 
58 public  import gtkc.glibtypes;
59 
60 private import gtkc.glib;
61 private import glib.ConstructionException;
62 
63 
64 private import glib.Str;
65 private import gtkc.Loader;
66 private import gtkc.paths;
67 
68 
69 
70 
71 /**
72  * The GScanner and its associated functions provide a
73  * general purpose lexical scanner.
74  */
75 public class ScannerG
76 {
77 	
78 	/** the main Gtk struct */
79 	protected GScanner* gScanner;
80 	
81 	
82 	public GScanner* getScannerGStruct()
83 	{
84 		return gScanner;
85 	}
86 	
87 	
88 	/** the main Gtk struct as a void* */
89 	protected void* getStruct()
90 	{
91 		return cast(void*)gScanner;
92 	}
93 	
94 	/**
95 	 * Sets our main struct and passes it to the parent class
96 	 */
97 	public this (GScanner* gScanner)
98 	{
99 		this.gScanner = gScanner;
100 	}
101 	
102 	~this ()
103 	{
104 		if ( Linker.isLoaded(LIBRARY.GLIB) && gScanner !is null )
105 		{
106 			g_scanner_destroy(gScanner);
107 		}
108 	}
109 	
110 	/**
111 	 */
112 	
113 	/**
114 	 * Creates a new GScanner.
115 	 * The config_templ structure specifies the initial settings
116 	 * of the scanner, which are copied into the GScanner
117 	 * config field. If you pass NULL then the default settings
118 	 * are used.
119 	 * Params:
120 	 * configTempl = the initial scanner settings
121 	 * Throws: ConstructionException GTK+ fails to create the object.
122 	 */
123 	public this (GScannerConfig* configTempl)
124 	{
125 		// GScanner * g_scanner_new (const GScannerConfig *config_templ);
126 		auto p = g_scanner_new(configTempl);
127 		if(p is null)
128 		{
129 			throw new ConstructionException("null returned by g_scanner_new(configTempl)");
130 		}
131 		this(cast(GScanner*) p);
132 	}
133 	
134 	/**
135 	 * Frees all memory used by the GScanner.
136 	 */
137 	public void destroy()
138 	{
139 		// void g_scanner_destroy (GScanner *scanner);
140 		g_scanner_destroy(gScanner);
141 	}
142 	
143 	/**
144 	 * Prepares to scan a file.
145 	 * Params:
146 	 * inputFd = a file descriptor
147 	 */
148 	public void inputFile(int inputFd)
149 	{
150 		// void g_scanner_input_file (GScanner *scanner,  gint input_fd);
151 		g_scanner_input_file(gScanner, inputFd);
152 	}
153 	
154 	/**
155 	 * Rewinds the filedescriptor to the current buffer position
156 	 * and blows the file read ahead buffer. This is useful for
157 	 * third party uses of the scanners filedescriptor, which hooks
158 	 * onto the current scanning position.
159 	 */
160 	public void syncFileOffset()
161 	{
162 		// void g_scanner_sync_file_offset (GScanner *scanner);
163 		g_scanner_sync_file_offset(gScanner);
164 	}
165 	
166 	/**
167 	 * Prepares to scan a text buffer.
168 	 * Params:
169 	 * text = the text buffer to scan
170 	 */
171 	public void inputText(string text)
172 	{
173 		// void g_scanner_input_text (GScanner *scanner,  const gchar *text,  guint text_len);
174 		g_scanner_input_text(gScanner, cast(char*)text.ptr, cast(int) text.length);
175 	}
176 	
177 	/**
178 	 * Parses the next token, without removing it from the input stream.
179 	 * The token data is placed in the next_token, next_value, next_line,
180 	 * and next_position fields of the GScanner structure.
181 	 * Note that, while the token is not removed from the input stream
182 	 * (i.e. the next call to g_scanner_get_next_token() will return the
183 	 * same token), it will not be reevaluated. This can lead to surprising
184 	 * results when changing scope or the scanner configuration after peeking
185 	 * the next token. Getting the next token after switching the scope or
186 	 * configuration will return whatever was peeked before, regardless of
187 	 * any symbols that may have been added or removed in the new scope.
188 	 * Returns: the type of the token
189 	 */
190 	public GTokenType peekNextToken()
191 	{
192 		// GTokenType g_scanner_peek_next_token (GScanner *scanner);
193 		return g_scanner_peek_next_token(gScanner);
194 	}
195 	
196 	/**
197 	 * Parses the next token just like g_scanner_peek_next_token()
198 	 * and also removes it from the input stream. The token data is
199 	 * placed in the token, value, line, and position fields of
200 	 * the GScanner structure.
201 	 * Returns: the type of the token
202 	 */
203 	public GTokenType getNextToken()
204 	{
205 		// GTokenType g_scanner_get_next_token (GScanner *scanner);
206 		return g_scanner_get_next_token(gScanner);
207 	}
208 	
209 	/**
210 	 * Returns TRUE if the scanner has reached the end of
211 	 * the file or text buffer.
212 	 * Returns: TRUE if the scanner has reached the end of the file or text buffer
213 	 */
214 	public int eof()
215 	{
216 		// gboolean g_scanner_eof (GScanner *scanner);
217 		return g_scanner_eof(gScanner);
218 	}
219 	
220 	/**
221 	 * Returns the current line in the input stream (counting
222 	 * from 1). This is the line of the last token parsed via
223 	 * g_scanner_get_next_token().
224 	 * Returns: the current line
225 	 */
226 	public uint curLine()
227 	{
228 		// guint g_scanner_cur_line (GScanner *scanner);
229 		return g_scanner_cur_line(gScanner);
230 	}
231 	
232 	/**
233 	 * Returns the current position in the current line (counting
234 	 * from 0). This is the position of the last token parsed via
235 	 * g_scanner_get_next_token().
236 	 * Returns: the current position on the line
237 	 */
238 	public uint curPosition()
239 	{
240 		// guint g_scanner_cur_position (GScanner *scanner);
241 		return g_scanner_cur_position(gScanner);
242 	}
243 	
244 	/**
245 	 * Gets the current token type. This is simply the token
246 	 * field in the GScanner structure.
247 	 * Returns: the current token type
248 	 */
249 	public GTokenType curToken()
250 	{
251 		// GTokenType g_scanner_cur_token (GScanner *scanner);
252 		return g_scanner_cur_token(gScanner);
253 	}
254 	
255 	/**
256 	 * Gets the current token value. This is simply the value
257 	 * field in the GScanner structure.
258 	 * Returns: the current token value
259 	 */
260 	public GTokenValue curValue()
261 	{
262 		// GTokenValue g_scanner_cur_value (GScanner *scanner);
263 		return g_scanner_cur_value(gScanner);
264 	}
265 	
266 	/**
267 	 * Sets the current scope.
268 	 * Params:
269 	 * scopeId = the new scope id
270 	 * Returns: the old scope id
271 	 */
272 	public uint setScope(uint scopeId)
273 	{
274 		// guint g_scanner_set_scope (GScanner *scanner,  guint scope_id);
275 		return g_scanner_set_scope(gScanner, scopeId);
276 	}
277 	
278 	/**
279 	 * Adds a symbol to the given scope.
280 	 * Params:
281 	 * scopeId = the scope id
282 	 * symbol = the symbol to add
283 	 * value = the value of the symbol
284 	 */
285 	public void scopeAddSymbol(uint scopeId, string symbol, void* value)
286 	{
287 		// void g_scanner_scope_add_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol,  gpointer value);
288 		g_scanner_scope_add_symbol(gScanner, scopeId, Str.toStringz(symbol), value);
289 	}
290 	
291 	/**
292 	 * Calls the given function for each of the symbol/value pairs
293 	 * in the given scope of the GScanner. The function is passed
294 	 * the symbol and value of each pair, and the given user_data
295 	 * parameter.
296 	 * Params:
297 	 * scopeId = the scope id
298 	 * func = the function to call for each symbol/value pair
299 	 * userData = user data to pass to the function
300 	 */
301 	public void scopeForeachSymbol(uint scopeId, GHFunc func, void* userData)
302 	{
303 		// void g_scanner_scope_foreach_symbol (GScanner *scanner,  guint scope_id,  GHFunc func,  gpointer user_data);
304 		g_scanner_scope_foreach_symbol(gScanner, scopeId, func, userData);
305 	}
306 	
307 	/**
308 	 * Looks up a symbol in a scope and return its value. If the
309 	 * symbol is not bound in the scope, NULL is returned.
310 	 * Params:
311 	 * scopeId = the scope id
312 	 * symbol = the symbol to look up
313 	 * Returns: the value of symbol in the given scope, or NULL if symbol is not bound in the given scope.
314 	 */
315 	public void* scopeLookupSymbol(uint scopeId, string symbol)
316 	{
317 		// gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol);
318 		return g_scanner_scope_lookup_symbol(gScanner, scopeId, Str.toStringz(symbol));
319 	}
320 	
321 	/**
322 	 * Removes a symbol from a scope.
323 	 * Params:
324 	 * scopeId = the scope id
325 	 * symbol = the symbol to remove
326 	 */
327 	public void scopeRemoveSymbol(uint scopeId, string symbol)
328 	{
329 		// void g_scanner_scope_remove_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol);
330 		g_scanner_scope_remove_symbol(gScanner, scopeId, Str.toStringz(symbol));
331 	}
332 	
333 	/**
334 	 * Looks up a symbol in the current scope and return its value.
335 	 * If the symbol is not bound in the current scope, NULL is
336 	 * returned.
337 	 * Params:
338 	 * symbol = the symbol to look up
339 	 * Returns: the value of symbol in the current scope, or NULL if symbol is not bound in the current scope
340 	 */
341 	public void* lookupSymbol(string symbol)
342 	{
343 		// gpointer g_scanner_lookup_symbol (GScanner *scanner,  const gchar *symbol);
344 		return g_scanner_lookup_symbol(gScanner, Str.toStringz(symbol));
345 	}
346 	
347 	/**
348 	 * Outputs a message through the scanner's msg_handler,
349 	 * resulting from an unexpected token in the input stream.
350 	 * Note that you should not call g_scanner_peek_next_token()
351 	 * followed by g_scanner_unexp_token() without an intermediate
352 	 * call to g_scanner_get_next_token(), as g_scanner_unexp_token()
353 	 * evaluates the scanner's current token (not the peeked token)
354 	 * to construct part of the message.
355 	 * Params:
356 	 * expectedToken = the expected token
357 	 * identifierSpec = a string describing how the scanner's user
358 	 * refers to identifiers (NULL defaults to "identifier").
359 	 * This is used if expected_token is G_TOKEN_IDENTIFIER or
360 	 * G_TOKEN_IDENTIFIER_NULL.
361 	 * symbolSpec = a string describing how the scanner's user refers
362 	 * to symbols (NULL defaults to "symbol"). This is used if
363 	 * expected_token is G_TOKEN_SYMBOL or any token value greater
364 	 * than G_TOKEN_LAST.
365 	 * symbolName = the name of the symbol, if the scanner's current
366 	 * token is a symbol.
367 	 * message = a message string to output at the end of the
368 	 * warning/error, or NULL.
369 	 * isError = if TRUE it is output as an error. If FALSE it is
370 	 * output as a warning.
371 	 */
372 	public void unexpToken(GTokenType expectedToken, string identifierSpec, string symbolSpec, string symbolName, string message, int isError)
373 	{
374 		// void g_scanner_unexp_token (GScanner *scanner,  GTokenType expected_token,  const gchar *identifier_spec,  const gchar *symbol_spec,  const gchar *symbol_name,  const gchar *message,  gint is_error);
375 		g_scanner_unexp_token(gScanner, expectedToken, Str.toStringz(identifierSpec), Str.toStringz(symbolSpec), Str.toStringz(symbolName), Str.toStringz(message), isError);
376 	}
377 }