summaryrefslogtreecommitdiff
path: root/giscanner/scannerlexer.l
diff options
context:
space:
mode:
authorAndreas Rottmann <a.rottmann@gmx.at>2010-12-07 00:18:15 +0100
committerAndreas Rottmann <a.rottmann@gmx.at>2010-12-07 00:18:15 +0100
commitd85dbebee2c565a911c79dd199f0e70020f2918a (patch)
tree8e6c4f829c61b6d40647a53f1ed31bf2a81b1a81 /giscanner/scannerlexer.l
parentf135e6f2f81e9dd52385cb1449779ef420c950c3 (diff)
downloadgobject-introspection-d85dbebee2c565a911c79dd199f0e70020f2918a.tar.gz
Support glib-mkenums comment /*< flags >*/
- Modify the lexer to consider all "trigraph" comments specially, and parse them for "flags" as well as "private" and "public" (which were previously hardcoded). This change allows for future support of multiple annotations inside a single trigraph comment. - Change the parser to consider the additional field "flags" set by the lexer when constructing enums. - Add a test case for the "flags" trigraph comment to the scanner annotation tests. See <https://bugzilla.gnome.org/show_bug.cgi?id=631530>.
Diffstat (limited to 'giscanner/scannerlexer.l')
-rw-r--r--giscanner/scannerlexer.l31
1 files changed, 29 insertions, 2 deletions
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index e06bc85d..6a403984 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -3,6 +3,7 @@
*
* Copyright (c) 1997 Sandro Sigala <ssigala@globalnet.it>
* Copyright (c) 2007-2008 Jürg Billeter <j@bitron.ch>
+ * Copyright (c) 2010 Andreas Rottmann <a.rottmann@gmx.at>
*
* All rights reserved.
*
@@ -46,6 +47,7 @@ extern int yylex (GISourceScanner *scanner);
#define YY_DECL int yylex (GISourceScanner *scanner)
static int yywrap (void);
static void parse_comment (GISourceScanner *scanner);
+static void parse_trigraph (GISourceScanner *scanner);
static void process_linemarks (GISourceScanner *scanner);
static int check_identifier (GISourceScanner *scanner, const char *);
static int parse_ignored_macro (void);
@@ -72,8 +74,7 @@ stringtext ([^\\\"])|(\\.)
[\t\f\v\r ]+ { /* Ignore whitespace. */ }
"/*" { parse_comment(scanner); }
-"/*"[\t ]*<[\t ]*"private"[\t ]*>" */" { scanner->private = TRUE; }
-"/*"[\t ]*<[\t ]*"public"[\t ]*>" */" { scanner->private = FALSE; }
+"/*"[\t ]?<[\t ,=A-Za-z0-9_]+>[\t ]?"*/" { parse_trigraph(scanner); }
"//".* { }
"#define "[a-zA-Z_][a-zA-Z_0-9]*"(" { yyless (yyleng - 1); return FUNCTION_MACRO; }
@@ -330,3 +331,29 @@ parse_ignored_macro (void)
return TRUE;
}
+
+static void
+parse_trigraph (GISourceScanner *scanner)
+{
+ char **items;
+ char *start, *end;
+ int i;
+
+ start = g_strstr_len (yytext, yyleng, "<");
+ g_assert (start != NULL);
+ end = g_strstr_len (yytext, yyleng, ">");
+ g_assert (end != NULL);
+ *end = '\0';
+ items = g_strsplit (start + 1, ",", 0);
+ for (i = 0; items[i] != NULL; i++) {
+ char *item = items[i];
+ g_strstrip (item);
+ if (strcmp (item, "public") == 0)
+ scanner->private = FALSE;
+ else if (strcmp (item, "private") == 0)
+ scanner->private = TRUE;
+ else if (strcmp (item, "flags") == 0)
+ scanner->flags = TRUE;
+ }
+ g_strfreev (items);
+}