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 private import glib.Str;
64 private import gtkc.Loader;
65 private import gtkc.paths;
66 
67 
68 
69 /**
70  * The GScanner and its associated functions provide a
71  * general purpose lexical scanner.
72  */
73 public class ScannerG
74 {
75 	
76 	/** the main Gtk struct */
77 	protected GScanner* gScanner;
78 	
79 	
80 	/** Get the main Gtk struct */
81 	public GScanner* getScannerGStruct()
82 	{
83 		return gScanner;
84 	}
85 	
86 	
87 	/** the main Gtk struct as a void* */
88 	protected void* getStruct()
89 	{
90 		return cast(void*)gScanner;
91 	}
92 	
93 	/**
94 	 * Sets our main struct and passes it to the parent class
95 	 */
96 	public this (GScanner* gScanner)
97 	{
98 		this.gScanner = gScanner;
99 	}
100 	
101 	~this ()
102 	{
103 		if ( Linker.isLoaded(LIBRARY.GLIB) && gScanner !is null )
104 		{
105 			g_scanner_destroy(gScanner);
106 		}
107 	}
108 	
109 	/**
110 	 */
111 	
112 	/**
113 	 * Creates a new GScanner.
114 	 * The config_templ structure specifies the initial settings
115 	 * of the scanner, which are copied into the GScanner
116 	 * config field. If you pass NULL then the default settings
117 	 * are used.
118 	 * Params:
119 	 * configTempl = the initial scanner settings
120 	 * Throws: ConstructionException GTK+ fails to create the object.
121 	 */
122 	public this (GScannerConfig* configTempl)
123 	{
124 		// GScanner * g_scanner_new (const GScannerConfig *config_templ);
125 		auto p = g_scanner_new(configTempl);
126 		if(p is null)
127 		{
128 			throw new ConstructionException("null returned by g_scanner_new(configTempl)");
129 		}
130 		this(cast(GScanner*) p);
131 	}
132 	
133 	/**
134 	 * Frees all memory used by the GScanner.
135 	 */
136 	public void destroy()
137 	{
138 		// void g_scanner_destroy (GScanner *scanner);
139 		g_scanner_destroy(gScanner);
140 	}
141 	
142 	/**
143 	 * Prepares to scan a file.
144 	 * Params:
145 	 * inputFd = a file descriptor
146 	 */
147 	public void inputFile(int inputFd)
148 	{
149 		// void g_scanner_input_file (GScanner *scanner,  gint input_fd);
150 		g_scanner_input_file(gScanner, inputFd);
151 	}
152 	
153 	/**
154 	 * Rewinds the filedescriptor to the current buffer position
155 	 * and blows the file read ahead buffer. This is useful for
156 	 * third party uses of the scanners filedescriptor, which hooks
157 	 * onto the current scanning position.
158 	 */
159 	public void syncFileOffset()
160 	{
161 		// void g_scanner_sync_file_offset (GScanner *scanner);
162 		g_scanner_sync_file_offset(gScanner);
163 	}
164 	
165 	/**
166 	 * Prepares to scan a text buffer.
167 	 * Params:
168 	 * text = the text buffer to scan
169 	 */
170 	public void inputText(string text)
171 	{
172 		// void g_scanner_input_text (GScanner *scanner,  const gchar *text,  guint text_len);
173 		g_scanner_input_text(gScanner, cast(char*)text.ptr, cast(int) text.length);
174 	}
175 	
176 	/**
177 	 * Parses the next token, without removing it from the input stream.
178 	 * The token data is placed in the next_token, next_value, next_line,
179 	 * and next_position fields of the GScanner structure.
180 	 * Note that, while the token is not removed from the input stream
181 	 * (i.e. the next call to g_scanner_get_next_token() will return the
182 	 * same token), it will not be reevaluated. This can lead to surprising
183 	 * results when changing scope or the scanner configuration after peeking
184 	 * the next token. Getting the next token after switching the scope or
185 	 * configuration will return whatever was peeked before, regardless of
186 	 * any symbols that may have been added or removed in the new scope.
187 	 * Returns: the type of the token
188 	 */
189 	public GTokenType peekNextToken()
190 	{
191 		// GTokenType g_scanner_peek_next_token (GScanner *scanner);
192 		return g_scanner_peek_next_token(gScanner);
193 	}
194 	
195 	/**
196 	 * Parses the next token just like g_scanner_peek_next_token()
197 	 * and also removes it from the input stream. The token data is
198 	 * placed in the token, value, line, and position fields of
199 	 * the GScanner structure.
200 	 * Returns: the type of the token
201 	 */
202 	public GTokenType getNextToken()
203 	{
204 		// GTokenType g_scanner_get_next_token (GScanner *scanner);
205 		return g_scanner_get_next_token(gScanner);
206 	}
207 	
208 	/**
209 	 * Returns TRUE if the scanner has reached the end of
210 	 * the file or text buffer.
211 	 * Returns: TRUE if the scanner has reached the end of the file or text buffer
212 	 */
213 	public int eof()
214 	{
215 		// gboolean g_scanner_eof (GScanner *scanner);
216 		return g_scanner_eof(gScanner);
217 	}
218 	
219 	/**
220 	 * Returns the current line in the input stream (counting
221 	 * from 1). This is the line of the last token parsed via
222 	 * g_scanner_get_next_token().
223 	 * Returns: the current line
224 	 */
225 	public uint curLine()
226 	{
227 		// guint g_scanner_cur_line (GScanner *scanner);
228 		return g_scanner_cur_line(gScanner);
229 	}
230 	
231 	/**
232 	 * Returns the current position in the current line (counting
233 	 * from 0). This is the position of the last token parsed via
234 	 * g_scanner_get_next_token().
235 	 * Returns: the current position on the line
236 	 */
237 	public uint curPosition()
238 	{
239 		// guint g_scanner_cur_position (GScanner *scanner);
240 		return g_scanner_cur_position(gScanner);
241 	}
242 	
243 	/**
244 	 * Gets the current token type. This is simply the token
245 	 * field in the GScanner structure.
246 	 * Returns: the current token type
247 	 */
248 	public GTokenType curToken()
249 	{
250 		// GTokenType g_scanner_cur_token (GScanner *scanner);
251 		return g_scanner_cur_token(gScanner);
252 	}
253 	
254 	/**
255 	 * Gets the current token value. This is simply the value
256 	 * field in the GScanner structure.
257 	 * Returns: the current token value
258 	 */
259 	public GTokenValue curValue()
260 	{
261 		// GTokenValue g_scanner_cur_value (GScanner *scanner);
262 		return g_scanner_cur_value(gScanner);
263 	}
264 	
265 	/**
266 	 * Sets the current scope.
267 	 * Params:
268 	 * scopeId = the new scope id
269 	 * Returns: the old scope id
270 	 */
271 	public uint setScope(uint scopeId)
272 	{
273 		// guint g_scanner_set_scope (GScanner *scanner,  guint scope_id);
274 		return g_scanner_set_scope(gScanner, scopeId);
275 	}
276 	
277 	/**
278 	 * Adds a symbol to the given scope.
279 	 * Params:
280 	 * scopeId = the scope id
281 	 * symbol = the symbol to add
282 	 * value = the value of the symbol
283 	 */
284 	public void scopeAddSymbol(uint scopeId, string symbol, void* value)
285 	{
286 		// void g_scanner_scope_add_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol,  gpointer value);
287 		g_scanner_scope_add_symbol(gScanner, scopeId, Str.toStringz(symbol), value);
288 	}
289 	
290 	/**
291 	 * Calls the given function for each of the symbol/value pairs
292 	 * in the given scope of the GScanner. The function is passed
293 	 * the symbol and value of each pair, and the given user_data
294 	 * parameter.
295 	 * Params:
296 	 * scopeId = the scope id
297 	 * func = the function to call for each symbol/value pair
298 	 * userData = user data to pass to the function
299 	 */
300 	public void scopeForeachSymbol(uint scopeId, GHFunc func, void* userData)
301 	{
302 		// void g_scanner_scope_foreach_symbol (GScanner *scanner,  guint scope_id,  GHFunc func,  gpointer user_data);
303 		g_scanner_scope_foreach_symbol(gScanner, scopeId, func, userData);
304 	}
305 	
306 	/**
307 	 * Looks up a symbol in a scope and return its value. If the
308 	 * symbol is not bound in the scope, NULL is returned.
309 	 * Params:
310 	 * scopeId = the scope id
311 	 * symbol = the symbol to look up
312 	 * Returns: the value of symbol in the given scope, or NULL if symbol is not bound in the given scope.
313 	 */
314 	public void* scopeLookupSymbol(uint scopeId, string symbol)
315 	{
316 		// gpointer g_scanner_scope_lookup_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol);
317 		return g_scanner_scope_lookup_symbol(gScanner, scopeId, Str.toStringz(symbol));
318 	}
319 	
320 	/**
321 	 * Removes a symbol from a scope.
322 	 * Params:
323 	 * scopeId = the scope id
324 	 * symbol = the symbol to remove
325 	 */
326 	public void scopeRemoveSymbol(uint scopeId, string symbol)
327 	{
328 		// void g_scanner_scope_remove_symbol (GScanner *scanner,  guint scope_id,  const gchar *symbol);
329 		g_scanner_scope_remove_symbol(gScanner, scopeId, Str.toStringz(symbol));
330 	}
331 	
332 	/**
333 	 * Looks up a symbol in the current scope and return its value.
334 	 * If the symbol is not bound in the current scope, NULL is
335 	 * returned.
336 	 * Params:
337 	 * symbol = the symbol to look up
338 	 * Returns: the value of symbol in the current scope, or NULL if symbol is not bound in the current scope
339 	 */
340 	public void* lookupSymbol(string symbol)
341 	{
342 		// gpointer g_scanner_lookup_symbol (GScanner *scanner,  const gchar *symbol);
343 		return g_scanner_lookup_symbol(gScanner, Str.toStringz(symbol));
344 	}
345 	
346 	/**
347 	 * Outputs a message through the scanner's msg_handler,
348 	 * resulting from an unexpected token in the input stream.
349 	 * Note that you should not call g_scanner_peek_next_token()
350 	 * followed by g_scanner_unexp_token() without an intermediate
351 	 * call to g_scanner_get_next_token(), as g_scanner_unexp_token()
352 	 * evaluates the scanner's current token (not the peeked token)
353 	 * to construct part of the message.
354 	 * Params:
355 	 * expectedToken = the expected token
356 	 * identifierSpec = a string describing how the scanner's user
357 	 * refers to identifiers (NULL defaults to "identifier").
358 	 * This is used if expected_token is G_TOKEN_IDENTIFIER or
359 	 * G_TOKEN_IDENTIFIER_NULL.
360 	 * symbolSpec = a string describing how the scanner's user refers
361 	 * to symbols (NULL defaults to "symbol"). This is used if
362 	 * expected_token is G_TOKEN_SYMBOL or any token value greater
363 	 * than G_TOKEN_LAST.
364 	 * symbolName = the name of the symbol, if the scanner's current
365 	 * token is a symbol.
366 	 * message = a message string to output at the end of the
367 	 * warning/error, or NULL.
368 	 * isError = if TRUE it is output as an error. If FALSE it is
369 	 * output as a warning.
370 	 */
371 	public void unexpToken(GTokenType expectedToken, string identifierSpec, string symbolSpec, string symbolName, string message, int isError)
372 	{
373 		// 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);
374 		g_scanner_unexp_token(gScanner, expectedToken, Str.toStringz(identifierSpec), Str.toStringz(symbolSpec), Str.toStringz(symbolName), Str.toStringz(message), isError);
375 	}
376 }