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