diff options
author | Philip Van Hoof <me@pvanhoof.be> | 2008-03-10 22:08:49 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-03-10 22:08:49 +0000 |
commit | b328ba7044dbfa26e01a85c7f0d11ba1a87a804e (patch) | |
tree | 3b3ff3705298681a29567bc78322e074e4875c3b /tools/scannerlexer.l | |
parent | 6015ef1e36a338a2e96b986aae1b2b32a7f3b427 (diff) | |
download | gobject-introspection-b328ba7044dbfa26e01a85c7f0d11ba1a87a804e.tar.gz |
reviewed and extensively tested by Johan
2008-03-10 Philip Van Hoof <me@pvanhoof.be>
reviewed and extensively tested by Johan
* tests/parser/Foo-expected.gidl:
* tests/parser/foo-object.h:
* tests/parser/foo.c:
* tools/gidlnode.c:
* tools/gidlnode.h:
* tools/gidlwriter.c:
* tools/scanner.c:
* tools/scanner.h:
* tools/scannerlexer.l:
* tools/scannerparser.y:
Add support for scanning for gtk-doc comments inside
C source files. Add tests
svn path=/trunk/; revision=140
Diffstat (limited to 'tools/scannerlexer.l')
-rw-r--r-- | tools/scannerlexer.l | 111 |
1 files changed, 87 insertions, 24 deletions
diff --git a/tools/scannerlexer.l b/tools/scannerlexer.l index 593c058c..f7dea412 100644 --- a/tools/scannerlexer.l +++ b/tools/scannerlexer.l @@ -178,57 +178,95 @@ static int yywrap (void) return 1; } -static void parse_gtkdoc (GIGenerator *igenerator, int *c1, int *c2) +static void parse_gtkdoc (GIGenerator *igenerator, gchar *symbol, int *c1, int *c2) { gboolean isline = FALSE; gchar line[256]; int i; gchar **parts; CDirective *directive; - char *name, *value; + char *name,*value; + GSList *directives; + GSList *options = NULL; i = 0; - do { + do + { *c1 = *c2; if (*c1 == '\n') - { - isline = TRUE; - break; - } + { + isline = TRUE; + break; + } if (i >= 256) - break; + break; line[i++] = *c1; *c2 = input(); - - } while (*c2 != EOF && !(*c1 == '*' && *c2 == '/')); + } while (*c2 != EOF && !(*c1 == '*' && *c2 == '/')); if (!isline) return; line[i] = '\0'; - parts = g_strsplit (line, ": ", 2); + parts = g_strsplit (line, ": ", 3); - if (g_strv_length (parts) == 2) + if (g_strv_length (parts) >= 2) { name = parts[0]; - value = parts[1]; + + if (g_strv_length (parts) == 3) + { + char *ptr = parts[1]; + GString *current = NULL; + gboolean open = FALSE; + + current = g_string_new (""); + value = parts[2]; + + while (*ptr++) + { + if (*ptr != ')') + g_string_append_c (current, *ptr); + else if (*ptr == ')') + options = g_slist_prepend (options, g_strdup (current->str)); + } + g_string_free (current, TRUE); + } + else + value = parts[1]; } else /* parts == 1 */ { name = parts[0]; value = NULL; } - - directive = cdirective_new (name, value); - igenerator->directives = g_slist_prepend (igenerator->directives, - directive); + + directive = cdirective_new (name, value, options); + + if (symbol == NULL) + { + igenerator->directives = g_slist_prepend (igenerator->directives, + directive); + } + else + { + directives = g_hash_table_lookup (igenerator->directives_map, symbol); + directives = g_slist_prepend (directives, directive); + g_hash_table_replace (igenerator->directives_map, + g_strdup (symbol), directives); + } + g_strfreev (parts); + } + static void parse_comment (GIGenerator *igenerator) { + GString *symbol = NULL; + gboolean startofline = FALSE, have_symbol = FALSE, start1 = FALSE, start_symbol = FALSE; int c1, c2; c1 = input(); @@ -236,18 +274,43 @@ static void parse_comment (GIGenerator *igenerator) while (c2 != EOF && !(c1 == '*' && c2 == '/')) { - if (c1 == '\n') - ++lineno; + if (c1 == ':') + have_symbol = TRUE; + else if (c1 == '\n') + start1 = TRUE; + else if (c1 == '*' && start1) + start_symbol = TRUE; + else if (!have_symbol && start_symbol) + { + if (!symbol) + symbol = g_string_new (""); + if (c1 != ' ') + g_string_append_c (symbol, c1); + } + + if (c1 == '\n') + { + ++lineno; + startofline = TRUE; + } + c1 = c2; c2 = input(); - if (c1 == ' ' && c2 == '@') - { - c1 = c2; - c2 = input(); - parse_gtkdoc (igenerator, &c1, &c2); + if ((c1 != '*' && c1 != ' ')) + startofline = FALSE; + + if (startofline && c1 == ' ' && c2 == '@') + { + c1 = c2; + c2 = input(); + parse_gtkdoc (igenerator, symbol ? symbol->str : NULL, &c1, &c2); + } } + if (symbol) + g_string_free (symbol, TRUE); + } static int check_identifier (GIGenerator *igenerator, const char *s) |