@@ -121,6 +121,11 @@ void Host_Repl(void) {
121
121
// REBOOL why_alert = TRUE;
122
122
123
123
#define MAX_CONT_LEVEL 1024
124
+ #define INPUT_NO_STRING 0
125
+ #define INPUT_SINGLE_LINE_STRING 1
126
+ #define INPUT_MULTI_LINE_STRING 2
127
+ #define INPUT_RAW_STRING 3
128
+
124
129
REBYTE cont_str [] = CONTIN_STR ;
125
130
REBCNT cont_level = 0 ;
126
131
REBYTE cont_stack [MAX_CONT_LEVEL ] = { 0 };
@@ -134,8 +139,10 @@ void Host_Repl(void) {
134
139
REBLEN line_len ;
135
140
136
141
REBYTE * utf8byte ;
137
- BOOL inside_short_str = FALSE ;
142
+ int raw_str_level = 0 ;
138
143
int long_str_level = 0 ;
144
+ int n = 0 ;
145
+ int state = INPUT_NO_STRING ;
139
146
140
147
while (TRUE) {
141
148
if (cont_level > 0 ) {
@@ -154,6 +161,7 @@ void Host_Repl(void) {
154
161
cont_level = 0 ;
155
162
input_len = 0 ;
156
163
input [0 ] = 0 ;
164
+ raw_str_level = 0 ;
157
165
continue ;
158
166
}
159
167
RESET_COLOR ;
@@ -163,45 +171,87 @@ void Host_Repl(void) {
163
171
line_len = 0 ;
164
172
for (utf8byte = line ; * utf8byte ; utf8byte ++ ) {
165
173
line_len ++ ;
166
- switch (* utf8byte ) {
167
- case '^' :
168
- if (* (utf8byte + 1 ) != 0 ) {
174
+ if (state == INPUT_NO_STRING )
175
+ {
176
+ switch (* utf8byte ) {
177
+ case '"' :
178
+ state = INPUT_SINGLE_LINE_STRING ;
179
+ break ;
180
+ case '[' :
181
+ case '(' :
182
+ if (cont_level < MAX_CONT_LEVEL ) cont_stack [cont_level ] = * utf8byte ;
183
+ cont_level ++ ;
184
+ break ;
185
+ case ']' :
186
+ case ')' :
187
+ if (cont_level > 0 ) cont_level -- ;
188
+ break ;
189
+ case '{' :
190
+ if (cont_level < MAX_CONT_LEVEL ) cont_stack [cont_level ] = * utf8byte ;
191
+ cont_level ++ ;
192
+ long_str_level ++ ;
193
+ state = INPUT_MULTI_LINE_STRING ;
194
+ break ;
195
+ case '%' :
196
+ n = 1 ;
197
+ while (utf8byte [n ] == '%' ) n ++ ;
198
+ if (utf8byte [n ] == '{' ) {
199
+ raw_str_level = n ;
200
+ if (cont_level < MAX_CONT_LEVEL ) cont_stack [cont_level ] = '{' ;
201
+ cont_level ++ ;
202
+ state = INPUT_RAW_STRING ;
203
+ }
204
+ line_len += n ;
205
+ utf8byte += n ;
206
+ break ;
207
+ }
208
+ }
209
+
210
+ else if (state == INPUT_SINGLE_LINE_STRING )
211
+ {
212
+ if (* utf8byte == '^' && utf8byte [1 ]) {
169
213
line_len ++ ;
170
214
utf8byte ++ ;
171
215
}
172
- break ;
173
- case '"' :
174
- if (long_str_level == 0 ) inside_short_str = !inside_short_str ;
175
- break ;
176
- case '[' :
177
- case '(' :
178
- if (!inside_short_str && long_str_level == 0 ) {
179
- if (cont_level < MAX_CONT_LEVEL ) cont_stack [cont_level ] = * utf8byte ;
180
- cont_level ++ ;
216
+ else if (* utf8byte == '"' ) {
217
+ state = INPUT_NO_STRING ;
181
218
}
182
- break ;
183
- case ']' :
184
- case ')' :
185
- if (!inside_short_str && long_str_level == 0 ) {
186
- cont_level -- ;
219
+ }
220
+
221
+ else if (state == INPUT_MULTI_LINE_STRING )
222
+ {
223
+ if (* utf8byte == '^' && utf8byte [1 ]) {
224
+ line_len ++ ;
225
+ utf8byte ++ ;
187
226
}
188
- break ;
189
- case '{' :
190
- if (!inside_short_str ) {
227
+ else if (* utf8byte == '{' ) {
191
228
if (cont_level < MAX_CONT_LEVEL ) cont_stack [cont_level ] = * utf8byte ;
192
229
cont_level ++ ;
193
230
long_str_level ++ ;
194
231
}
195
- break ;
196
- case '}' :
197
- if (!inside_short_str ) {
232
+ else if (* utf8byte == '}' ) {
198
233
cont_level -- ;
199
- if (long_str_level > 0 ) long_str_level -- ;
234
+ long_str_level -- ;
235
+ if (long_str_level == 0 ) state = INPUT_NO_STRING ;
236
+ }
237
+ }
238
+
239
+ else if (state == INPUT_RAW_STRING )
240
+ {
241
+ if (* utf8byte == '}' && utf8byte [1 ] == '%' ) {
242
+ n = 1 ;
243
+ while (utf8byte [n ] == '%' ) n ++ ;
244
+ if (raw_str_level < n ) {
245
+ raw_str_level = 0 ;
246
+ line_len += n ;
247
+ utf8byte += n ;
248
+ cont_level -- ;
249
+ state = INPUT_NO_STRING ;
250
+ }
200
251
}
201
- break ;
202
252
}
203
253
}
204
- inside_short_str = FALSE ;
254
+ if ( state == INPUT_SINGLE_LINE_STRING ) state = INPUT_NO_STRING ;
205
255
206
256
if (input_len + line_len > input_max ) {
207
257
// limit maximum input size to 2GB (it should be more than enough)
@@ -230,6 +280,7 @@ void Host_Repl(void) {
230
280
231
281
input_len = 0 ;
232
282
cont_level = 0 ;
283
+ raw_str_level = 0 ;
233
284
234
285
RESET_COLOR ;
235
286
0 commit comments