forked from erkyrath/Inform7-IDE-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIFError.l
More file actions
213 lines (164 loc) · 4.8 KB
/
IFError.l
File metadata and controls
213 lines (164 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
%{
//
// IFError.l
// Inform
//
// Created by Andrew Hunter on Mon Aug 18 2003.
// Copyright (c) 2003 Andrew Hunter. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "IFError.h"
int IFLexLastProgress;
char* IFLexLastProgressString;
struct errorValue {
IFLex style;
int line;
char* file;
};
static struct errorValue currentError;
%}
%option noyywrap
%x MPW_1
%x ERRORMESSAGE
%%
.*\ Inform\ [0-9]+\.[0-9]+\ \(.*\)\n { return IFLexCompilerVersion; }
Copy\ blorb\ to:\ \[\[.*\]\]\n {
// Blorb copy request
int copyLen = strlen(yytext)-19;
char* copyTo = calloc(copyLen, 1);
strncpy(copyTo, yytext + 17, copyLen);
copyTo[copyLen-1] = 0;
IFErrorCopyBlorbTo(copyTo);
free(copyTo);
return IFLexCompilerMessage;
}
\+\+\ ([0-9]+)\%\n {
// A progress line
IFLexLastProgress = atoi(yytext+3);
IFLexLastProgressString = NULL;
return IFLexProgress;
}
\+\+\ ([0-9]+)\%\ \(.*\)\n {
// A progress line with status text
IFLexLastProgress = atoi(yytext+3);
IFLexLastProgressString = yytext+3;
while (IFLexLastProgressString[0] != '(') IFLexLastProgressString++;
IFLexLastProgressString++;
return IFLexProgress;
}
File\ \".*\";\ Line\ {
// Beginning of an MPW-style error message
currentError.file = calloc(strlen(yytext)-13, 1);
strncpy(currentError.file, yytext + 6, strlen(yytext)-14);
BEGIN(MPW_1);
}
<MPW_1>[0-9]+\t#\ {
// MPW-style line number
currentError.line = atoi(yytext);
BEGIN(ERRORMESSAGE);
}
<MPW_1>. {
// Not MPW after all, something else thoroughly weird
free(currentError.file); currentError.file = NULL;
BEGIN(0);
return -1;
}
<ERRORMESSAGE>\w*\*\*\*\ Compiler\ error:.*\n {
char* comerr = strstr(yytext, "Compiler error:");
char* message = calloc(strlen(comerr), 1);
strncpy(message, comerr + 16, strlen(comerr)-17);
IFErrorAddError(currentError.file,
currentError.line,
IFLexCompilerFatalError,
message);
if (currentError.file) free(currentError.file);
free(message);
BEGIN(0);
return IFLexCompilerFatalError;
}
<ERRORMESSAGE>\w*Fatal\ error:.*\n {
char* comerr = strstr(yytext, "Fatal error:");
char* message = calloc(strlen(comerr), 1);
strncpy(message, comerr + 13, strlen(comerr)-14);
IFErrorAddError(currentError.file,
currentError.line,
IFLexCompilerFatalError,
message);
if (currentError.file) free(currentError.file);
free(message);
BEGIN(0);
return IFLexCompilerFatalError;
}
<ERRORMESSAGE>\w*Error:.*\n {
char* comerr = strstr(yytext, "Error:");
char* message = calloc(strlen(comerr), 1);
strncpy(message, comerr + 8, strlen(comerr)-9);
IFErrorAddError(currentError.file,
currentError.line,
IFLexCompilerError,
message);
if (currentError.file) free(currentError.file);
free(message);
BEGIN(0);
return IFLexCompilerError;
}
<ERRORMESSAGE>\w*Warning:.*\n {
char* comerr = strstr(yytext, "Warning:");
char* message = calloc(strlen(comerr), 1);
strncpy(message, comerr + 10, strlen(comerr)-11);
IFErrorAddError(currentError.file,
currentError.line,
IFLexCompilerWarning,
message);
if (currentError.file) free(currentError.file);
free(message);
BEGIN(0);
return IFLexCompilerWarning;
}
<ERRORMESSAGE>.*\n {
char* comerr = yytext;
char* message = calloc(strlen(comerr), 1);
strncpy(message, comerr, strlen(comerr)-1);
IFErrorAddError(currentError.file,
currentError.line,
IFLexCompilerMessage,
message);
if (currentError.file) free(currentError.file);
free(message);
BEGIN(0);
return IFLexCompilerMessage;
}
(\".*\",\ )?line\ [0-9]+\:\ .*\n {
// RISC OS style error
return IFLexCompilerError;
}
\>.*\n { return IFLexCompilerMessage; }
. { return -1; }
%%
int IFErrorScanString(const char* string) {
int len = strlen(string);
yy_delete_buffer(YY_CURRENT_BUFFER);
YY_BUFFER_STATE b;
char* oldbuf;
static char *buf = NULL;
yy_size_t n;
int i;
oldbuf = buf;
/* Get memory for full buffer, including space for trailing EOB's. */
n = len + 2;
buf = (char *) malloc( n );
if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in IFErrorScanString" );
for ( i = 0; i < len; ++i )
buf[i] = string[i];
buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR;
b = yy_scan_buffer( buf, n );
if ( ! b )
YY_FATAL_ERROR( "bad buffer in IFErrorScanString" );
if (oldbuf != NULL) {
free(oldbuf);
}
return yylex();
}