1
/***************************************************************************
3
lexer.l (IDL lex scanner)
5
Copyright (C) 1998, 1999 Andrew T. Veliath
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public
18
License along with this library; if not, write to the Free
19
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
$Id: lexer.l,v 1.72.4.2 2001/09/11 22:25:37 sopwith Exp $
23
***************************************************************************/
36
# define YY_NEVER_INTERACTIVE 1
39
/* Eliminate warning */
42
#define YY_INPUT(buf,result,the_max_size) do { \
43
if (__IDL_inputcb == NULL) { \
44
if ((result = fread (buf, 1, the_max_size, yyin)) == YY_NULL && \
46
YY_FATAL_ERROR ("input in scanner failed"); \
48
union IDL_input_data data; \
50
data.fill.buffer = buf; \
51
data.fill.max_size = the_max_size; \
52
result = (*__IDL_inputcb) (IDL_INPUT_REASON_FILL, &data, \
53
__IDL_inputcb_user_data); \
55
YY_FATAL_ERROR ("input callback returned failure"); \
59
#define tokreturn(token) do { \
60
__IDL_prev_token_line = __IDL_cur_token_line; \
61
__IDL_cur_token_line = __IDL_cur_line; \
65
#define SELECT_START \
66
/* Parser driven start conditions */ \
67
if (__IDL_flagsi & IDLFP_PROPERTIES) \
69
else if (__IDL_flagsi & IDLFP_NATIVE) \
71
/* Global syntax start conditions */ \
72
else if (__IDL_flags & IDLF_XPIDL) \
74
else if (__IDL_flags & IDLF_CODEFRAGS) \
77
#define SELECT_RESTART \
82
extern void __IDL_do_pragma (const char *s);
83
static int count_nl (const char *s);
88
int __IDL_prev_token_line;
89
int __IDL_cur_token_line;
90
static int warn_underscores;
91
static char * codefrag_desc;
92
static GSList * codefrag_list;
93
static GSList * codefrag_list_tail;
96
whitespace [ \t\v\f\r]*
97
whitespacenl [ \t\v\f\r\n]*
99
cpp_pragma ^{whitespace}#{whitespace}pragma{whitespace}.*
100
cpp_status ^{whitespace}#.*
103
b16_int 0[xX][0-9A-Fa-f]+
104
float_lit [0-9]*\.[0-9]+([eE]-?[0-9]+)?|[0-9]+\.?([eE]-?[0-9]+)?
105
fixed_lit ([0-9]*\.[0-9]+|-?[0-9]+\.?[0-9]*)[dD]
106
declspec __declspec{whitespacenl}\({whitespacenl}[A-Za-z]*{whitespacenl}\)
107
happy_ident [A-Za-z][A-Za-z0-9]*
108
err1_ident _[A-Za-z0-9_]+
109
warn1_ident [A-Za-z][A-Za-z0-9_]*
110
prop_key [A-Za-z][A-Za-z0-9_]*
111
prop_value \([^\)]+\)
113
sqstring \'[^\'\n]*[\'\n]
114
dqstring \"[^\"\n]*[\"\n]
130
<INITIAL,XP,CFRG>^%\{.* {
131
char *s = yytext + 2;
133
while (isspace (*s)) ++s;
134
codefrag_desc = g_strdup (s);
135
codefrag_list = codefrag_list_tail = NULL;
137
if (!(__IDL_flags & IDLF_XPIDL || __IDL_flags & IDLF_CODEFRAGS))
138
yyerror ("Code fragment syntax not enabled");
143
yylval.tree = IDL_codefrag_new (codefrag_desc, codefrag_list);
144
tokreturn (TOK_CODEFRAG);
150
s = g_strdup (yytext);
151
slist = g_slist_alloc ();
154
if (codefrag_list == NULL) {
155
codefrag_list = slist;
156
codefrag_list_tail = slist;
158
codefrag_list_tail->next = slist;
159
codefrag_list_tail = slist;
167
while (isspace (*p) || *p == '#') ++p;
169
sscanf (p, "%*6s%n", &n); s += n;
170
while (isspace (*s)) ++s;
172
t = s + strlen(s) - 1;
173
while(isspace(*t) && t > s) *(t--) = '\0'; /* Chomp trailing spaces */
184
while (isspace (*starttext)) ++starttext;
185
filename = g_malloc (strlen (starttext) + 1);
187
if (sscanf (starttext, "# %d %s", &line, filename) == 2) {
189
if (*filename == '"') {
190
filename2 = g_strdup (filename + 1);
191
filename2[strlen (filename) - 2] = 0;
194
filename2 = filename;
196
IDL_file_set (filename2, line);
204
sscanf (yytext, "%" IDL_LL "o", &yylval.integer);
205
tokreturn (TOK_INTEGER);
208
sscanf (yytext, "%" IDL_LL "u", &yylval.integer);
209
tokreturn (TOK_INTEGER);
212
sscanf (yytext + 2, "%" IDL_LL "x", &yylval.integer);
213
tokreturn (TOK_INTEGER);
216
yylval.str = g_strdup (yytext);
217
tokreturn (TOK_FIXEDP);
220
yylval.floatp = atof (yytext);
221
tokreturn (TOK_FLOATP);
223
FALSE tokreturn (TOK_FALSE);
224
Object tokreturn (TOK_OBJECT);
225
TRUE tokreturn (TOK_TRUE);
226
any tokreturn (TOK_ANY);
227
attribute tokreturn (TOK_ATTRIBUTE);
228
boolean tokreturn (TOK_BOOLEAN);
229
case tokreturn (TOK_CASE);
230
char tokreturn (TOK_CHAR);
231
const tokreturn (TOK_CONST);
232
context tokreturn (TOK_CONTEXT);
233
default tokreturn (TOK_DEFAULT);
234
double tokreturn (TOK_DOUBLE);
235
enum tokreturn (TOK_ENUM);
236
exception tokreturn (TOK_EXCEPTION);
237
fixed tokreturn (TOK_FIXED);
238
float tokreturn (TOK_FLOAT);
239
in tokreturn (TOK_IN);
240
inout tokreturn (TOK_INOUT);
241
interface tokreturn (TOK_INTERFACE);
242
long tokreturn (TOK_LONG);
243
module tokreturn (TOK_MODULE);
244
native tokreturn (TOK_NATIVE);
245
octet tokreturn (TOK_OCTET);
246
oneway tokreturn (TOK_ONEWAY);
247
out tokreturn (TOK_OUT);
248
raises tokreturn (TOK_RAISES);
249
readonly tokreturn (TOK_READONLY);
250
sequence tokreturn (TOK_SEQUENCE);
251
short tokreturn (TOK_SHORT);
252
string tokreturn (TOK_STRING);
253
struct tokreturn (TOK_STRUCT);
254
switch tokreturn (TOK_SWITCH);
255
typedef tokreturn (TOK_TYPEDEF);
256
union tokreturn (TOK_UNION);
257
unsigned tokreturn (TOK_UNSIGNED);
258
<XP>\.\.\. tokreturn (TOK_VARARGS);
259
void tokreturn (TOK_VOID);
260
wchar tokreturn (TOK_WCHAR);
261
wstring tokreturn (TOK_WSTRING);
262
:: tokreturn (TOK_OP_SCOPE);
263
\>\> tokreturn (TOK_OP_SHR);
264
\<\< tokreturn (TOK_OP_SHL);
266
char *s = g_strdup (yytext);
268
/* Get the parenthesized expression (ignoring whitespace) */
269
sscanf (yytext, "__declspec %*[(] %[A-Za-z_] %*[)]", s);
271
__IDL_cur_line += count_nl (yytext);
272
tokreturn (TOK_DECLSPEC);
275
if (__IDL_flags & IDLF_TYPECODES && strcmp (yytext, "TypeCode") == 0)
276
tokreturn (TOK_TYPECODE);
277
yylval.str = g_strdup (yytext);
278
tokreturn (TOK_IDENT);
281
yyerrorv ("`%s' is not a valid identifier in IDL", yytext);
282
yyerror ("(Identifiers cannot start with an underscore)");
283
yylval.str = g_strdup (yytext);
284
tokreturn (TOK_IDENT);
287
if (!warn_underscores) {
288
yywarningv (IDL_WARNING2,
289
"`%s' underscores within identifiers are discouraged for use "
290
"with C-language IDL mappings", yytext);
291
warn_underscores = 1;
293
yylval.str = g_strdup (yytext);
294
tokreturn (TOK_IDENT);
297
__IDL_flagsi &= ~IDLFP_PROPERTIES;
299
tokreturn (yytext[0]);
302
yylval.str = g_strdup (yytext);
303
tokreturn (TOK_PROP_KEY);
306
yylval.str = g_strdup (yytext + 1);
307
yylval.str[strlen (yylval.str) - 1] = 0;
308
tokreturn (TOK_PROP_VALUE);
310
<NATIVE>{native_type} {
311
__IDL_flagsi &= ~IDLFP_NATIVE;
312
yylval.str = g_strdup (yytext);
313
yylval.str[strlen (yylval.str) - 1] = 0;
314
tokreturn (TOK_NATIVE_TYPE);
317
yylval.str = g_strdup (yytext + 1);
318
yylval.str[strlen (yytext) - 2] = 0;
319
tokreturn (TOK_SQSTRING);
322
yylval.str = g_strdup (yytext + 1);
323
yylval.str[strlen (yytext) - 2] = 0;
324
tokreturn (TOK_DQSTRING);
326
<*>{newline} ++__IDL_cur_line;
332
while ((c = input ()) != '*' && c != EOF)
333
if (c == '\n') ++__IDL_cur_line;
335
while ((c = input ()) == '*') ;
338
if (c == '\n') ++__IDL_cur_line;
340
yywarning (IDL_WARNING1, "End of file in comment");
345
<*>. tokreturn (yytext[0]);
349
void __IDL_lex_init (void)
351
__IDL_inputcb = NULL;
353
__IDL_cur_token_line = 0;
354
__IDL_prev_token_line = 0;
355
__IDL_cur_filename = NULL;
356
__IDL_cur_fileinfo = NULL;
357
warn_underscores = 0;
360
void __IDL_lex_cleanup (void)
362
__IDL_cur_filename = NULL;
371
static int count_nl (const char *s)
376
(s = strchr (s, '\n')) != NULL;
387
* indent-tabs-mode: t