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