From d5facc4cc6d996ce875c10181d4b1cc75fb64e48 Mon Sep 17 00:00:00 2001 From: BST 1999 Tony Gale Date: Sun, 29 Aug 1999 12:29:19 +0000 Subject: [PATCH] Minor FAQ Update Sun Aug 29 13:38:59 BST 1999 Tony Gale Minor FAQ Update --- ChangeLog | 4 +++ ChangeLog.pre-2-0 | 4 +++ ChangeLog.pre-2-10 | 4 +++ ChangeLog.pre-2-2 | 4 +++ ChangeLog.pre-2-4 | 4 +++ ChangeLog.pre-2-6 | 4 +++ ChangeLog.pre-2-8 | 4 +++ docs/faq/gtkfaq.sgml | 70 +++++++++++++++++++++++++++++++++++++++++++- docs/gtkfaq.sgml | 70 +++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 166 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1287cfe64c..ff9458f1d6 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,7 @@ +Sun Aug 29 13:38:59 BST 1999 Tony Gale + + * docs/gtkfaq.sgml: Minor FAQ Update + Sat Aug 28 14:34:37 BST 1999 Tony Gale * docs/gtkfaq.sgml: FAQ update diff --git a/docs/faq/gtkfaq.sgml b/docs/faq/gtkfaq.sgml index 3ceeefba01..766c2affac 100644 --- a/docs/faq/gtkfaq.sgml +++ b/docs/faq/gtkfaq.sgml @@ -9,7 +9,7 @@ Nathan Froyd, Tony Gale, Shawn T. Amundson, Emmanuel Deloget -August 28th 1999 +August 29th 1999 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[]) } +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: + + +"hi i am 17" + | | | | + | | | v + | | v TOKEN_INT, value: 17 + | v TOKEN_IDENTIFIER, value: "am" + v TOKEN_CHAR, value: 'i' +TOKEN_IDENTIFIER, value: "hi" + + +If you configure the scanner with: + +scanner->config->int_2_float = TRUE; +scanner->config->char_2_token = TRUE; +scanner->config->scan_symbols = TRUE; + + +and add "am" as a symbol with + +g_scanner_add_symbol (scanner, "am", "symbol value"); + + +GScanner will parse it as + + +"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" + + +You need to match the token sequence with your code, and if you encounter +something that you don't want, you error out: + + +/* 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; + + +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". + GTK+ FAQ Contributions, Maintainers and Copyright

diff --git a/docs/gtkfaq.sgml b/docs/gtkfaq.sgml index 3ceeefba01..766c2affac 100644 --- a/docs/gtkfaq.sgml +++ b/docs/gtkfaq.sgml @@ -9,7 +9,7 @@ Nathan Froyd, Tony Gale, Shawn T. Amundson, Emmanuel Deloget -August 28th 1999 +August 29th 1999 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[]) } +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: + + +"hi i am 17" + | | | | + | | | v + | | v TOKEN_INT, value: 17 + | v TOKEN_IDENTIFIER, value: "am" + v TOKEN_CHAR, value: 'i' +TOKEN_IDENTIFIER, value: "hi" + + +If you configure the scanner with: + +scanner->config->int_2_float = TRUE; +scanner->config->char_2_token = TRUE; +scanner->config->scan_symbols = TRUE; + + +and add "am" as a symbol with + +g_scanner_add_symbol (scanner, "am", "symbol value"); + + +GScanner will parse it as + + +"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" + + +You need to match the token sequence with your code, and if you encounter +something that you don't want, you error out: + + +/* 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; + + +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". + GTK+ FAQ Contributions, Maintainers and Copyright