2 /* scan.lex -- scanner for the IDL compiler
4 * Written by Scott Wood <scott@buserror.net>
17 int curline, comment_level=0;
25 interface return TOK_IFACE;
26 const return TOK_CONST;
30 ushort return TOK_USHORT;
32 ulong return TOK_ULONG;
33 short return TOK_SHORT;
36 fshort return TOK_FSHORT;
37 flong return TOK_FLONG;
38 struct return TOK_STRUCT;
40 octet return TOK_OCTET;
51 \.\.\. return TOK_3DOT;
56 bitfield return TOK_BITFIELD;
58 namespace return TOK_NAMESPACE;
59 using return TOK_USING;
60 async return TOK_ASYNC;
62 inout return TOK_INOUT;
63 shared return TOK_SHARED;
65 typedef return TOK_TYPEDEF;
66 alias return TOK_ALIAS;
67 upcast return TOK_INVALID;
68 downcast return TOK_INVALID;
69 ifaceref return TOK_INVALID;
70 virtual return TOK_VIRTUAL;
72 inline return TOK_INLINE;
73 static return TOK_STATIC;
74 immutable return TOK_IMMUTABLE;
76 false return TOK_FALSE;
78 name return TOK_NAME; // CDL tokens
79 method return TOK_METHOD;
80 class return TOK_CLASS;
84 <*>\r // Put up with DOS files
86 [[:alpha:]][[:alnum:]_]* {
87 // Leading underscores and digits are prohibited by the regex.
88 if (yytext[yyleng - 1] == '_') {
89 yyerrorf("Identifier \"%s\" has a trailing underscore.",
91 } else if (strstr(yytext, "__")) {
92 yyerrorf("Identifier \"%s\" has contiguous underscores.",
94 } else if (!strncmp(yytext, "IDL_", 4)) {
95 yyerrorf("Identifier \"%s\" begins with the reserved "
96 "\"IDL_\" prefix.", yytext);
97 } else if (strstr(yytext, "IDLNS")) {
98 yyerrorf("Identifier \"%s\" contains the reserved sequence "
99 "\"IDLNS\".", yytext);
100 } else if (!strcmp(yytext + yyleng - 3, "_ns")) {
101 yyerrorf("Identifier \"%s\" ends with the reserved suffix \"_ns\".", yytext);
104 *yylval_string = new String(yytext, cur_input_file, curline, TOK_IDENT);
112 if (strchr(yytext, '8') || strchr(yytext, '9')) {
113 yyerrorf("Invalid digit in octal constant %s.", yytext);
114 yylval_con->type = TOK_INVALID;
115 yylval_con->con.ucon = 0;
119 yylval_con->con.ucon = strtoull(yytext, NULL, 8);
121 if (errno == ERANGE) {
122 yyerrorf("Constant %s is out of range.", yytext);
123 yylval_con->type = TOK_INVALID;
124 yylval_con->con.ucon = 0;
125 } else if (yylval_con->con.ucon > LLONG_MAX) {
126 yylval_con->type = TOK_UCON;
128 yylval_con->type = TOK_ICON;
131 return yylval_con->type;
136 yylval_con->con.ucon = strtoull(yytext, NULL, 16);
138 if (errno == ERANGE) {
139 yyerrorf("Constant %s is out of range.", yytext);
140 yylval_con->type = TOK_INVALID;
141 yylval_con->con.ucon = 0;
142 } else if (yylval_con->con.ucon > LLONG_MAX) {
143 yylval_con->type = TOK_UCON;
145 yylval_con->type = TOK_ICON;
148 return yylval_con->type;
153 yylval_con->con.ucon = strtoull(yytext, NULL, 10);
155 if (errno == ERANGE) {
156 yyerrorf("Constant %s is out of range.", yytext);
157 yylval_con->type = TOK_INVALID;
158 yylval_con->con.ucon = 0;
159 } else if (yylval_con->con.ucon > LLONG_MAX) {
160 yylval_con->type = TOK_UCON;
162 yylval_con->type = TOK_ICON;
165 return yylval_con->type;
168 [0-9]*\.[0-9]+([eE][+-][0-9]+)? {
170 yylval_con->con.fcon = strtod(yytext, NULL);
172 if (errno == ERANGE) {
173 yyerrorf("Constant %s is out of range.", yytext);
174 yylval_con->con.fcon = 0;
175 yylval_con->type = TOK_INVALID;
177 yylval_con->type = TOK_FCON;
180 return yylval_con->type;
187 *yylval_string = new String("", cur_input_file, curline, TOK_STR);
196 \\\" **yylval_string += '"';
197 \\\n **yylval_string += '\n';
198 \\\\ **yylval_string += '\\';
200 yyerrorf("Unknown escape sequence '\\%c'.", yytext[1]);
201 **yylval_string += yytext[1];
204 yyerrorf("Unterminated string literal at line %d.", curline);
208 [^\\\"\n]+ **yylval_string += yytext;
217 "/*" comment_level++;
218 "*/" if (!(--comment_level)) BEGIN(INITIAL);
225 "//" BEGIN(LINECOMMENT);
232 [[:blank:]]+ /* Whitespace */
239 yyerrorf("End of file within comment.");
241 // Keep message from occurring twice if parse is OK
249 if (isprint(yytext[0]))
250 yyerrorf("Unexpected character '%c'.", yytext[0]);
252 yyerrorf("Unexpected character #%d.", yytext[0]);
260 yyerrorf("End of file within comment.");