]> git.saurik.com Git - wxWidgets.git/blame - src/common/lexer.l
MIME support
[wxWidgets.git] / src / common / lexer.l
CommitLineData
cfe780fb
JS
1SIGN [+-]
2DIGIT [0-9]
3ALPHA [a-zA-Z_]
4ALPHADIGIT [a-zA-Z_0-9]
5STRINGCHAR [^"\\]
6WORDCHAR [^'\\]
7
8%{
9/*
10 * File: lexer.l
11 * Description: Lexical analyser for PROLOGIO; can be used with
12 * either lex and flex.
13 */
14#include <string.h>
bbe0af5b 15#include <unistd.h>
cfe780fb
JS
16
17/* +++steve162e: added, otherwise, PROIO_input will be undefined (at least under LINUX)
18 please check, if this is also TRUE under other UNIXes.
19 */
20
21#if defined(FLEX_SCANNER) && defined(_LINUX)
22#define PROIO_input my_input
23#endif
24/* ---steve162e */
25
26#include "wx/expr.h"
27
28#ifdef wx_x
29extern char *malloc();
30#endif
31#define Return(x) return x;
32
33#if defined(VMS) && !defined(strdup)
34#define strdup(s) (strcpy((char *)malloc(strlen(s)+1), s));
35#endif
36
37static size_t lex_buffer_length = 0;
38static const char *lex_buffer = NULL;
39static size_t lex_string_ptr = 0;
40static int lex_read_from_string = 0;
41
42static int my_input(void);
43static int my_unput(char);
44
45#ifdef FLEX_SCANNER
46#undef YY_INPUT
47# define YY_INPUT(buf,result,max_size) \
48 if (lex_read_from_string) \
49 { int c = my_input(); result = (c == 0) ? YY_NULL : ((buf)[0]=(c), 1); } \
50 else \
51 if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
52 YY_FATAL_ERROR( "read() in flex scanner failed" );
53#else
54# undef unput
55# define unput(_c) my_unput(_c)
56#endif
57
58%}
59
60%%
61
62{SIGN}?{DIGIT}+ {yylval.s = strdup(yytext); Return(INTEGER);}
63
64"e" Return(EXP);
65
66{ALPHA}{ALPHADIGIT}* {yylval.s = strdup(yytext); Return(WORD);}
67
68"'"{WORDCHAR}*"'" {int len = strlen(yytext);
69 yytext[len-1] = 0;
70 yylval.s = strdup(yytext+1);
71 Return(WORD);}
72
73\"({STRINGCHAR}|\\\"|\|\\\\|\\)*\" {yylval.s = strdup(yytext); Return(STRING);}
74
75"(" Return(OPEN);
76
77")" Return(CLOSE);
78
79"," Return(COMMA);
80
81"[" Return(OPEN_SQUARE);
82
83"]" Return(CLOSE_SQUARE);
84
85"=" Return(EQUALS);
86
87"." Return(PERIOD);
88
89[ \t] ;
90
91\n ;
92
93"/*" { loop:
94#ifdef __cplusplus
95 while (yyinput() != '*');
96 switch (yyinput())
97#else
98 while (input() != '*');
99 switch (input())
100#endif
101 {
102 case '/': break;
103 case '*': unput('*');
104 default: goto loop;
105 }
106 }
107
108. Return(ERROR);
109
110%%
111
112
113#ifdef FLEX_SCANNER
114static int lex_input() {
115 return input();
116}
117#else /* BSD/AT&T lex */
118#ifndef input
119# error "Sorry, but need either flex or AT&T lex"
120#endif
121static int lex_input() {
122 return input();
123}
124/* # undef unput
125# define unput(_c) my_unput(_c)
126*/
127
128# undef input
129# define input() my_input()
130static int my_unput(char c)
131{
132 if (lex_read_from_string) {
133 /* Make sure we have something */
134 if (lex_string_ptr) {
135 if (c == '\n') yylineno--;
136 lex_string_ptr--;
137 }
138 } else {
139 yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;
140/* unput(c); Causes infinite recursion! */
141 }
142 return c;
143}
144
145#endif
146
147/* Public */
148void LexFromFile(FILE *fd)
149{
150 lex_read_from_string = 0;
151 yyin = fd;
152 /* Don't know why this is necessary, but otherwise
153 * lex only works _once_!
154 */
155#ifdef FLEX_SCANNER
156 yyrestart(fd);
157 yy_init = 1;
158#endif
159}
160
161void LexFromString(char *buffer)
162{
163 lex_read_from_string = 1;
164 lex_buffer = buffer;
165 lex_buffer_length = strlen(buffer);
166 lex_string_ptr = 0;
167 /* Don't know why this is necessary, but otherwise
168 * lex only works _once_!
169 */
170#ifdef FLEX_SCANNER
171 yy_init = 1;
172#endif
173}
174
175static int my_input( void )
176{
177 if (lex_read_from_string) {
178 if (lex_string_ptr == lex_buffer_length)
179 return 0;
180 else {
181 char c = lex_buffer[lex_string_ptr++];
182#ifndef FLEX_SCANNER
183 if (c == '\n') yylineno++;
184#endif
185 return c;
186 }
187 } else {
188 return lex_input();
189 }
190}
191
192void wxExprCleanUp()
193{
750b78ba 194#ifdef FLEX_SCANNER
cfe780fb
JS
195 if (yy_current_buffer)
196 yy_delete_buffer(yy_current_buffer);
750b78ba 197#endif
cfe780fb 198}