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