comparison src/lex.l @ 1091:54abf1b3a8e9

[project @ 1995-02-02 00:30:14 by jwe]
author jwe
date Thu, 02 Feb 1995 00:30:14 +0000
parents 0491f3433f66
children f6cca79f2721
comparison
equal deleted inserted replaced
1090:d5b0d11e3200 1091:54abf1b3a8e9
119 static char *strip_trailing_whitespace (char *s); 119 static char *strip_trailing_whitespace (char *s);
120 static void handle_number (char *yytext); 120 static void handle_number (char *yytext);
121 static int handle_string (char delim, int text_style = 0); 121 static int handle_string (char delim, int text_style = 0);
122 static int handle_close_brace (int spc_gobbled); 122 static int handle_close_brace (int spc_gobbled);
123 static int handle_identifier (char *tok, int spc_gobbled); 123 static int handle_identifier (char *tok, int spc_gobbled);
124 static int have_continuation (void); 124 static int have_continuation (int trailing_comments_ok = 1);
125 static int have_ellipsis_continuation (void); 125 static int have_ellipsis_continuation (int trailing_comments_ok = 1);
126 static int eat_whitespace (void); 126 static int eat_whitespace (void);
127 static int eat_continuation (void); 127 static int eat_continuation (void);
128 128
129 %} 129 %}
130 130
1458 // Once a comment character is found, discard all input until newline. 1458 // Once a comment character is found, discard all input until newline.
1459 // If non-whitespace characters are found before comment 1459 // If non-whitespace characters are found before comment
1460 // characters, return 0. Otherwise, return 1. 1460 // characters, return 0. Otherwise, return 1.
1461 1461
1462 static int 1462 static int
1463 have_continuation (void) 1463 have_continuation (int trailing_comments_ok)
1464 { 1464 {
1465 ostrstream buf; 1465 ostrstream buf;
1466 1466
1467 int in_comment = 0; 1467 int in_comment = 0;
1468 char c; 1468 char c;
1476 case '\t': 1476 case '\t':
1477 break; 1477 break;
1478 1478
1479 case '%': 1479 case '%':
1480 case '#': 1480 case '#':
1481 in_comment = 1; 1481 if (trailing_comments_ok)
1482 in_comment = 1;
1483 else
1484 goto cleanup;
1482 break; 1485 break;
1483 1486
1484 case '\n': 1487 case '\n':
1485 current_input_column = 0; 1488 current_input_column = 0;
1486 promptflag--; 1489 promptflag--;
1487 return 1; 1490 return 1;
1488 1491
1489 default: 1492 default:
1490 if (in_comment) 1493 if (! in_comment)
1491 break; 1494 goto cleanup;
1492 else 1495 break;
1493 {
1494 buf << ends;
1495 char *s = buf.str ();
1496 if (s)
1497 {
1498 int len = strlen (s);
1499 while (len--)
1500 yyunput (s[len], yytext);
1501 }
1502 delete [] s;
1503 return 0;
1504 }
1505 } 1496 }
1506 } 1497 }
1507 1498
1508 yyunput (c, yytext); 1499 yyunput (c, yytext);
1509 1500 return 0;
1501
1502 cleanup:
1503 buf << ends;
1504 char *s = buf.str ();
1505 if (s)
1506 {
1507 int len = strlen (s);
1508 while (len--)
1509 yyunput (s[len], yytext);
1510 }
1511 delete [] s;
1510 return 0; 1512 return 0;
1511 } 1513 }
1512 1514
1513 // We have seen a `.' and need to see if it is the start of a 1515 // We have seen a `.' and need to see if it is the start of a
1514 // continuation. If so, this eats it, up to and including the new 1516 // continuation. If so, this eats it, up to and including the new
1515 // line character. 1517 // line character.
1516 1518
1517 static int 1519 static int
1518 have_ellipsis_continuation (void) 1520 have_ellipsis_continuation (int trailing_comments_ok)
1519 { 1521 {
1520 char c1 = yyinput (); 1522 char c1 = yyinput ();
1521 if (c1 == '.') 1523 if (c1 == '.')
1522 { 1524 {
1523 char c2 = yyinput (); 1525 char c2 = yyinput ();
1524 if (c2 == '.' && have_continuation ()) 1526 if (c2 == '.' && have_continuation (trailing_comments_ok))
1525 return 1; 1527 return 1;
1526 else 1528 else
1527 { 1529 {
1528 yyunput (c2, yytext); 1530 yyunput (c2, yytext);
1529 yyunput (c1, yytext); 1531 yyunput (c1, yytext);
1573 buf << (char) c; 1575 buf << (char) c;
1574 escape_pending = 0; 1576 escape_pending = 0;
1575 } 1577 }
1576 else 1578 else
1577 { 1579 {
1578 if (have_continuation ()) 1580 if (have_continuation (0))
1579 escape_pending = 0; 1581 escape_pending = 0;
1580 else 1582 else
1581 { 1583 {
1582 buf << (char) c; 1584 buf << (char) c;
1583 escape_pending = 1; 1585 escape_pending = 1;
1585 } 1587 }
1586 continue; 1588 continue;
1587 } 1589 }
1588 else if (c == '.') 1590 else if (c == '.')
1589 { 1591 {
1590 if (! have_ellipsis_continuation ()) 1592 if (! have_ellipsis_continuation (0))
1591 buf << (char) c; 1593 buf << (char) c;
1592 } 1594 }
1593 else if (c == '\n') 1595 else if (c == '\n')
1594 { 1596 {
1595 error ("unterminated string constant"); 1597 error ("unterminated string constant");