comparison src/lex.l @ 3105:f936c7f5074f

[project @ 1997-11-19 04:36:17 by jwe]
author jwe
date Wed, 19 Nov 1997 04:37:56 +0000
parents 98d862e12945
children 61bb314b2c3d
comparison
equal deleted inserted replaced
3104:b9aea66ecbae 3105:f936c7f5074f
156 // [eye (2)] 156 // [eye (2)]
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
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;
165 161
166 // Forward declarations for functions defined at the bottom of this 162 // Forward declarations for functions defined at the bottom of this
167 // file. 163 // file.
168 164
169 static void fixup_column_count (char *s); 165 static void fixup_column_count (char *s);
1294 case '\\': 1290 case '\\':
1295 if (in_comment) 1291 if (in_comment)
1296 break; 1292 break;
1297 else 1293 else
1298 { 1294 {
1299 if (Vbackslash_escapes && have_continuation ()) 1295 if (have_continuation ())
1300 break; 1296 break;
1301 else 1297 else
1302 goto done; 1298 goto done;
1303 } 1299 }
1304 1300
1449 eat_continuation (void) 1445 eat_continuation (void)
1450 { 1446 {
1451 int retval = ATE_NOTHING; 1447 int retval = ATE_NOTHING;
1452 int c = yyinput (); 1448 int c = yyinput ();
1453 if ((c == '.' && have_ellipsis_continuation ()) 1449 if ((c == '.' && have_ellipsis_continuation ())
1454 || (c == '\\' && Vbackslash_escapes && have_continuation ())) 1450 || (c == '\\' && have_continuation ()))
1455 retval = eat_whitespace (); 1451 retval = eat_whitespace ();
1456 else 1452 else
1457 yyunput (c, yytext); 1453 yyunput (c, yytext);
1458 1454
1459 return retval; 1455 return retval;
1469 1465
1470 while ((c = yyinput ()) != EOF) 1466 while ((c = yyinput ()) != EOF)
1471 { 1467 {
1472 current_input_column++; 1468 current_input_column++;
1473 1469
1474 if (c == '\\' && Vbackslash_escapes) 1470 if (c == '\\')
1475 { 1471 {
1476 if (escape_pending) 1472 if (escape_pending)
1477 { 1473 {
1478 buf << (char) c; 1474 buf << (char) c;
1479 escape_pending = 0; 1475 escape_pending = 0;
1511 buf << (char) c; 1507 buf << (char) c;
1512 else 1508 else
1513 { 1509 {
1514 yyunput (c, yytext); 1510 yyunput (c, yytext);
1515 buf << ends; 1511 buf << ends;
1516 char *tmp = buf.str (); 1512 char *t = buf.str ();
1517 string tok = Vbackslash_escapes 1513 string s = do_string_escapes (t);
1518 ? do_string_escapes (tmp) : string (tmp); 1514 delete [] t;
1519 delete [] tmp;
1520 1515
1521 if (text_style && lexer_flags.doing_set) 1516 if (text_style && lexer_flags.doing_set)
1522 { 1517 {
1523 if (! tok.empty ()) 1518 if (! s.empty ())
1524 tok = string (delim, 1) + tok + string (delim, 1); 1519 s = string (delim, 1) + s + string (delim, 1);
1525 } 1520 }
1526 else 1521 else
1527 { 1522 {
1528 lexer_flags.quote_is_transpose = true; 1523 lexer_flags.quote_is_transpose = true;
1529 lexer_flags.cant_be_identifier = true; 1524 lexer_flags.cant_be_identifier = true;
1530 lexer_flags.convert_spaces_to_comma = true; 1525 lexer_flags.convert_spaces_to_comma = true;
1531 } 1526 }
1532 1527
1533 yylval.tok_val = new token (tok); 1528 yylval.tok_val = new token (s);
1534 token_stack.push (yylval.tok_val); 1529 token_stack.push (yylval.tok_val);
1535 return TEXT; 1530 return TEXT;
1536 } 1531 }
1537 } 1532 }
1538 } 1533 }
1875 // Quote marks strings intially. 1870 // Quote marks strings intially.
1876 quote_is_transpose = false; 1871 quote_is_transpose = false;
1877 } 1872 }
1878 1873
1879 int 1874 int
1880 backslash_escapes (void)
1881 {
1882 Vbackslash_escapes = check_preference ("backslash_escapes");
1883
1884 return 0;
1885 }
1886
1887 int
1888 whitespace_in_literal_matrix (void) 1875 whitespace_in_literal_matrix (void)
1889 { 1876 {
1890 int pref = 0; 1877 int pref = 0;
1891 1878
1892 string val = builtin_string_variable ("whitespace_in_literal_matrix"); 1879 string val = builtin_string_variable ("whitespace_in_literal_matrix");
1905 } 1892 }
1906 1893
1907 void 1894 void
1908 symbols_of_lex (void) 1895 symbols_of_lex (void)
1909 { 1896 {
1910 DEFVAR (backslash_escapes, 1.0, 0, backslash_escapes,
1911 "if nonzero, Octave recognizes backslashes in strings as escapes that\n\
1912 introduce special characters like newline (\\n), tab (\\t), etc.");
1913
1914 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, 1897 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix,
1915 "control auto-insertion of commas and semicolons in literal matrices"); 1898 "control auto-insertion of commas and semicolons in literal matrices");
1916 } 1899 }
1917 1900
1918 /* 1901 /*