Mercurial > hg > octave-jordi
comparison src/lex.l @ 3096:ff8b4d6371b3
[project @ 1997-11-14 07:59:14 by jwe]
author | jwe |
---|---|
date | Fri, 14 Nov 1997 07:59:15 +0000 |
parents | eb827eb9b8ff |
children | 98d862e12945 |
comparison
equal
deleted
inserted
replaced
3095:528f4270e904 | 3096:ff8b4d6371b3 |
---|---|
157 // | 157 // |
158 // will result in a call to `eye' with the argument `2'. | 158 // will result in a call to `eye' with the argument `2'. |
159 | 159 |
160 static int Vwhitespace_in_literal_matrix; | 160 static int Vwhitespace_in_literal_matrix; |
161 | 161 |
162 // Should Octave treat backslashes in strings as escapes that | |
163 // introduce special characters like newline (\n), tab (\t), etc.? | |
164 static bool Vbackslash_escapes; | |
162 | 165 |
163 // Forward declarations for functions defined at the bottom of this | 166 // Forward declarations for functions defined at the bottom of this |
164 // file. | 167 // file. |
165 | 168 |
166 static void do_string_escapes (char *s); | 169 static void do_string_escapes (char *s); |
177 static string strip_trailing_whitespace (char *s); | 180 static string strip_trailing_whitespace (char *s); |
178 static void handle_number (char *yytext); | 181 static void handle_number (char *yytext); |
179 static int handle_string (char delim, int text_style = 0); | 182 static int handle_string (char delim, int text_style = 0); |
180 static int handle_close_brace (int spc_gobbled); | 183 static int handle_close_brace (int spc_gobbled); |
181 static int handle_identifier (const string& tok, int spc_gobbled); | 184 static int handle_identifier (const string& tok, int spc_gobbled); |
182 static bool have_continuation (int trailing_comments_ok = 1); | 185 static bool have_continuation (bool trailing_comments_ok = true); |
183 static bool have_ellipsis_continuation (int trailing_comments_ok = 1); | 186 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); |
184 static yum_yum eat_whitespace (void); | 187 static yum_yum eat_whitespace (void); |
185 static yum_yum eat_continuation (void); | 188 static yum_yum eat_continuation (void); |
186 | 189 |
187 %} | 190 %} |
188 | 191 |
719 // Replace backslash escapes in a string with the real values. | 722 // Replace backslash escapes in a string with the real values. |
720 | 723 |
721 static void | 724 static void |
722 do_string_escapes (char *s) | 725 do_string_escapes (char *s) |
723 { | 726 { |
727 if (! Vbackslash_escapes) | |
728 return; | |
729 | |
724 char *p1 = s; | 730 char *p1 = s; |
725 char *p2 = s; | 731 char *p2 = s; |
726 | 732 |
727 while (*p2 != '\0') | 733 while (*p2 != '\0') |
728 { | 734 { |
1365 case '\\': | 1371 case '\\': |
1366 if (in_comment) | 1372 if (in_comment) |
1367 break; | 1373 break; |
1368 else | 1374 else |
1369 { | 1375 { |
1370 if (have_continuation ()) | 1376 if (Vbackslash_escapes && have_continuation ()) |
1371 break; | 1377 break; |
1372 else | 1378 else |
1373 goto done; | 1379 goto done; |
1374 } | 1380 } |
1375 | 1381 |
1431 // Once a comment character is found, discard all input until newline. | 1437 // Once a comment character is found, discard all input until newline. |
1432 // If non-whitespace characters are found before comment | 1438 // If non-whitespace characters are found before comment |
1433 // characters, return 0. Otherwise, return 1. | 1439 // characters, return 0. Otherwise, return 1. |
1434 | 1440 |
1435 static bool | 1441 static bool |
1436 have_continuation (int trailing_comments_ok) | 1442 have_continuation (bool trailing_comments_ok) |
1437 { | 1443 { |
1438 ostrstream buf; | 1444 ostrstream buf; |
1439 | 1445 |
1440 bool in_comment = false; | 1446 bool in_comment = false; |
1441 char c; | 1447 char c; |
1470 } | 1476 } |
1471 | 1477 |
1472 yyunput (c, yytext); | 1478 yyunput (c, yytext); |
1473 return false; | 1479 return false; |
1474 | 1480 |
1475 cleanup: | 1481 cleanup: |
1476 buf << ends; | 1482 buf << ends; |
1477 char *s = buf.str (); | 1483 char *s = buf.str (); |
1478 if (s) | 1484 if (s) |
1479 { | 1485 { |
1480 int len = strlen (s); | 1486 int len = strlen (s); |
1481 while (len--) | 1487 while (len--) |
1482 yyunput (s[len], yytext); | 1488 yyunput (s[len], yytext); |
1483 } | 1489 } |
1484 delete [] s; | 1490 delete [] s; |
1491 | |
1485 return false; | 1492 return false; |
1486 } | 1493 } |
1487 | 1494 |
1488 // We have seen a `.' and need to see if it is the start of a | 1495 // We have seen a `.' and need to see if it is the start of a |
1489 // continuation. If so, this eats it, up to and including the new | 1496 // continuation. If so, this eats it, up to and including the new |
1490 // line character. | 1497 // line character. |
1491 | 1498 |
1492 static bool | 1499 static bool |
1493 have_ellipsis_continuation (int trailing_comments_ok) | 1500 have_ellipsis_continuation (bool trailing_comments_ok) |
1494 { | 1501 { |
1495 char c1 = yyinput (); | 1502 char c1 = yyinput (); |
1496 if (c1 == '.') | 1503 if (c1 == '.') |
1497 { | 1504 { |
1498 char c2 = yyinput (); | 1505 char c2 = yyinput (); |
1519 eat_continuation (void) | 1526 eat_continuation (void) |
1520 { | 1527 { |
1521 int retval = ATE_NOTHING; | 1528 int retval = ATE_NOTHING; |
1522 int c = yyinput (); | 1529 int c = yyinput (); |
1523 if ((c == '.' && have_ellipsis_continuation ()) | 1530 if ((c == '.' && have_ellipsis_continuation ()) |
1524 || (c == '\\' && have_continuation ())) | 1531 || (c == '\\' && Vbackslash_escapes && have_continuation ())) |
1525 retval = eat_whitespace (); | 1532 retval = eat_whitespace (); |
1526 else | 1533 else |
1527 yyunput (c, yytext); | 1534 yyunput (c, yytext); |
1528 | 1535 |
1529 return retval; | 1536 return retval; |
1539 | 1546 |
1540 while ((c = yyinput ()) != EOF) | 1547 while ((c = yyinput ()) != EOF) |
1541 { | 1548 { |
1542 current_input_column++; | 1549 current_input_column++; |
1543 | 1550 |
1544 if (c == '\\') | 1551 if (c == '\\' && Vbackslash_escapes) |
1545 { | 1552 { |
1546 if (escape_pending) | 1553 if (escape_pending) |
1547 { | 1554 { |
1548 buf << (char) c; | 1555 buf << (char) c; |
1549 escape_pending = 0; | 1556 escape_pending = 0; |
1550 } | 1557 } |
1551 else | 1558 else |
1552 { | 1559 { |
1553 if (have_continuation (0)) | 1560 if (have_continuation (false)) |
1554 escape_pending = 0; | 1561 escape_pending = 0; |
1555 else | 1562 else |
1556 { | 1563 { |
1557 buf << (char) c; | 1564 buf << (char) c; |
1558 escape_pending = 1; | 1565 escape_pending = 1; |
1560 } | 1567 } |
1561 continue; | 1568 continue; |
1562 } | 1569 } |
1563 else if (c == '.') | 1570 else if (c == '.') |
1564 { | 1571 { |
1565 if (! have_ellipsis_continuation (0)) | 1572 if (! have_ellipsis_continuation (false)) |
1566 buf << (char) c; | 1573 buf << (char) c; |
1567 } | 1574 } |
1568 else if (c == '\n') | 1575 else if (c == '\n') |
1569 { | 1576 { |
1570 error ("unterminated string constant"); | 1577 error ("unterminated string constant"); |
1953 // Quote marks strings intially. | 1960 // Quote marks strings intially. |
1954 quote_is_transpose = false; | 1961 quote_is_transpose = false; |
1955 } | 1962 } |
1956 | 1963 |
1957 int | 1964 int |
1965 backslash_escapes (void) | |
1966 { | |
1967 Vbackslash_escapes = check_preference ("backslash_escapes"); | |
1968 | |
1969 return 0; | |
1970 } | |
1971 | |
1972 int | |
1958 whitespace_in_literal_matrix (void) | 1973 whitespace_in_literal_matrix (void) |
1959 { | 1974 { |
1960 int pref = 0; | 1975 int pref = 0; |
1961 | 1976 |
1962 string val = builtin_string_variable ("whitespace_in_literal_matrix"); | 1977 string val = builtin_string_variable ("whitespace_in_literal_matrix"); |
1975 } | 1990 } |
1976 | 1991 |
1977 void | 1992 void |
1978 symbols_of_lex (void) | 1993 symbols_of_lex (void) |
1979 { | 1994 { |
1995 DEFVAR (backslash_escapes, 1.0, 0, backslash_escapes, | |
1996 "if nonzero, Octave recognizes backslashes in strings as escapes that\n\ | |
1997 introduce special characters like newline (\\n), tab (\\t), etc."); | |
1998 | |
1980 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, | 1999 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, |
1981 "control auto-insertion of commas and semicolons in literal matrices"); | 2000 "control auto-insertion of commas and semicolons in literal matrices"); |
1982 } | 2001 } |
1983 | 2002 |
1984 /* | 2003 /* |