summaryrefslogtreecommitdiff
path: root/docs/faq
diff options
context:
space:
mode:
authorBST 1999 Tony Gale <gale@gtk.org>1999-08-29 12:29:19 +0000
committerTony Gale <gale@src.gnome.org>1999-08-29 12:29:19 +0000
commitd5facc4cc6d996ce875c10181d4b1cc75fb64e48 (patch)
tree5b994cb23aa22c26489453af1fa5cdf41277cc71 /docs/faq
parentfc3cd85675a6edcfbe41a3bdf15faaa59573c114 (diff)
downloadgdk-pixbuf-d5facc4cc6d996ce875c10181d4b1cc75fb64e48.tar.gz
Minor FAQ Update
Sun Aug 29 13:38:59 BST 1999 Tony Gale <gale@gtk.org> Minor FAQ Update
Diffstat (limited to 'docs/faq')
-rw-r--r--docs/faq/gtkfaq.sgml70
1 files changed, 69 insertions, 1 deletions
diff --git a/docs/faq/gtkfaq.sgml b/docs/faq/gtkfaq.sgml
index 3ceeefba0..766c2affa 100644
--- a/docs/faq/gtkfaq.sgml
+++ b/docs/faq/gtkfaq.sgml
@@ -9,7 +9,7 @@
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
<author>Nathan Froyd, Tony Gale, Shawn T. Amundson, Emmanuel Deloget
-<date>August 28th 1999
+<date>August 29th 1999
<abstract> This document is intended to answer questions that are likely to be
frequently asked by programmers using GTK+ or people who are just looking at
@@ -2090,6 +2090,7 @@ parse_symbol (GScanner *scanner)
return G_TOKEN_NONE;
}
+
int
main (int argc, char *argv[])
{
@@ -2152,6 +2153,73 @@ main (int argc, char *argv[])
}
</verb>
+You need to understand that the scanner will parse it's input and
+tokenize it, it is up to you to interpret these tokens, not define
+their types before they get parsed, e.g. watch gscanner parse a string:
+
+<verb>
+"hi i am 17"
+ | | | |
+ | | | v
+ | | v TOKEN_INT, value: 17
+ | v TOKEN_IDENTIFIER, value: "am"
+ v TOKEN_CHAR, value: 'i'
+TOKEN_IDENTIFIER, value: "hi"
+</verb>
+
+If you configure the scanner with:
+<verb>
+scanner->config->int_2_float = TRUE;
+scanner->config->char_2_token = TRUE;
+scanner->config->scan_symbols = TRUE;
+</verb>
+
+and add "am" as a symbol with
+<verb>
+g_scanner_add_symbol (scanner, "am", "symbol value");
+</verb>
+
+GScanner will parse it as
+
+<verb>
+"hi i am 17"
+ | | | |
+ | | | v
+ | | v TOKEN_FLOAT, value: 17.0 (automatic int->float conversion)
+ | | TOKEN_SYMBOL, value: "symbol value" (a successfull hash table lookup
+ | | turned a TOKEN_IDENTIFIER into a
+ | | TOKEN_SYMBOL and took over the
+ | v symbol's value)
+ v 'i' ('i' can be a valid token as well, as all chars >0 and <256)
+TOKEN_IDENTIFIER, value: "hi"
+</verb>
+
+You need to match the token sequence with your code, and if you encounter
+something that you don't want, you error out:
+
+<verb>
+/* expect an identifier ("hi") */
+g_scanner_get_next_token (scanner);
+if (scanner->token != G_TOKEN_IDENTIFIER)
+ return G_TOKEN_IDENTIFIER;
+/* expect a token 'i' */
+g_scanner_get_next_token (scanner);
+if (scanner->token != 'i')
+ return 'i';
+/* expect a symbol ("am") */
+g_scanner_get_next_token (scanner);
+if (scanner->token != G_TOKEN_SYMBOL)
+ return G_TOKEN_SYMBOL;
+/* expect a float (17.0) */
+g_scanner_get_next_token (scanner);
+if (scanner->token != G_TOKEN_FLOAT)
+ return G_TOKEN_FLOAT;
+</verb>
+
+If you got past here, you have parsed "hi i am 17" and would have
+accepted "dooh i am 42" and "bah i am 0.75" as well, but you would
+have not accepted "hi 7 am 17" or "hi i hi 17".
+
<!-- ***************************************************************** -->
<sect>GTK+ FAQ Contributions, Maintainers and Copyright
<p>