summaryrefslogtreecommitdiff
path: root/giscanner/scannerlexer.l
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2009-01-12 20:11:44 +0000
committerJohan Dahlin <johan@src.gnome.org>2009-01-12 20:11:44 +0000
commit7dbbda9abea9882d2c98726f382a905fa8738706 (patch)
treebdf438fc921de19ddee90d7f2c5972cf76fec48f /giscanner/scannerlexer.l
parentba4ee2e606545ac703941698aa25e6d865e6976f (diff)
downloadgobject-introspection-7dbbda9abea9882d2c98726f382a905fa8738706.tar.gz
Bug 563794 - Redo annotation parsing & applying
2009-01-12 Johan Dahlin <jdahlin@async.com.br> Bug 563794 - Redo annotation parsing & applying Thanks to Colin for helping out considerably in landing this. * giscanner/Makefile.am: * giscanner/ast.py: * giscanner/dumper.py: * giscanner/girparser.py: * giscanner/giscannermodule.c (pygi_source_scanner_get_comments), (calc_attrs_length), (pygi_collect_attributes), (init_giscanner): * giscanner/glibtransformer.py: * giscanner/scannerlexer.l: * giscanner/sourcescanner.c (gi_source_symbol_unref), (gi_source_scanner_new), (gi_source_scanner_free), (gi_source_scanner_get_comments): * giscanner/sourcescanner.h: * giscanner/sourcescanner.py: * giscanner/transformer.py: * giscanner/xmlwriter.py: * tests/scanner/annotation-1.0-expected.gir: * tests/scanner/annotation-1.0-expected.tgir: * tests/scanner/annotation.c: * tests/scanner/annotation.h: * tests/scanner/foo-1.0-expected.gir: * tests/scanner/foo-1.0-expected.tgir: * tests/scanner/foo.h: * tools/g-ir-scanner: This commit merges the annotation parser rewrite branch. It'll change the annotation parsing to be done completely in python code which will make it easier to do further annotation parsing easier. svn path=/trunk/; revision=1017
Diffstat (limited to 'giscanner/scannerlexer.l')
-rw-r--r--giscanner/scannerlexer.l172
1 files changed, 6 insertions, 166 deletions
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index 27072cd4..53603e25 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -200,187 +200,27 @@ yywrap (void)
static void
-parse_gtkdoc (GISourceScanner *scanner,
- gchar *symbol,
- int *c1,
- int *c2)
-{
- gboolean isline = FALSE;
- GString *line_buf;
- char *line;
- gchar **parts;
- GISourceDirective *directive;
- char *name,*value;
- GSList *directives;
- GSList *options = NULL;
- char *rname;
- int n_parts;
-
- line_buf = g_string_new ("");
-
- do
- {
- *c1 = *c2;
- if (*c1 == '\n')
- {
- isline = TRUE;
- break;
- }
- g_string_append_c (line_buf, *c1);
- *c2 = input();
- } while (*c2 != EOF && !(*c1 == '*' && *c2 == '/'));
-
- if (!isline)
- {
- g_string_free (line_buf, TRUE);
- return;
- }
-
- line = g_string_free (line_buf, FALSE);
-
- /* Ignore lines that don't have a : - this is a hack but avoids
- * trying to parse too many things as annotations
- */
- if (!strchr (line, ':'))
- {
- g_free (line);
- return;
- }
-
- parts = g_strsplit (line, ":", 3);
- n_parts = g_strv_length (parts);
-
- if (g_ascii_strcasecmp (parts[0], "eprecated") == 0)
- {
- if (n_parts == 3)
- options = g_slist_prepend (options, g_strdup_printf ("%s: %s", parts[1], parts[2]));
- else if (n_parts == 2)
- options = g_slist_prepend (options, g_strdup (parts[1]));
- else
- options = g_slist_prepend (options, g_strdup (""));
- name = parts[0];
- value = NULL;
- }
- else if (g_ascii_strcasecmp (parts[0], "ince") == 0)
- {
- if (n_parts == 2)
- options = g_slist_prepend (options, g_strdup (parts[1]));
- else
- options = g_slist_prepend (options, g_strdup (""));
- name = parts[0];
- value = NULL;
- }
- else if (n_parts >= 2)
- {
- name = parts[0];
-
- if (n_parts == 3)
- {
- char *ptr = g_strdup (parts[1]);
- char *start;
- char *end;
-
- options = NULL;
- start = strchr (ptr, '(');
- while (start != NULL)
- {
- end = strchr (start, ')');
- if (end)
- {
- options = g_slist_prepend (options, g_strndup (start+1, end-(start+1)));
- start = strchr (end+1, '(');
- }
- else
- {
- break;
- }
- }
- g_free (ptr);
- value = parts[2];
- }
- else
- value = parts[1];
- }
- else /* parts == 1 */
- {
- name = parts[0];
- value = NULL;
- }
-
- /*
- * Special cases for global annotations.
- * Context-sensitive parsing would probably be the right way to go.
- */
- if (g_ascii_strncasecmp ("eturn", name, 5) == 0)
- rname = "return";
- else if (g_ascii_strncasecmp ("eprecated", name, 9) == 0)
- rname = "deprecated";
- else if (g_ascii_strncasecmp ("ince", name, 4) == 0)
- rname = "since";
- else
- rname = name;
-
- directive = gi_source_directive_new (rname, value, options);
- directives = g_hash_table_lookup (scanner->directives_map, symbol);
- directives = g_slist_prepend (directives, directive);
- g_hash_table_replace (scanner->directives_map,
- g_strdup (symbol), directives);
-
- g_strfreev (parts);
- g_free (line);
-}
-
-
-static void
parse_comment (GISourceScanner *scanner)
{
- GString *symbol = NULL;
- gboolean startofline = FALSE, have_symbol = FALSE, start1 = FALSE, start_symbol = FALSE;
+ GString *comment;
int c1, c2;
c1 = input();
c2 = input();
+ comment = g_string_new ("");
+
while (c2 != EOF && !(c1 == '*' && c2 == '/'))
{
- 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;
- }
+ g_string_append_c (comment, c1);
c1 = c2;
c2 = input();
- if ((c1 != '*' && c1 != ' '))
- startofline = FALSE;
-
- if (startofline && (c1 == ' ') && ((c2 == '@') || (c2 == 'r') || (c2 == 'R') || (c2 == 'D') || (c2 == 'S')))
- {
- c1 = c2;
- c2 = input();
- if (symbol)
- parse_gtkdoc (scanner, symbol->str, &c1, &c2);
- }
}
- if (symbol)
- g_string_free (symbol, TRUE);
-
+ scanner->comments = g_slist_prepend (scanner->comments,
+ g_string_free (comment, FALSE));
}
static int