summaryrefslogtreecommitdiff
path: root/src/genjsbind-lexer.l
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2012-10-21 12:56:50 +0100
committerVincent Sanders <vince@kyllikki.org>2012-10-21 12:56:50 +0100
commitd264e721abc7848ae4f82fbaae444245f0e1e2b9 (patch)
tree00255013bf0803c4badfa02313af5cdec4ff054d /src/genjsbind-lexer.l
parent903f328e2ea9405a0d351c828389cf0080670b6c (diff)
downloadnsgenbind-d264e721abc7848ae4f82fbaae444245f0e1e2b9.tar.gz
nsgenbind-d264e721abc7848ae4f82fbaae444245f0e1e2b9.tar.bz2
add includes in binding files to allow binding definitions to be split up
Diffstat (limited to 'src/genjsbind-lexer.l')
-rw-r--r--src/genjsbind-lexer.l41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/genjsbind-lexer.l b/src/genjsbind-lexer.l
index 2282c5e..3701252 100644
--- a/src/genjsbind-lexer.l
+++ b/src/genjsbind-lexer.l
@@ -13,6 +13,7 @@
#include <string.h>
#include "genjsbind-parser.h"
+#include "genjsbind-ast.h"
#define YY_USER_ACTION yylloc->first_line = yylloc->last_line; \
yylloc->first_column = yylloc->last_column + 1; \
@@ -60,8 +61,13 @@ cblockopen \%\{
cblockclose \%\}
+/* used for #include directive */
+poundsign ^{whitespace}*#
+
%x cblock
+%x incl
+
%%
{whitespace} ++yylloc->last_column;/* nothing */
@@ -104,12 +110,45 @@ operation return TOK_OPERATION;
{multicomment} /* nothing */
+{poundsign}include BEGIN(incl);
+
{other} return (int) yytext[0];
. /* nothing */
<cblock>[^\%]* yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
<cblock>{cblockclose} BEGIN(INITIAL);
-<cblock>\% yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
+<cblock>\% yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
+
+
+<incl>[ \t]*\" /* eat the whitespace and open quotes */
+
+<incl>[^\t\n\"]+ {
+ /* got the include file name */
+ yyin = genbindopen(yytext);
+
+ if (! yyin) {
+ fprintf(stderr, "Unable to open include %s\n", yytext);
+ exit(3);
+ }
+ yypush_buffer_state(yy_create_buffer( yyin, YY_BUF_SIZE ));
+
+ BEGIN(INITIAL);
+ }
+
+<incl>\n BEGIN(INITIAL);
+
+<incl>. /* nothing */
+
+<<EOF>> {
+ yypop_buffer_state();
+
+ if ( !YY_CURRENT_BUFFER ) {
+ yyterminate();
+ } else {
+ BEGIN(incl);
+ }
+
+ }
%%