Mercurial > hg > octave-lyh
comparison libinterp/parse-tree/lex.ll @ 16158:7eb614760ddb
rename lexical_feedback to octave_lexer
* lex.h (octave_lexer): Rename from lexical_feedback.
* lex.h, lex.ll, parse.h, oct-parse.yy: Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 28 Feb 2013 11:24:38 -0500 |
parents | aa5e1e8dce66 |
children | c5bfdc4c0963 |
comparison
equal
deleted
inserted
replaced
16157:335041cc657a | 16158:7eb614760ddb |
---|---|
107 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ | 107 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ |
108 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) | 108 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) |
109 #error lex.l requires flex version 2.5.4 or later | 109 #error lex.l requires flex version 2.5.4 or later |
110 #endif | 110 #endif |
111 | 111 |
112 #define YY_EXTRA_TYPE lexical_feedback * | 112 #define YY_EXTRA_TYPE octave_lexer * |
113 #define curr_lexer yyextra | 113 #define curr_lexer yyextra |
114 | 114 |
115 // Arrange to get input via readline. | 115 // Arrange to get input via readline. |
116 | 116 |
117 #ifdef YY_INPUT | 117 #ifdef YY_INPUT |
351 | 351 |
352 curr_lexer->looking_for_object_index = true; | 352 curr_lexer->looking_for_object_index = true; |
353 curr_lexer->at_beginning_of_statement = false; | 353 curr_lexer->at_beginning_of_statement = false; |
354 | 354 |
355 int c = yytext[yyleng-1]; | 355 int c = yytext[yyleng-1]; |
356 bool cont_is_spc = (curr_lexer->eat_continuation () != lexical_feedback::NO_WHITESPACE); | 356 bool cont_is_spc = (curr_lexer->eat_continuation () != octave_lexer::NO_WHITESPACE); |
357 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 357 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
358 int tok_to_return = curr_lexer->handle_close_bracket (spc_gobbled, ']'); | 358 int tok_to_return = curr_lexer->handle_close_bracket (spc_gobbled, ']'); |
359 | 359 |
360 if (spc_gobbled) | 360 if (spc_gobbled) |
361 curr_lexer->xunput (' '); | 361 curr_lexer->xunput (' '); |
377 | 377 |
378 curr_lexer->looking_for_object_index = true; | 378 curr_lexer->looking_for_object_index = true; |
379 curr_lexer->at_beginning_of_statement = false; | 379 curr_lexer->at_beginning_of_statement = false; |
380 | 380 |
381 int c = yytext[yyleng-1]; | 381 int c = yytext[yyleng-1]; |
382 bool cont_is_spc = (curr_lexer->eat_continuation () != lexical_feedback::NO_WHITESPACE); | 382 bool cont_is_spc = (curr_lexer->eat_continuation () != octave_lexer::NO_WHITESPACE); |
383 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 383 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
384 int tok_to_return = curr_lexer->handle_close_bracket (spc_gobbled, '}'); | 384 int tok_to_return = curr_lexer->handle_close_bracket (spc_gobbled, '}'); |
385 | 385 |
386 if (spc_gobbled) | 386 if (spc_gobbled) |
387 curr_lexer->xunput (' '); | 387 curr_lexer->xunput (' '); |
407 curr_lexer->looking_for_object_index = false; | 407 curr_lexer->looking_for_object_index = false; |
408 curr_lexer->at_beginning_of_statement = false; | 408 curr_lexer->at_beginning_of_statement = false; |
409 | 409 |
410 if (! curr_lexer->looking_at_object_index.front ()) | 410 if (! curr_lexer->looking_at_object_index.front ()) |
411 { | 411 { |
412 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) | 412 if ((tmp & octave_lexer::NEWLINE) == octave_lexer::NEWLINE) |
413 { | 413 { |
414 curr_lexer->maybe_warn_separator_insert (';'); | 414 curr_lexer->maybe_warn_separator_insert (';'); |
415 | 415 |
416 curr_lexer->xunput (';'); | 416 curr_lexer->xunput (';'); |
417 } | 417 } |
444 | 444 |
445 if (! (postfix_un_op || bin_op || sep_op) | 445 if (! (postfix_un_op || bin_op || sep_op) |
446 && curr_lexer->nesting_level.is_bracket_or_brace () | 446 && curr_lexer->nesting_level.is_bracket_or_brace () |
447 && curr_lexer->convert_spaces_to_comma) | 447 && curr_lexer->convert_spaces_to_comma) |
448 { | 448 { |
449 if ((tmp & lexical_feedback::NEWLINE) == lexical_feedback::NEWLINE) | 449 if ((tmp & octave_lexer::NEWLINE) == octave_lexer::NEWLINE) |
450 { | 450 { |
451 curr_lexer->maybe_warn_separator_insert (';'); | 451 curr_lexer->maybe_warn_separator_insert (';'); |
452 | 452 |
453 curr_lexer->xunput (';'); | 453 curr_lexer->xunput (';'); |
454 } | 454 } |
1282 | 1282 |
1283 class | 1283 class |
1284 flex_stream_reader : public stream_reader | 1284 flex_stream_reader : public stream_reader |
1285 { | 1285 { |
1286 public: | 1286 public: |
1287 flex_stream_reader (lexical_feedback *l, char *buf_arg) | 1287 flex_stream_reader (octave_lexer *l, char *buf_arg) |
1288 : stream_reader (), lexer (l), buf (buf_arg) | 1288 : stream_reader (), lexer (l), buf (buf_arg) |
1289 { } | 1289 { } |
1290 | 1290 |
1291 int getc (void) { return lexer->text_yyinput (); } | 1291 int getc (void) { return lexer->text_yyinput (); } |
1292 int ungetc (int c) { lexer->xunput (c, buf); return 0; } | 1292 int ungetc (int c) { lexer->xunput (c, buf); return 0; } |
1297 | 1297 |
1298 flex_stream_reader (const flex_stream_reader&); | 1298 flex_stream_reader (const flex_stream_reader&); |
1299 | 1299 |
1300 flex_stream_reader& operator = (const flex_stream_reader&); | 1300 flex_stream_reader& operator = (const flex_stream_reader&); |
1301 | 1301 |
1302 lexical_feedback *lexer; | 1302 octave_lexer *lexer; |
1303 | 1303 |
1304 char *buf; | 1304 char *buf; |
1305 }; | 1305 }; |
1306 | 1306 |
1307 lexical_feedback::~lexical_feedback (void) | 1307 octave_lexer::~octave_lexer (void) |
1308 { | 1308 { |
1309 // Clear out the stack of token info used to track line and | 1309 // Clear out the stack of token info used to track line and |
1310 // column numbers. | 1310 // column numbers. |
1311 | 1311 |
1312 while (! token_stack.empty ()) | 1312 while (! token_stack.empty ()) |
1317 | 1317 |
1318 yylex_destroy (scanner); | 1318 yylex_destroy (scanner); |
1319 } | 1319 } |
1320 | 1320 |
1321 void | 1321 void |
1322 lexical_feedback::init (void) | 1322 octave_lexer::init (void) |
1323 { | 1323 { |
1324 // The closest paren, brace, or bracket nesting is not an object | 1324 // The closest paren, brace, or bracket nesting is not an object |
1325 // index. | 1325 // index. |
1326 looking_at_object_index.push_front (false); | 1326 looking_at_object_index.push_front (false); |
1327 | 1327 |
1328 yylex_init (&scanner); | 1328 yylex_init (&scanner); |
1329 | 1329 |
1330 // Make lexical_feedback object available through yyextra in | 1330 // Make octave_lexer object available through yyextra in |
1331 // flex-generated lexer. | 1331 // flex-generated lexer. |
1332 yyset_extra (this, scanner); | 1332 yyset_extra (this, scanner); |
1333 } | 1333 } |
1334 | 1334 |
1335 // Inside Flex-generated functions, yyg is the scanner cast to its real | 1335 // Inside Flex-generated functions, yyg is the scanner cast to its real |
1336 // type. The BEGIN macro uses yyg and we want to use that in | 1336 // type. The BEGIN macro uses yyg and we want to use that in |
1337 // lexical_feedback member functions. If we could set the start state | 1337 // octave_lexer member functions. If we could set the start state |
1338 // by calling a function instead of using the BEGIN macro, we could | 1338 // by calling a function instead of using the BEGIN macro, we could |
1339 // eliminate the OCTAVE_YYG macro. | 1339 // eliminate the OCTAVE_YYG macro. |
1340 | 1340 |
1341 #define OCTAVE_YYG \ | 1341 #define OCTAVE_YYG \ |
1342 struct yyguts_t *yyg = static_cast<struct yyguts_t*> (scanner) | 1342 struct yyguts_t *yyg = static_cast<struct yyguts_t*> (scanner) |
1343 | 1343 |
1344 void | 1344 void |
1345 lexical_feedback::reset (void) | 1345 octave_lexer::reset (void) |
1346 { | 1346 { |
1347 OCTAVE_YYG; | 1347 OCTAVE_YYG; |
1348 | 1348 |
1349 // Start off on the right foot. | 1349 // Start off on the right foot. |
1350 BEGIN (INITIAL); | 1350 BEGIN (INITIAL); |
1370 while (! help_buf.empty ()) | 1370 while (! help_buf.empty ()) |
1371 help_buf.pop (); | 1371 help_buf.pop (); |
1372 } | 1372 } |
1373 | 1373 |
1374 void | 1374 void |
1375 lexical_feedback::prep_for_script_file (void) | 1375 octave_lexer::prep_for_script_file (void) |
1376 { | 1376 { |
1377 OCTAVE_YYG; | 1377 OCTAVE_YYG; |
1378 | 1378 |
1379 BEGIN (SCRIPT_FILE_BEGIN); | 1379 BEGIN (SCRIPT_FILE_BEGIN); |
1380 } | 1380 } |
1381 | 1381 |
1382 void | 1382 void |
1383 lexical_feedback::prep_for_function_file (void) | 1383 octave_lexer::prep_for_function_file (void) |
1384 { | 1384 { |
1385 OCTAVE_YYG; | 1385 OCTAVE_YYG; |
1386 | 1386 |
1387 BEGIN (FUNCTION_FILE_BEGIN); | 1387 BEGIN (FUNCTION_FILE_BEGIN); |
1388 } | 1388 } |
1389 | 1389 |
1390 int | 1390 int |
1391 lexical_feedback::octave_read (char *buf, unsigned max_size) | 1391 octave_lexer::octave_read (char *buf, unsigned max_size) |
1392 { | 1392 { |
1393 static const char * const eol = "\n"; | 1393 static const char * const eol = "\n"; |
1394 static std::string input_buf; | 1394 static std::string input_buf; |
1395 static const char *pos = 0; | 1395 static const char *pos = 0; |
1396 static size_t chars_left = 0; | 1396 static size_t chars_left = 0; |
1450 | 1450 |
1451 return status; | 1451 return status; |
1452 } | 1452 } |
1453 | 1453 |
1454 char * | 1454 char * |
1455 lexical_feedback::flex_yytext (void) | 1455 octave_lexer::flex_yytext (void) |
1456 { | 1456 { |
1457 return yyget_text (scanner); | 1457 return yyget_text (scanner); |
1458 } | 1458 } |
1459 | 1459 |
1460 int | 1460 int |
1461 lexical_feedback::flex_yyleng (void) | 1461 octave_lexer::flex_yyleng (void) |
1462 { | 1462 { |
1463 return yyget_leng (scanner); | 1463 return yyget_leng (scanner); |
1464 } | 1464 } |
1465 | 1465 |
1466 // GAG. | 1466 // GAG. |
1467 // | 1467 // |
1468 // If we're reading a matrix and the next character is '[', make sure | 1468 // If we're reading a matrix and the next character is '[', make sure |
1469 // that we insert a comma ahead of it. | 1469 // that we insert a comma ahead of it. |
1470 | 1470 |
1471 void | 1471 void |
1472 lexical_feedback::do_comma_insert_check (void) | 1472 octave_lexer::do_comma_insert_check (void) |
1473 { | 1473 { |
1474 bool spc_gobbled = (eat_continuation () != lexical_feedback::NO_WHITESPACE); | 1474 bool spc_gobbled = (eat_continuation () != octave_lexer::NO_WHITESPACE); |
1475 | 1475 |
1476 int c = text_yyinput (); | 1476 int c = text_yyinput (); |
1477 | 1477 |
1478 xunput (c); | 1478 xunput (c); |
1479 | 1479 |
1483 do_comma_insert = (! looking_at_object_index.front () | 1483 do_comma_insert = (! looking_at_object_index.front () |
1484 && bracketflag && c == '['); | 1484 && bracketflag && c == '['); |
1485 } | 1485 } |
1486 | 1486 |
1487 int | 1487 int |
1488 lexical_feedback::text_yyinput (void) | 1488 octave_lexer::text_yyinput (void) |
1489 { | 1489 { |
1490 int c = yyinput (scanner); | 1490 int c = yyinput (scanner); |
1491 | 1491 |
1492 if (lexer_debug_flag) | 1492 if (lexer_debug_flag) |
1493 { | 1493 { |
1521 | 1521 |
1522 return c; | 1522 return c; |
1523 } | 1523 } |
1524 | 1524 |
1525 void | 1525 void |
1526 lexical_feedback::xunput (char c, char *buf) | 1526 octave_lexer::xunput (char c, char *buf) |
1527 { | 1527 { |
1528 if (lexer_debug_flag) | 1528 if (lexer_debug_flag) |
1529 { | 1529 { |
1530 std::cerr << "U: "; | 1530 std::cerr << "U: "; |
1531 display_character (c); | 1531 display_character (c); |
1537 | 1537 |
1538 yyunput (c, buf, scanner); | 1538 yyunput (c, buf, scanner); |
1539 } | 1539 } |
1540 | 1540 |
1541 void | 1541 void |
1542 lexical_feedback::xunput (char c) | 1542 octave_lexer::xunput (char c) |
1543 { | 1543 { |
1544 char *yytxt = flex_yytext (); | 1544 char *yytxt = flex_yytext (); |
1545 | 1545 |
1546 xunput (c, yytxt); | 1546 xunput (c, yytxt); |
1547 } | 1547 } |
1548 | 1548 |
1549 // If we read some newlines, we need figure out what column we're | 1549 // If we read some newlines, we need figure out what column we're |
1550 // really looking at. | 1550 // really looking at. |
1551 | 1551 |
1552 void | 1552 void |
1553 lexical_feedback::fixup_column_count (char *s) | 1553 octave_lexer::fixup_column_count (char *s) |
1554 { | 1554 { |
1555 char c; | 1555 char c; |
1556 while ((c = *s++) != '\0') | 1556 while ((c = *s++) != '\0') |
1557 { | 1557 { |
1558 if (c == '\n') | 1558 if (c == '\n') |
1564 current_input_column++; | 1564 current_input_column++; |
1565 } | 1565 } |
1566 } | 1566 } |
1567 | 1567 |
1568 bool | 1568 bool |
1569 lexical_feedback::inside_any_object_index (void) | 1569 octave_lexer::inside_any_object_index (void) |
1570 { | 1570 { |
1571 bool retval = false; | 1571 bool retval = false; |
1572 | 1572 |
1573 for (std::list<bool>::const_iterator i = looking_at_object_index.begin (); | 1573 for (std::list<bool>::const_iterator i = looking_at_object_index.begin (); |
1574 i != looking_at_object_index.end (); i++) | 1574 i != looking_at_object_index.end (); i++) |
1584 } | 1584 } |
1585 | 1585 |
1586 // Handle keywords. Return -1 if the keyword should be ignored. | 1586 // Handle keywords. Return -1 if the keyword should be ignored. |
1587 | 1587 |
1588 int | 1588 int |
1589 lexical_feedback::is_keyword_token (const std::string& s) | 1589 octave_lexer::is_keyword_token (const std::string& s) |
1590 { | 1590 { |
1591 int l = input_line_number; | 1591 int l = input_line_number; |
1592 int c = current_input_column; | 1592 int c = current_input_column; |
1593 | 1593 |
1594 int len = s.length (); | 1594 int len = s.length (); |
1799 | 1799 |
1800 return 0; | 1800 return 0; |
1801 } | 1801 } |
1802 | 1802 |
1803 bool | 1803 bool |
1804 lexical_feedback::is_variable (const std::string& name) | 1804 octave_lexer::is_variable (const std::string& name) |
1805 { | 1805 { |
1806 return (symbol_table::is_variable (name) | 1806 return (symbol_table::is_variable (name) |
1807 || (pending_local_variables.find (name) | 1807 || (pending_local_variables.find (name) |
1808 != pending_local_variables.end ())); | 1808 != pending_local_variables.end ())); |
1809 } | 1809 } |
1810 | 1810 |
1811 std::string | 1811 std::string |
1812 lexical_feedback::grab_block_comment (stream_reader& reader, bool& eof) | 1812 octave_lexer::grab_block_comment (stream_reader& reader, bool& eof) |
1813 { | 1813 { |
1814 std::string buf; | 1814 std::string buf; |
1815 | 1815 |
1816 bool at_bol = true; | 1816 bool at_bol = true; |
1817 bool look_for_marker = false; | 1817 bool look_for_marker = false; |
1913 | 1913 |
1914 return buf; | 1914 return buf; |
1915 } | 1915 } |
1916 | 1916 |
1917 std::string | 1917 std::string |
1918 lexical_feedback::grab_comment_block (stream_reader& reader, bool at_bol, | 1918 octave_lexer::grab_comment_block (stream_reader& reader, bool at_bol, |
1919 bool& eof) | 1919 bool& eof) |
1920 { | 1920 { |
1921 std::string buf; | 1921 std::string buf; |
1922 | 1922 |
1923 // TRUE means we are at the beginning of a comment block. | 1923 // TRUE means we are at the beginning of a comment block. |
1924 bool begin_comment = false; | 1924 bool begin_comment = false; |
2053 | 2053 |
2054 return buf; | 2054 return buf; |
2055 } | 2055 } |
2056 | 2056 |
2057 int | 2057 int |
2058 lexical_feedback::process_comment (bool start_in_block, bool& eof) | 2058 octave_lexer::process_comment (bool start_in_block, bool& eof) |
2059 { | 2059 { |
2060 OCTAVE_YYG; | 2060 OCTAVE_YYG; |
2061 | 2061 |
2062 eof = false; | 2062 eof = false; |
2063 | 2063 |
2107 | 2107 |
2108 // Recognize separators. If the separator is a CRLF pair, it is | 2108 // Recognize separators. If the separator is a CRLF pair, it is |
2109 // replaced by a single LF. | 2109 // replaced by a single LF. |
2110 | 2110 |
2111 bool | 2111 bool |
2112 lexical_feedback::next_token_is_sep_op (void) | 2112 octave_lexer::next_token_is_sep_op (void) |
2113 { | 2113 { |
2114 bool retval = false; | 2114 bool retval = false; |
2115 | 2115 |
2116 int c = text_yyinput (); | 2116 int c = text_yyinput (); |
2117 | 2117 |
2124 | 2124 |
2125 // Try to determine if the next token should be treated as a postfix | 2125 // Try to determine if the next token should be treated as a postfix |
2126 // unary operator. This is ugly, but it seems to do the right thing. | 2126 // unary operator. This is ugly, but it seems to do the right thing. |
2127 | 2127 |
2128 bool | 2128 bool |
2129 lexical_feedback::next_token_is_postfix_unary_op (bool spc_prev) | 2129 octave_lexer::next_token_is_postfix_unary_op (bool spc_prev) |
2130 { | 2130 { |
2131 bool un_op = false; | 2131 bool un_op = false; |
2132 | 2132 |
2133 int c0 = text_yyinput (); | 2133 int c0 = text_yyinput (); |
2134 | 2134 |
2171 // Note that a line continuation directly following a + or - operator | 2171 // Note that a line continuation directly following a + or - operator |
2172 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be | 2172 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be |
2173 // parsed as a binary operator. | 2173 // parsed as a binary operator. |
2174 | 2174 |
2175 bool | 2175 bool |
2176 lexical_feedback::next_token_is_bin_op (bool spc_prev) | 2176 octave_lexer::next_token_is_bin_op (bool spc_prev) |
2177 { | 2177 { |
2178 bool bin_op = false; | 2178 bool bin_op = false; |
2179 | 2179 |
2180 int c0 = text_yyinput (); | 2180 int c0 = text_yyinput (); |
2181 | 2181 |
2272 } | 2272 } |
2273 | 2273 |
2274 // FIXME -- we need to handle block comments here. | 2274 // FIXME -- we need to handle block comments here. |
2275 | 2275 |
2276 void | 2276 void |
2277 lexical_feedback::scan_for_comments (const char *text) | 2277 octave_lexer::scan_for_comments (const char *text) |
2278 { | 2278 { |
2279 std::string comment_buf; | 2279 std::string comment_buf; |
2280 | 2280 |
2281 bool in_comment = false; | 2281 bool in_comment = false; |
2282 bool beginning_of_comment = false; | 2282 bool beginning_of_comment = false; |
2333 // Discard whitespace, including comments and continuations. | 2333 // Discard whitespace, including comments and continuations. |
2334 | 2334 |
2335 // FIXME -- we need to handle block comments here. | 2335 // FIXME -- we need to handle block comments here. |
2336 | 2336 |
2337 int | 2337 int |
2338 lexical_feedback::eat_whitespace (void) | 2338 octave_lexer::eat_whitespace (void) |
2339 { | 2339 { |
2340 int retval = lexical_feedback::NO_WHITESPACE; | 2340 int retval = octave_lexer::NO_WHITESPACE; |
2341 | 2341 |
2342 std::string comment_buf; | 2342 std::string comment_buf; |
2343 | 2343 |
2344 bool in_comment = false; | 2344 bool in_comment = false; |
2345 bool beginning_of_comment = false; | 2345 bool beginning_of_comment = false; |
2357 if (in_comment) | 2357 if (in_comment) |
2358 { | 2358 { |
2359 comment_buf += static_cast<char> (c); | 2359 comment_buf += static_cast<char> (c); |
2360 beginning_of_comment = false; | 2360 beginning_of_comment = false; |
2361 } | 2361 } |
2362 retval |= lexical_feedback::SPACE_OR_TAB; | 2362 retval |= octave_lexer::SPACE_OR_TAB; |
2363 break; | 2363 break; |
2364 | 2364 |
2365 case '\n': | 2365 case '\n': |
2366 retval |= lexical_feedback::NEWLINE; | 2366 retval |= octave_lexer::NEWLINE; |
2367 if (in_comment) | 2367 if (in_comment) |
2368 { | 2368 { |
2369 comment_buf += static_cast<char> (c); | 2369 comment_buf += static_cast<char> (c); |
2370 octave_comment_buffer::append (comment_buf); | 2370 octave_comment_buffer::append (comment_buf); |
2371 comment_buf.resize (0); | 2371 comment_buf.resize (0); |
2446 { | 2446 { |
2447 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); | 2447 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); |
2448 } | 2448 } |
2449 | 2449 |
2450 void | 2450 void |
2451 lexical_feedback::handle_number (void) | 2451 octave_lexer::handle_number (void) |
2452 { | 2452 { |
2453 double value = 0.0; | 2453 double value = 0.0; |
2454 int nread = 0; | 2454 int nread = 0; |
2455 | 2455 |
2456 char *yytxt = flex_yytext (); | 2456 char *yytxt = flex_yytext (); |
2504 // characters, return 0. Otherwise, return 1. | 2504 // characters, return 0. Otherwise, return 1. |
2505 | 2505 |
2506 // FIXME -- we need to handle block comments here. | 2506 // FIXME -- we need to handle block comments here. |
2507 | 2507 |
2508 bool | 2508 bool |
2509 lexical_feedback::have_continuation (bool trailing_comments_ok) | 2509 octave_lexer::have_continuation (bool trailing_comments_ok) |
2510 { | 2510 { |
2511 std::ostringstream buf; | 2511 std::ostringstream buf; |
2512 | 2512 |
2513 std::string comment_buf; | 2513 std::string comment_buf; |
2514 | 2514 |
2592 // We have seen a '.' and need to see if it is the start of a | 2592 // We have seen a '.' and need to see if it is the start of a |
2593 // continuation. If so, this eats it, up to and including the new | 2593 // continuation. If so, this eats it, up to and including the new |
2594 // line character. | 2594 // line character. |
2595 | 2595 |
2596 bool | 2596 bool |
2597 lexical_feedback::have_ellipsis_continuation (bool trailing_comments_ok) | 2597 octave_lexer::have_ellipsis_continuation (bool trailing_comments_ok) |
2598 { | 2598 { |
2599 char c1 = text_yyinput (); | 2599 char c1 = text_yyinput (); |
2600 if (c1 == '.') | 2600 if (c1 == '.') |
2601 { | 2601 { |
2602 char c2 = text_yyinput (); | 2602 char c2 = text_yyinput (); |
2616 | 2616 |
2617 // See if we have a continuation line. If so, eat it and the leading | 2617 // See if we have a continuation line. If so, eat it and the leading |
2618 // whitespace on the next line. | 2618 // whitespace on the next line. |
2619 | 2619 |
2620 int | 2620 int |
2621 lexical_feedback::eat_continuation (void) | 2621 octave_lexer::eat_continuation (void) |
2622 { | 2622 { |
2623 int retval = lexical_feedback::NO_WHITESPACE; | 2623 int retval = octave_lexer::NO_WHITESPACE; |
2624 | 2624 |
2625 int c = text_yyinput (); | 2625 int c = text_yyinput (); |
2626 | 2626 |
2627 if ((c == '.' && have_ellipsis_continuation ()) | 2627 if ((c == '.' && have_ellipsis_continuation ()) |
2628 || (c == '\\' && have_continuation ())) | 2628 || (c == '\\' && have_continuation ())) |
2632 | 2632 |
2633 return retval; | 2633 return retval; |
2634 } | 2634 } |
2635 | 2635 |
2636 int | 2636 int |
2637 lexical_feedback::handle_string (char delim) | 2637 octave_lexer::handle_string (char delim) |
2638 { | 2638 { |
2639 std::ostringstream buf; | 2639 std::ostringstream buf; |
2640 | 2640 |
2641 int bos_line = input_line_number; | 2641 int bos_line = input_line_number; |
2642 int bos_col = current_input_column; | 2642 int bos_col = current_input_column; |
2725 | 2725 |
2726 return LEXICAL_ERROR; | 2726 return LEXICAL_ERROR; |
2727 } | 2727 } |
2728 | 2728 |
2729 bool | 2729 bool |
2730 lexical_feedback::next_token_is_assign_op (void) | 2730 octave_lexer::next_token_is_assign_op (void) |
2731 { | 2731 { |
2732 bool retval = false; | 2732 bool retval = false; |
2733 | 2733 |
2734 int c0 = text_yyinput (); | 2734 int c0 = text_yyinput (); |
2735 | 2735 |
2809 | 2809 |
2810 return retval; | 2810 return retval; |
2811 } | 2811 } |
2812 | 2812 |
2813 bool | 2813 bool |
2814 lexical_feedback::next_token_is_index_op (void) | 2814 octave_lexer::next_token_is_index_op (void) |
2815 { | 2815 { |
2816 int c = text_yyinput (); | 2816 int c = text_yyinput (); |
2817 xunput (c); | 2817 xunput (c); |
2818 return c == '(' || c == '{'; | 2818 return c == '(' || c == '{'; |
2819 } | 2819 } |
2820 | 2820 |
2821 int | 2821 int |
2822 lexical_feedback::handle_close_bracket (bool spc_gobbled, int bracket_type) | 2822 octave_lexer::handle_close_bracket (bool spc_gobbled, int bracket_type) |
2823 { | 2823 { |
2824 OCTAVE_YYG; | 2824 OCTAVE_YYG; |
2825 | 2825 |
2826 int retval = bracket_type; | 2826 int retval = bracket_type; |
2827 | 2827 |
2885 | 2885 |
2886 return retval; | 2886 return retval; |
2887 } | 2887 } |
2888 | 2888 |
2889 void | 2889 void |
2890 lexical_feedback::maybe_unput_comma (int spc_gobbled) | 2890 octave_lexer::maybe_unput_comma (int spc_gobbled) |
2891 { | 2891 { |
2892 if (nesting_level.is_bracket () | 2892 if (nesting_level.is_bracket () |
2893 || (nesting_level.is_brace () | 2893 || (nesting_level.is_brace () |
2894 && ! looking_at_object_index.front ())) | 2894 && ! looking_at_object_index.front ())) |
2895 { | 2895 { |
2924 xunput (','); | 2924 xunput (','); |
2925 } | 2925 } |
2926 } | 2926 } |
2927 | 2927 |
2928 bool | 2928 bool |
2929 lexical_feedback::next_token_can_follow_bin_op (void) | 2929 octave_lexer::next_token_can_follow_bin_op (void) |
2930 { | 2930 { |
2931 std::stack<char> buf; | 2931 std::stack<char> buf; |
2932 | 2932 |
2933 int c = EOF; | 2933 int c = EOF; |
2934 | 2934 |
2966 || tok == "Inf" || tok == "inf" | 2966 || tok == "Inf" || tok == "inf" |
2967 || tok == "NaN" || tok == "nan"); | 2967 || tok == "NaN" || tok == "nan"); |
2968 } | 2968 } |
2969 | 2969 |
2970 bool | 2970 bool |
2971 lexical_feedback::looks_like_command_arg (void) | 2971 octave_lexer::looks_like_command_arg (void) |
2972 { | 2972 { |
2973 bool retval = true; | 2973 bool retval = true; |
2974 | 2974 |
2975 int c0 = text_yyinput (); | 2975 int c0 = text_yyinput (); |
2976 | 2976 |
3188 | 3188 |
3189 return retval; | 3189 return retval; |
3190 } | 3190 } |
3191 | 3191 |
3192 int | 3192 int |
3193 lexical_feedback::handle_superclass_identifier (void) | 3193 octave_lexer::handle_superclass_identifier (void) |
3194 { | 3194 { |
3195 eat_continuation (); | 3195 eat_continuation (); |
3196 | 3196 |
3197 std::string pkg; | 3197 std::string pkg; |
3198 char *yytxt = flex_yytext (); | 3198 char *yytxt = flex_yytext (); |
3226 | 3226 |
3227 return SUPERCLASSREF; | 3227 return SUPERCLASSREF; |
3228 } | 3228 } |
3229 | 3229 |
3230 int | 3230 int |
3231 lexical_feedback::handle_meta_identifier (void) | 3231 octave_lexer::handle_meta_identifier (void) |
3232 { | 3232 { |
3233 eat_continuation (); | 3233 eat_continuation (); |
3234 | 3234 |
3235 std::string pkg; | 3235 std::string pkg; |
3236 char *yytxt = flex_yytext (); | 3236 char *yytxt = flex_yytext (); |
3263 // Figure out exactly what kind of token to return when we have seen | 3263 // Figure out exactly what kind of token to return when we have seen |
3264 // an identifier. Handles keywords. Return -1 if the identifier | 3264 // an identifier. Handles keywords. Return -1 if the identifier |
3265 // should be ignored. | 3265 // should be ignored. |
3266 | 3266 |
3267 int | 3267 int |
3268 lexical_feedback::handle_identifier (void) | 3268 octave_lexer::handle_identifier (void) |
3269 { | 3269 { |
3270 OCTAVE_YYG; | 3270 OCTAVE_YYG; |
3271 | 3271 |
3272 bool at_bos = at_beginning_of_statement; | 3272 bool at_bos = at_beginning_of_statement; |
3273 | 3273 |
3275 | 3275 |
3276 std::string tok = strip_trailing_whitespace (yytxt); | 3276 std::string tok = strip_trailing_whitespace (yytxt); |
3277 | 3277 |
3278 int c = yytxt[flex_yyleng()-1]; | 3278 int c = yytxt[flex_yyleng()-1]; |
3279 | 3279 |
3280 bool cont_is_spc = (eat_continuation () != lexical_feedback::NO_WHITESPACE); | 3280 bool cont_is_spc = (eat_continuation () != octave_lexer::NO_WHITESPACE); |
3281 | 3281 |
3282 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 3282 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
3283 | 3283 |
3284 // If we are expecting a structure element, avoid recognizing | 3284 // If we are expecting a structure element, avoid recognizing |
3285 // keywords and other special names and return STRUCT_ELT, which is | 3285 // keywords and other special names and return STRUCT_ELT, which is |
3432 | 3432 |
3433 return NAME; | 3433 return NAME; |
3434 } | 3434 } |
3435 | 3435 |
3436 void | 3436 void |
3437 lexical_feedback::maybe_warn_separator_insert (char sep) | 3437 octave_lexer::maybe_warn_separator_insert (char sep) |
3438 { | 3438 { |
3439 std::string nm = curr_fcn_file_full_name; | 3439 std::string nm = curr_fcn_file_full_name; |
3440 | 3440 |
3441 if (nm.empty ()) | 3441 if (nm.empty ()) |
3442 warning_with_id ("Octave:separator-insert", | 3442 warning_with_id ("Octave:separator-insert", |
3447 "potential auto-insertion of '%c' near line %d of file %s", | 3447 "potential auto-insertion of '%c' near line %d of file %s", |
3448 sep, input_line_number, nm.c_str ()); | 3448 sep, input_line_number, nm.c_str ()); |
3449 } | 3449 } |
3450 | 3450 |
3451 void | 3451 void |
3452 lexical_feedback::gripe_single_quote_string (void) | 3452 octave_lexer::gripe_single_quote_string (void) |
3453 { | 3453 { |
3454 std::string nm = curr_fcn_file_full_name; | 3454 std::string nm = curr_fcn_file_full_name; |
3455 | 3455 |
3456 if (nm.empty ()) | 3456 if (nm.empty ()) |
3457 warning_with_id ("Octave:single-quote-string", | 3457 warning_with_id ("Octave:single-quote-string", |
3462 "single quote delimited string near line %d of file %s", | 3462 "single quote delimited string near line %d of file %s", |
3463 input_line_number, nm.c_str ()); | 3463 input_line_number, nm.c_str ()); |
3464 } | 3464 } |
3465 | 3465 |
3466 void | 3466 void |
3467 lexical_feedback::gripe_matlab_incompatible (const std::string& msg) | 3467 octave_lexer::gripe_matlab_incompatible (const std::string& msg) |
3468 { | 3468 { |
3469 std::string nm = curr_fcn_file_full_name; | 3469 std::string nm = curr_fcn_file_full_name; |
3470 | 3470 |
3471 if (nm.empty ()) | 3471 if (nm.empty ()) |
3472 warning_with_id ("Octave:matlab-incompatible", | 3472 warning_with_id ("Octave:matlab-incompatible", |
3477 "potential Matlab compatibility problem: %s near line %d offile %s", | 3477 "potential Matlab compatibility problem: %s near line %d offile %s", |
3478 msg.c_str (), input_line_number, nm.c_str ()); | 3478 msg.c_str (), input_line_number, nm.c_str ()); |
3479 } | 3479 } |
3480 | 3480 |
3481 void | 3481 void |
3482 lexical_feedback::maybe_gripe_matlab_incompatible_comment (char c) | 3482 octave_lexer::maybe_gripe_matlab_incompatible_comment (char c) |
3483 { | 3483 { |
3484 if (c == '#') | 3484 if (c == '#') |
3485 gripe_matlab_incompatible ("# used as comment character"); | 3485 gripe_matlab_incompatible ("# used as comment character"); |
3486 } | 3486 } |
3487 | 3487 |
3488 void | 3488 void |
3489 lexical_feedback::gripe_matlab_incompatible_continuation (void) | 3489 octave_lexer::gripe_matlab_incompatible_continuation (void) |
3490 { | 3490 { |
3491 gripe_matlab_incompatible ("\\ used as line continuation marker"); | 3491 gripe_matlab_incompatible ("\\ used as line continuation marker"); |
3492 } | 3492 } |
3493 | 3493 |
3494 void | 3494 void |
3495 lexical_feedback::gripe_matlab_incompatible_operator (const std::string& op) | 3495 octave_lexer::gripe_matlab_incompatible_operator (const std::string& op) |
3496 { | 3496 { |
3497 std::string t = op; | 3497 std::string t = op; |
3498 int n = t.length (); | 3498 int n = t.length (); |
3499 if (t[n-1] == '\n') | 3499 if (t[n-1] == '\n') |
3500 t.resize (n-1); | 3500 t.resize (n-1); |
3501 gripe_matlab_incompatible (t + " used as operator"); | 3501 gripe_matlab_incompatible (t + " used as operator"); |
3502 } | 3502 } |
3503 | 3503 |
3504 void | 3504 void |
3505 lexical_feedback::push_token (token *tok) | 3505 octave_lexer::push_token (token *tok) |
3506 { | 3506 { |
3507 YYSTYPE *lval = yyget_lval (scanner); | 3507 YYSTYPE *lval = yyget_lval (scanner); |
3508 lval->tok_val = tok; | 3508 lval->tok_val = tok; |
3509 token_stack.push (tok); | 3509 token_stack.push (tok); |
3510 } | 3510 } |
3511 | 3511 |
3512 token * | 3512 token * |
3513 lexical_feedback::current_token (void) | 3513 octave_lexer::current_token (void) |
3514 { | 3514 { |
3515 YYSTYPE *lval = yyget_lval (scanner); | 3515 YYSTYPE *lval = yyget_lval (scanner); |
3516 return lval->tok_val; | 3516 return lval->tok_val; |
3517 } | 3517 } |
3518 | 3518 |
3519 void | 3519 void |
3520 lexical_feedback::display_token (int tok) | 3520 octave_lexer::display_token (int tok) |
3521 { | 3521 { |
3522 switch (tok) | 3522 switch (tok) |
3523 { | 3523 { |
3524 case '=': std::cerr << "'='\n"; break; | 3524 case '=': std::cerr << "'='\n"; break; |
3525 case ':': std::cerr << "':'\n"; break; | 3525 case ':': std::cerr << "':'\n"; break; |
3686 break; | 3686 break; |
3687 } | 3687 } |
3688 } | 3688 } |
3689 | 3689 |
3690 void | 3690 void |
3691 lexical_feedback::fatal_error (const char *msg) | 3691 octave_lexer::fatal_error (const char *msg) |
3692 { | 3692 { |
3693 error (msg); | 3693 error (msg); |
3694 | 3694 |
3695 OCTAVE_QUIT; | 3695 OCTAVE_QUIT; |
3696 | 3696 |
3697 yy_fatal_error (msg, scanner); | 3697 yy_fatal_error (msg, scanner); |
3698 } | 3698 } |
3699 | 3699 |
3700 void | 3700 void |
3701 lexical_feedback::lexer_debug (const char *pattern, const char *text) | 3701 octave_lexer::lexer_debug (const char *pattern, const char *text) |
3702 { | 3702 { |
3703 OCTAVE_YYG; | 3703 OCTAVE_YYG; |
3704 | 3704 |
3705 std::cerr << std::endl; | 3705 std::cerr << std::endl; |
3706 | 3706 |