~ubuntu-branches/ubuntu/warty/orbit/warty

« back to all changes in this revision

Viewing changes to libIDL/lexer.l

  • Committer: Bazaar Package Importer
  • Author(s): Chris Waters
  • Date: 2002-06-02 19:43:11 UTC
  • Revision ID: james.westby@ubuntu.com-20020602194311-vaexyon6f1ht295e
Tags: upstream-0.5.16
ImportĀ upstreamĀ versionĀ 0.5.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 
 
3
    lexer.l (IDL lex scanner)
 
4
 
 
5
    Copyright (C) 1998, 1999 Andrew T. Veliath
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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.
 
20
 
 
21
    $Id: lexer.l,v 1.72.4.2 2001/09/11 22:25:37 sopwith Exp $
 
22
 
 
23
***************************************************************************/
 
24
%{
 
25
#include <assert.h>
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <ctype.h>
 
29
#include <string.h>
 
30
#include "rename.h"
 
31
#include "util.h"
 
32
#include "parser.h"
 
33
 
 
34
#ifdef XP_MAC
 
35
#  include <unix.h>
 
36
#  define YY_NEVER_INTERACTIVE 1
 
37
#endif
 
38
 
 
39
/* Eliminate warning */
 
40
#define YY_NO_UNPUT 1
 
41
 
 
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 && \
 
45
                    ferror (yyin))                                              \
 
46
                        YY_FATAL_ERROR ("input in scanner failed");             \
 
47
        } else {                                                                \
 
48
                union IDL_input_data data;                                      \
 
49
                                                                                \
 
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);            \
 
54
                if (result < 0)                                                 \
 
55
                        YY_FATAL_ERROR ("input callback returned failure");     \
 
56
        }                                                                       \
 
57
} while (0)
 
58
 
 
59
#define tokreturn(token)                        do {    \
 
60
        __IDL_prev_token_line = __IDL_cur_token_line;   \
 
61
        __IDL_cur_token_line = __IDL_cur_line;          \
 
62
        return token;                                   \
 
63
} while (0)
 
64
 
 
65
#define SELECT_START                            \
 
66
        /* Parser driven start conditions */    \
 
67
        if (__IDL_flagsi & IDLFP_PROPERTIES)    \
 
68
                BEGIN (PROP);                   \
 
69
        else if (__IDL_flagsi & IDLFP_NATIVE)   \
 
70
                BEGIN (NATIVE);                 \
 
71
        /* Global syntax start conditions */    \
 
72
        else if (__IDL_flags & IDLF_XPIDL)      \
 
73
                BEGIN (XP);                     \
 
74
        else if (__IDL_flags & IDLF_CODEFRAGS)  \
 
75
                BEGIN (CFRG);
 
76
 
 
77
#define SELECT_RESTART                          \
 
78
        SELECT_START                            \
 
79
        else                                    \
 
80
                BEGIN (INITIAL);
 
81
 
 
82
extern void             __IDL_do_pragma                 (const char *s);
 
83
static int              count_nl                        (const char *s);
 
84
 
 
85
#ifdef YYDEBUG
 
86
extern int                              yydebug;
 
87
#endif
 
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;
 
94
%}
 
95
 
 
96
whitespace              [ \t\v\f\r]*
 
97
whitespacenl            [ \t\v\f\r\n]*
 
98
newline                 \n
 
99
cpp_pragma              ^{whitespace}#{whitespace}pragma{whitespace}.*
 
100
cpp_status              ^{whitespace}#.*
 
101
b8_int                  0[0-9]*
 
102
b10_uint                [1-9][0-9]*
 
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              \([^\)]+\)
 
112
native_type             [^\)]+\)
 
113
sqstring                \'[^\'\n]*[\'\n]
 
114
dqstring                \"[^\"\n]*[\"\n]
 
115
 
 
116
%p 5000
 
117
 
 
118
%s XP
 
119
 
 
120
%x PROP
 
121
%x NATIVE
 
122
 
 
123
%s CFRG
 
124
%x CFRGX
 
125
 
 
126
%%
 
127
 
 
128
        SELECT_START;
 
129
 
 
130
<INITIAL,XP,CFRG>^%\{.*                                 {
 
131
        char *s = yytext + 2;
 
132
 
 
133
        while (isspace (*s)) ++s;
 
134
        codefrag_desc = g_strdup (s);
 
135
        codefrag_list = codefrag_list_tail = NULL;
 
136
 
 
137
        if (!(__IDL_flags & IDLF_XPIDL || __IDL_flags & IDLF_CODEFRAGS))
 
138
                yyerror ("Code fragment syntax not enabled");
 
139
        else
 
140
                BEGIN (CFRGX);
 
141
}
 
142
<CFRGX>^%\}.*                                           {
 
143
        yylval.tree = IDL_codefrag_new (codefrag_desc, codefrag_list);
 
144
        tokreturn (TOK_CODEFRAG);
 
145
}
 
146
<CFRGX>.*                                               {
 
147
        char *s;
 
148
        GSList *slist;
 
149
 
 
150
        s = g_strdup (yytext);
 
151
        slist = g_slist_alloc ();
 
152
        slist->data = s;
 
153
 
 
154
        if (codefrag_list == NULL) {
 
155
                codefrag_list = slist;
 
156
                codefrag_list_tail = slist;
 
157
        } else {
 
158
                codefrag_list_tail->next = slist;
 
159
                codefrag_list_tail = slist;
 
160
        }
 
161
}
 
162
<*>{cpp_pragma}                                         {
 
163
        int n;
 
164
        char *p = yytext;
 
165
        char *s, *t;
 
166
 
 
167
        while (isspace (*p) || *p == '#') ++p;
 
168
        s = p;
 
169
        sscanf (p, "%*6s%n", &n); s += n;
 
170
        while (isspace (*s)) ++s;
 
171
 
 
172
        t = s + strlen(s) - 1;
 
173
        while(isspace(*t) && t > s) *(t--) = '\0'; /* Chomp trailing spaces */
 
174
 
 
175
        __IDL_do_pragma (s);
 
176
}
 
177
<*>{cpp_status}                                         {
 
178
        char *starttext;
 
179
        char *filename;
 
180
        char *filename2;
 
181
        int line;
 
182
 
 
183
        starttext = yytext;
 
184
        while (isspace (*starttext)) ++starttext;
 
185
        filename = g_malloc (strlen (starttext) + 1);
 
186
 
 
187
        if (sscanf (starttext, "# %d %s", &line, filename) == 2) {
 
188
 
 
189
                if (*filename == '"') {
 
190
                        filename2 = g_strdup (filename + 1);
 
191
                        filename2[strlen (filename) - 2] = 0;
 
192
                        g_free (filename);
 
193
                } else
 
194
                        filename2 = filename;
 
195
 
 
196
                IDL_file_set (filename2, line);
 
197
 
 
198
                g_free (filename2);
 
199
        } else
 
200
                g_free (filename);
 
201
}
 
202
<*>{whitespace}                                         ;
 
203
{b8_int}                                                {
 
204
        sscanf (yytext, "%" IDL_LL "o", &yylval.integer);
 
205
        tokreturn (TOK_INTEGER);
 
206
}
 
207
{b10_uint}                                              {
 
208
        sscanf (yytext, "%" IDL_LL "u", &yylval.integer);
 
209
        tokreturn (TOK_INTEGER);
 
210
}
 
211
{b16_int}                                               {
 
212
        sscanf (yytext + 2, "%" IDL_LL "x", &yylval.integer);
 
213
        tokreturn (TOK_INTEGER);
 
214
}
 
215
{fixed_lit}                                             {
 
216
        yylval.str = g_strdup (yytext);
 
217
        tokreturn (TOK_FIXEDP);
 
218
}
 
219
{float_lit}                                             {
 
220
        yylval.floatp = atof (yytext);
 
221
        tokreturn (TOK_FLOATP);
 
222
}
 
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);
 
265
{declspec}                                              {
 
266
        char *s = g_strdup (yytext);
 
267
 
 
268
        /* Get the parenthesized expression (ignoring whitespace) */
 
269
        sscanf (yytext, "__declspec %*[(] %[A-Za-z_] %*[)]", s);
 
270
        yylval.str = s;
 
271
        __IDL_cur_line += count_nl (yytext);
 
272
        tokreturn (TOK_DECLSPEC);
 
273
}
 
274
{happy_ident}                                           {
 
275
        if (__IDL_flags & IDLF_TYPECODES && strcmp (yytext, "TypeCode") == 0)
 
276
                tokreturn (TOK_TYPECODE);
 
277
        yylval.str = g_strdup (yytext);
 
278
        tokreturn (TOK_IDENT);
 
279
}
 
280
{err1_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);
 
285
}
 
286
{warn1_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;
 
292
        }
 
293
        yylval.str = g_strdup (yytext);
 
294
        tokreturn (TOK_IDENT);
 
295
}
 
296
<PROP>]                                                 {
 
297
        __IDL_flagsi &= ~IDLFP_PROPERTIES;
 
298
        SELECT_RESTART;
 
299
        tokreturn (yytext[0]);
 
300
}
 
301
<PROP>{prop_key}                                        {
 
302
        yylval.str = g_strdup (yytext);
 
303
        tokreturn (TOK_PROP_KEY);
 
304
}
 
305
<PROP>{prop_value}                                      {
 
306
        yylval.str = g_strdup (yytext + 1);
 
307
        yylval.str[strlen (yylval.str) - 1] = 0;
 
308
        tokreturn (TOK_PROP_VALUE);
 
309
}
 
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);
 
315
}
 
316
{sqstring}                                              {
 
317
        yylval.str = g_strdup (yytext + 1);
 
318
        yylval.str[strlen (yytext) - 2] = 0;
 
319
        tokreturn (TOK_SQSTRING);
 
320
}
 
321
{dqstring}                                              {
 
322
        yylval.str = g_strdup (yytext + 1);
 
323
        yylval.str[strlen (yytext) - 2] = 0;
 
324
        tokreturn (TOK_DQSTRING);
 
325
}
 
326
<*>{newline}            ++__IDL_cur_line;
 
327
<*>\/\/.*               ;
 
328
<*>\/\*                                                 {
 
329
        int c;
 
330
 
 
331
        while (1) {
 
332
                while ((c = input ()) != '*' && c != EOF)
 
333
                        if (c == '\n') ++__IDL_cur_line;
 
334
                if (c == '*') {
 
335
                        while ((c = input ()) == '*') ;
 
336
                        if (c == '/') break;
 
337
                }
 
338
                if (c == '\n') ++__IDL_cur_line;
 
339
                if (c == EOF) {
 
340
                        yywarning (IDL_WARNING1, "End of file in comment");
 
341
                        break;
 
342
                }
 
343
        }
 
344
}
 
345
<*>.                    tokreturn (yytext[0]);
 
346
 
 
347
%%
 
348
 
 
349
void __IDL_lex_init (void)
 
350
{
 
351
        __IDL_inputcb = NULL;
 
352
        __IDL_cur_line = 1;
 
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;
 
358
}
 
359
 
 
360
void __IDL_lex_cleanup (void)
 
361
{
 
362
        __IDL_cur_filename = NULL;
 
363
        YY_NEW_FILE;
 
364
}
 
365
 
 
366
int yywrap (void)
 
367
{
 
368
        return 1;
 
369
}
 
370
 
 
371
static int count_nl (const char *s)
 
372
{
 
373
        int i;
 
374
 
 
375
        for (i = 0;
 
376
             (s = strchr (s, '\n')) != NULL;
 
377
             ++s, ++i) ;
 
378
 
 
379
        return i;
 
380
}
 
381
 
 
382
/*
 
383
 * Local variables:
 
384
 * mode: C
 
385
 * c-basic-offset: 8
 
386
 * tab-width: 8
 
387
 * indent-tabs-mode: t
 
388
 * End:
 
389
 */