nsgenbind
Loading...
Searching...
No Matches
nsgenbind-lexer.l
Go to the documentation of this file.
1%{
2
3/* lexer for the binding generation config file
4 *
5 * This file is part of nsgenbind.
6 * Licensed under the MIT License,
7 * http://www.opensource.org/licenses/mit-license.php
8 * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
9 */
10
11#include <stdbool.h>
12#include <stdio.h>
13#include <string.h>
14
15#include "nsgenbind-parser.h"
16#include "nsgenbind-ast.h"
17
18#define YY_USER_ACTION \
19 yylloc->first_line = yylloc->last_line = yylineno; \
20 yylloc->first_column = yylloc->last_column + 1; \
21 yylloc->last_column += yyleng;
22
23
24/* Ensure compatability with bison 2.6 and later */
25#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED && defined NSGENBIND_STYPE_IS_DECLARED
26#define YYSTYPE NSGENBIND_STYPE
27#endif
28
29#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED && defined NSGENBIND_LTYPE_IS_DECLARED
30#define YYLTYPE NSGENBIND_LTYPE
31#endif
32
33static struct YYLTYPE *locations = NULL;
34
35static struct YYLTYPE *push_location(struct YYLTYPE *head,
36 struct YYLTYPE *loc,
37 const char *filename)
38{
39 struct YYLTYPE *res;
40 res = calloc(1, sizeof(struct YYLTYPE));
41 /* copy current location and line number */
42 *res = *loc;
43 res->start_line = yylineno;
44 res->next = head;
45
46 /* reset current location */
47 loc->first_line = loc->last_line = 1;
48 loc->first_column = loc->last_column = 1;
49 loc->filename = strdup(filename);
50 yylineno = 1;
51
52 return res;
53}
54
55static struct YYLTYPE *pop_location(struct YYLTYPE *head, struct YYLTYPE *loc)
56{
57 struct YYLTYPE *res = NULL;
58
59 if (head != NULL) {
60 res = head->next;
61 *loc = *head;
62 free(head);
63
64 yylineno = loc->start_line;
65 }
66 return res;
67}
68
69
DOMString filename
Definition html.idl:1561
#define yylineno
void free(void *)
struct YYLTYPE * next
char * filename
70%}
71
72/* lexer options */
73%option never-interactive
74%option yylineno
75%option bison-bridge
76%option bison-locations
77%option nodefault
78%option warn
79%option prefix="nsgenbind_"
80%option nounput
81%option noinput
82%option noyywrap
83
84/* other Unicode “space separator” */
85USP (\xe1\x9a\x80)|(\xe1\xa0\x8e)|(\xe2\x80[\x80-\x8a])|(\xe2\x80\xaf)|(\xe2\x81\x9f)|(\xe3\x80\x80)
86
87/* non breaking space \u00A0 */
88NBSP (\xc2\xa0)
89
90/* Line separator \u2028 */
91LS (\xe2\x80\xa8)
92
93/* paragraph separator \u2029 */
94PS (\xe2\x80\xa9)
95
96whitespace ([ \t\v\f]|{NBSP}|{USP})
97
98lineend ([\n\r]|{LS}|{PS})
99
100multicomment \/\*(([^*])|(\*[^/]))*\*\/
101
102quotedstring [^\"\\\n\r]
103
104identifier [A-Z_a-z][0-9A-Z_a-z]*
105
106other [^\t\n\r 0-9A-Z_a-z]
107
108cblockopen \%\{
109
110cblockclose \%\}
111
112/* used for #include directive */
113poundsign ^{whitespace}*#
114
115dblcolon \:\:
116
117%x cblock
118
119%x incl
120
122
123{whitespace} ++yylloc->last_column;/* nothing */
YYLTYPE * yylloc
124
125{lineend} if (yytext[0] != '\r') {
126 /* update position counts */
127 ++yylloc->last_line;
128 yylloc->last_column = 0;
129 }
#define yytext
130
131 /* binding terminals */
132
133binding return TOK_BINDING;
@ TOK_BINDING
134webidl return TOK_WEBIDL;
@ TOK_WEBIDL
135preface return TOK_PREFACE;
@ TOK_PREFACE
136prologue return TOK_PROLOGUE;
@ TOK_PROLOGUE
137epilogue return TOK_EPILOGUE;
@ TOK_EPILOGUE
138postface return TOK_POSTFACE;
@ TOK_POSTFACE
139
140
141 /* class member terminals */
142
143class return TOK_CLASS;
@ TOK_CLASS
144private return TOK_PRIVATE;
@ TOK_PRIVATE
145internal return TOK_INTERNAL;
@ TOK_INTERNAL
146flags return TOK_FLAGS;
@ TOK_FLAGS
147type return TOK_TYPE;
@ TOK_TYPE
148unshared return TOK_UNSHARED;
@ TOK_UNSHARED
149shared return TOK_SHARED;
@ TOK_SHARED
150property return TOK_PROPERTY;
@ TOK_PROPERTY
151
152 /* implementation terminals */
153
154init return TOK_INIT;
@ TOK_INIT
155fini return TOK_FINI;
@ TOK_FINI
156method return TOK_METHOD;
@ TOK_METHOD
157getter return TOK_GETTER;
@ TOK_GETTER
158setter return TOK_SETTER;
@ TOK_SETTER
159prototype return TOK_PROTOTYPE;
@ TOK_PROTOTYPE
160
161 /* c type terminals */
162
163struct return TOK_STRUCT;
@ TOK_STRUCT
164union return TOK_UNION;
@ TOK_UNION
165unsigned return TOK_UNSIGNED;
@ TOK_UNSIGNED
166
167 /* other terminals */
168
169{dblcolon} return TOK_DBLCOLON;
@ TOK_DBLCOLON
170
171{cblockopen} BEGIN(cblock);
#define cblock
#define BEGIN
172
173{identifier} {
174 /* A leading "_" is used to escape an identifier from
175 * looking like a reserved word terminal.
176 */
177 yylval->text = (yytext[0] == '_') ? strdup(yytext + 1) : strdup(yytext);
178 return TOK_IDENTIFIER;
179 }
YYSTYPE * yylval
@ TOK_IDENTIFIER
180
181\"{quotedstring}*\" yylval->text = strndup(yytext + 1, yyleng - 2 ); return TOK_STRING_LITERAL;
#define yyleng
@ TOK_STRING_LITERAL
182
183{multicomment} /* nothing */
184
185{poundsign}include BEGIN(incl);
#define incl
186
187{other} return (int) yytext[0];
188
189. /* nothing */
190
191<cblock>[^\%]* yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
@ TOK_CCODE_LITERAL
192<cblock>{cblockclose} BEGIN(INITIAL);
#define INITIAL
193<cblock>\% yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
194
195
196<incl>[ \t]*\" /* eat the whitespace and open quotes */
197
198<incl>[^\t\n\"]+ {
199 /* got the include file name */
201
202 if (! yyin) {
203 fprintf(stderr, "Unable to open include %s\n", yytext);
204 exit(3);
205 }
206
207 locations = push_location(locations, yylloc, yytext);
208
210 BEGIN(INITIAL);
211 }
FILE * genbindopen(const char *filename)
#define yypush_buffer_state
#define yyin
#define yy_create_buffer
#define YY_BUF_SIZE
212
213<incl>\n BEGIN(INITIAL);
214
215<incl>. /* nothing */
216
217<<EOF>> {
219
220 if ( !YY_CURRENT_BUFFER ) {
221 yyterminate();
222 } else {
223 locations = pop_location(locations, yylloc);
224 BEGIN(incl);
225 }
226
227 }
#define YY_CURRENT_BUFFER
#define yypop_buffer_state
#define yyterminate()
228
229%%