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