📄 glib-lexical-scanner.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Lexical Scanner</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="next" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Miscellaneous-Utility-Functions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Automatic-String-Completion.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3080056" class="shortcut">Top</a>  |  <a href="#id3080915" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-Lexical-Scanner"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3080056"></a><span class="refentrytitle">Lexical Scanner</span></h2><p>Lexical Scanner — a general purpose lexical scanner</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h> <a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a>; <a class="link" href="glib-Lexical-Scanner.html#GScannerConfig">GScannerConfig</a>;<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a>* <a class="link" href="glib-Lexical-Scanner.html#g-scanner-new">g_scanner_new</a> (const <a class="link" href="glib-Lexical-Scanner.html#GScannerConfig">GScannerConfig</a> *config_templ);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-destroy">g_scanner_destroy</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-input-file">g_scanner_input_file</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#gint">gint</a> input_fd);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-sync-file-offset">g_scanner_sync_file_offset</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-input-text">g_scanner_input_text</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *text, <a class="link" href="glib-Basic-Types.html#guint">guint</a> text_len);<a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-peek-next-token">g_scanner_peek_next_token</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-get-next-token">g_scanner_get_next_token</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-eof">g_scanner_eof</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Basic-Types.html#guint">guint</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-cur-line">g_scanner_cur_line</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Basic-Types.html#guint">guint</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-cur-position">g_scanner_cur_position</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-cur-token">g_scanner_cur_token</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Lexical-Scanner.html#GTokenValue">GTokenValue</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-cur-value">g_scanner_cur_value</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner);<a class="link" href="glib-Basic-Types.html#guint">guint</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-set-scope">g_scanner_set_scope</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#guint">guint</a> scope_id);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-scope-add-symbol">g_scanner_scope_add_symbol</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#guint">guint</a> scope_id, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> value);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-scope-foreach-symbol">g_scanner_scope_foreach_symbol</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#guint">guint</a> scope_id, <a class="link" href="glib-Hash-Tables.html#GHFunc">GHFunc</a> func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-scope-lookup-symbol">g_scanner_scope_lookup_symbol</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#guint">guint</a> scope_id, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-scope-remove-symbol">g_scanner_scope_remove_symbol</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#guint">guint</a> scope_id, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol);#define <a class="link" href="glib-Lexical-Scanner.html#g-scanner-add-symbol">g_scanner_add_symbol</a> ( scanner, symbol, value )#define <a class="link" href="glib-Lexical-Scanner.html#g-scanner-remove-symbol">g_scanner_remove_symbol</a> ( scanner, symbol )#define <a class="link" href="glib-Lexical-Scanner.html#g-scanner-foreach-symbol">g_scanner_foreach_symbol</a> ( scanner, func, data )#define <a class="link" href="glib-Lexical-Scanner.html#g-scanner-freeze-symbol-table">g_scanner_freeze_symbol_table</a> (scanner)#define <a class="link" href="glib-Lexical-Scanner.html#g-scanner-thaw-symbol-table">g_scanner_thaw_symbol_table</a> (scanner)<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="glib-Lexical-Scanner.html#g-scanner-lookup-symbol">g_scanner_lookup_symbol</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-warn">g_scanner_warn</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-error">g_scanner_error</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *format, ...);void <a class="link" href="glib-Lexical-Scanner.html#g-scanner-unexp-token">g_scanner_unexp_token</a> (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a> expected_token, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *identifier_spec, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol_spec, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *symbol_name, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *message, <a class="link" href="glib-Basic-Types.html#gint">gint</a> is_error);void (<a class="link" href="glib-Lexical-Scanner.html#GScannerMsgFunc">*GScannerMsgFunc</a>) (<a class="link" href="glib-Lexical-Scanner.html#GScanner">GScanner</a> *scanner, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *message, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> error);#define <a class="link" href="glib-Lexical-Scanner.html#G-CSET-a-2-z">G_CSET_a_2_z</a>#define <a class="link" href="glib-Lexical-Scanner.html#G-CSET-A-2-Z:CAPS">G_CSET_A_2_Z</a>#define <a class="link" href="glib-Lexical-Scanner.html#G-CSET-DIGITS:CAPS">G_CSET_DIGITS</a>#define <a class="link" href="glib-Lexical-Scanner.html#G-CSET-LATINC:CAPS">G_CSET_LATINC</a>#define <a class="link" href="glib-Lexical-Scanner.html#G-CSET-LATINS:CAPS">G_CSET_LATINS</a>enum <a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a>;union <a class="link" href="glib-Lexical-Scanner.html#GTokenValue">GTokenValue</a>;enum <a class="link" href="glib-Lexical-Scanner.html#GErrorType">GErrorType</a>;</pre></div><div class="refsect1" lang="en"><a name="id3080915"></a><h2>Description</h2><p>The <a class="link" href="glib-Lexical-Scanner.html#GScanner"><span class="type">GScanner</span></a> and its associated functions provide a general purposelexical scanner.</p></div><div class="refsect1" lang="en"><a name="id3080944"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3080954"></a><h3><a name="GScanner"></a>GScanner</h3><a class="indexterm" name="id3080967"></a><pre class="programlisting">typedef struct { /* unused fields */ gpointer user_data; guint max_parse_errors; /* g_scanner_error() increments this field */ guint parse_errors; /* name of input stream, featured by the default message handler */ const gchar *input_name; /* quarked data */ GData *qdata; /* link into the scanner configuration */ GScannerConfig *config; /* fields filled in after g_scanner_get_next_token() */ GTokenType token; GTokenValue value; guint line; guint position; /* fields filled in after g_scanner_peek_next_token() */ GTokenType next_token; GTokenValue next_value; guint next_line; guint next_position; /* to be considered private */ GHashTable *symbol_table; gint input_fd; const gchar *text; const gchar *text_end; gchar *buffer; guint scope_id; /* handler function for _warn and _error */ GScannerMsgFunc msg_handler;} GScanner;</pre><p>The data structure representing a lexical scanner.</p><p>You should set <em class="structfield"><code>input_name</code></em> after creating the scanner, since it is used by the default message handler when displaying warnings and errors. If you are scanning a file, the file name would be a good choice.</p><p>The <em class="structfield"><code>user_data</code></em> and<em class="structfield"><code>max_parse_errors</code></em> fields are not used.If you need to associate extra data with the scanner you can place them here.</p><p>If you want to use your own message handler you can set the<em class="structfield"><code>msg_handler</code></em> field. The type of the messagehandler function is declared by <a class="link" href="glib-Lexical-Scanner.html#GScannerMsgFunc"><span class="type">GScannerMsgFunc</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> <em class="structfield"><code>user_data</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>max_parse_errors</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>parse_errors</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term">const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *<em class="structfield"><code>input_name</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Keyed-Data-Lists.html#GData">GData</a> *<em class="structfield"><code>qdata</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Lexical-Scanner.html#GScannerConfig">GScannerConfig</a> *<em class="structfield"><code>config</code></em>;</span></p></td><td></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Lexical-Scanner.html#GTokenType">GTokenType</a> <em class="structfield"><code>token</code></em>;</span></p></td><td> token parsed by the last <a class="link" href="glib-Lexical-Scanner.html#g-scanner-get-next-token"><code class="function">g_scanner_get_next_token()</code></a></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Lexical-Scanner.html#GTokenValue">GTokenValue</a> <em class="structfield"><code>value</code></em>;</span></p></td><td> value of the last token from <a class="link" href="glib-Lexical-Scanner.html#g-scanner-get-next-token"><code class="function">g_scanner_get_next_token()</code></a></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>line</code></em>;</span></p></td><td> line number of the last token from <a class="link" href="glib-Lexical-Scanner.html#g-scanner-get-next-token"><code class="function">g_scanner_get_next_token()</code></a></td></tr><tr><td><p><span class="term"><a class="link" href="glib-Basic-Types.html#guint">guint</a> <em class="structfield"><code>position</code></em>;</span></p></td><td> char number of the last token from <a class="link" href="glib-Lexical-Scanner.html#g-scanner-get-next-token"><code class="function">g_scanner_get_next_token()</code></a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -