Mercurial > octave
comparison src/lex.l @ 1088:0491f3433f66
[project @ 1995-02-01 21:43:25 by jwe]
author | jwe |
---|---|
date | Wed, 01 Feb 1995 21:43:25 +0000 |
parents | d1a1608f1028 |
children | 54abf1b3a8e9 |
comparison
equal
deleted
inserted
replaced
1087:85731fac3a15 | 1088:0491f3433f66 |
---|---|
86 // `title', and `with' keywords. | 86 // `title', and `with' keywords. |
87 static int cant_be_identifier = 0; | 87 static int cant_be_identifier = 0; |
88 | 88 |
89 #define BRACE 1 | 89 #define BRACE 1 |
90 #define PAREN 2 | 90 #define PAREN 2 |
91 | |
92 // Did eat_whitespace() eat a space or tab, or a newline, or both? | |
93 #define ATE_SPACE_OR_TAB 1 | |
94 #define ATE_NEWLINE 2 | |
91 | 95 |
92 // Is the closest nesting level a square brace or a paren? | 96 // Is the closest nesting level a square brace or a paren? |
93 // | 97 // |
94 // BRACE -> spaces are important (they can turn into commas) | 98 // BRACE -> spaces are important (they can turn into commas) |
95 // new lines are important (they can turn into semicolons) | 99 // new lines are important (they can turn into semicolons) |
209 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 213 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
210 return handle_close_brace (spc_gobbled); | 214 return handle_close_brace (spc_gobbled); |
211 } | 215 } |
212 | 216 |
213 %{ | 217 %{ |
214 // Commas are element separators in matrix constants. | 218 // Commas are element separators in matrix constants. If we don't |
219 // check for continuations here we can end up inserting too many | |
220 // commas. | |
215 %} | 221 %} |
216 | 222 |
217 <MATRIX>{S}*\,{S}* { | 223 <MATRIX>{S}*\,{S}* { |
218 TOK_RETURN (','); | 224 current_input_column += yyleng; |
225 int tmp = eat_continuation (); | |
226 quote_is_transpose = 0; | |
227 cant_be_identifier = 0; | |
228 convert_spaces_to_comma = 1; | |
229 if (user_pref.whitespace_in_literal_matrix != 2 | |
230 && (tmp & ATE_NEWLINE) == ATE_NEWLINE) | |
231 unput (';'); | |
232 return (','); | |
219 } | 233 } |
220 | 234 |
221 %{ | 235 %{ |
222 // In some cases, spaces in matrix constants can turn into commas. | 236 // In some cases, spaces in matrix constants can turn into commas. |
223 // If commas are required, spaces are not important in matrix | 237 // If commas are required, spaces are not important in matrix |
224 // constants so we just eat them. | 238 // constants so we just eat them. If we don't check for continuations |
239 // here we can end up inserting too many commas. | |
225 %} | 240 %} |
226 | 241 |
227 <MATRIX>{S}+ { | 242 <MATRIX>{S}+ { |
243 current_input_column += yyleng; | |
228 if (user_pref.whitespace_in_literal_matrix != 2) | 244 if (user_pref.whitespace_in_literal_matrix != 2) |
229 { | 245 { |
246 int tmp = eat_continuation (); | |
230 int bin_op = next_token_is_bin_op (1, yytext); | 247 int bin_op = next_token_is_bin_op (1, yytext); |
231 int postfix_un_op = next_token_is_postfix_unary_op (1, yytext); | 248 int postfix_un_op = next_token_is_postfix_unary_op (1, yytext); |
232 | 249 |
233 if (! (postfix_un_op || bin_op || nesting_level.empty ()) | 250 if (! (postfix_un_op || bin_op || nesting_level.empty ()) |
234 && nesting_level.top () == BRACE | 251 && nesting_level.top () == BRACE |
235 && convert_spaces_to_comma) | 252 && convert_spaces_to_comma) |
236 TOK_RETURN (','); | 253 { |
254 quote_is_transpose = 0; | |
255 cant_be_identifier = 0; | |
256 convert_spaces_to_comma = 1; | |
257 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) | |
258 unput (';'); | |
259 return (','); | |
260 } | |
237 } | 261 } |
238 } | 262 } |
239 | 263 |
240 %{ | 264 %{ |
241 // Semicolons are handled as row seprators in matrix constants. | 265 // Semicolons are handled as row seprators in matrix constants. If we |
266 // don't eat whitespace here we can end up inserting too many | |
267 // semicolons. | |
242 %} | 268 %} |
243 | 269 |
244 <MATRIX>{SNLCMT}*;{SNLCMT}* { | 270 <MATRIX>{SNLCMT}*;{SNLCMT}* { |
245 fixup_column_count (yytext); | 271 fixup_column_count (yytext); |
246 eat_whitespace (); | 272 eat_whitespace (); |
249 convert_spaces_to_comma = 1; | 275 convert_spaces_to_comma = 1; |
250 return ';'; | 276 return ';'; |
251 } | 277 } |
252 | 278 |
253 %{ | 279 %{ |
254 // In some cases, new lines can also become row separators. | 280 // In some cases, new lines can also become row separators. If we |
281 // don't eat whitespace here we can end up inserting too many | |
282 // semicolons. | |
255 %} | 283 %} |
256 | 284 |
257 <MATRIX>{SNLCMT}*\n{SNLCMT}* { | 285 <MATRIX>{SNLCMT}*\n{SNLCMT}* { |
258 fixup_column_count (yytext); | 286 fixup_column_count (yytext); |
287 eat_whitespace (); | |
259 if (user_pref.whitespace_in_literal_matrix != 2) | 288 if (user_pref.whitespace_in_literal_matrix != 2) |
260 { | 289 { |
261 quote_is_transpose = 0; | 290 quote_is_transpose = 0; |
262 cant_be_identifier = 0; | 291 cant_be_identifier = 0; |
263 convert_spaces_to_comma = 1; | 292 convert_spaces_to_comma = 1; |
1322 | 1351 |
1323 return retval; | 1352 return retval; |
1324 } | 1353 } |
1325 | 1354 |
1326 // Discard whitespace, including comments and continuations. | 1355 // Discard whitespace, including comments and continuations. |
1327 // Return 1 if whitespace appeared in the input, 0 otherwise. | 1356 // |
1357 // Return value is logical OR of the following values: | |
1358 // | |
1359 // ATE_SPACE_OR_TAB : space or tab in input | |
1360 // ATE_NEWLINE : bare new line in input | |
1328 | 1361 |
1329 static int | 1362 static int |
1330 eat_whitespace (void) | 1363 eat_whitespace (void) |
1331 { | 1364 { |
1332 int retval = 0; | 1365 int retval = 0; |
1338 | 1371 |
1339 switch (c) | 1372 switch (c) |
1340 { | 1373 { |
1341 case ' ': | 1374 case ' ': |
1342 case '\t': | 1375 case '\t': |
1343 retval = 1; | 1376 retval |= ATE_SPACE_OR_TAB; |
1344 break; | 1377 break; |
1345 | 1378 |
1346 case '\n': | 1379 case '\n': |
1347 retval = 1; | 1380 retval |= ATE_NEWLINE; |
1348 in_comment = 0; | 1381 in_comment = 0; |
1349 current_input_column = 0; | 1382 current_input_column = 0; |
1350 break; | 1383 break; |
1351 | 1384 |
1352 case '#': | 1385 case '#': |
1502 return 0; | 1535 return 0; |
1503 } | 1536 } |
1504 | 1537 |
1505 // See if we have a continuation line. If so, eat it and the leading | 1538 // See if we have a continuation line. If so, eat it and the leading |
1506 // whitespace on the next line. | 1539 // whitespace on the next line. |
1507 // Return 1 if whitespace appeared in the input, 0 otherwise. | 1540 // |
1541 // Return value is the same as described for eat_whitespace(). | |
1508 | 1542 |
1509 static int | 1543 static int |
1510 eat_continuation (void) | 1544 eat_continuation (void) |
1511 { | 1545 { |
1512 int retval = 0; | 1546 int retval = 0; |