comparison libinterp/parse-tree/oct-parse.yy @ 27766:0ca7f17de041

use file position object to track line and column info in lexer and parser * filepos.h: New file. * libinterp/parse-tree/module.mk: Update. * lex.h, lex.ll (lexical_feedback::m_filepos): New member variable for tracking file position. (lexical_feedback::m_input_line_number, lexical_feedback::m_current_input_column): Delete. Replace all uses with operations on m_filepos.
author John W. Eaton <jwe@octave.org>
date Mon, 02 Dec 2019 18:20:28 -0600
parents f64e399b6dda
children 2f8559459314
comparison
equal deleted inserted replaced
27765:dd93e1fdc7db 27766:0ca7f17de041
1568 } 1568 }
1569 else 1569 else
1570 { 1570 {
1571 octave::tree_statement *end_of_script 1571 octave::tree_statement *end_of_script
1572 = parser.make_end ("endscript", true, 1572 = parser.make_end ("endscript", true,
1573 lexer.m_input_line_number, 1573 lexer.m_filepos.line (), lexer.m_filepos.column ());
1574 lexer.m_current_input_column);
1575 1574
1576 parser.make_script ($3, end_of_script); 1575 parser.make_script ($3, end_of_script);
1577 } 1576 }
1578 1577
1579 $$ = nullptr; 1578 $$ = nullptr;
1678 parser.bison_error ("classdef body open at end of input"); 1677 parser.bison_error ("classdef body open at end of input");
1679 YYABORT; 1678 YYABORT;
1680 } 1679 }
1681 1680
1682 $$ = parser.make_end ("endfunction", true, 1681 $$ = parser.make_end ("endfunction", true,
1683 lexer.m_input_line_number, 1682 lexer.m_filepos.line (), lexer.m_filepos.column ());
1684 lexer.m_current_input_column);
1685 } 1683 }
1686 ; 1684 ;
1687 1685
1688 function : function_beg stash_comment fcn_name 1686 function : function_beg stash_comment fcn_name
1689 opt_param_list opt_sep opt_list function_end 1687 opt_param_list opt_sep opt_list function_end
2561 tree_anon_fcn_handle * 2559 tree_anon_fcn_handle *
2562 base_parser::make_anon_fcn_handle (tree_parameter_list *param_list, 2560 base_parser::make_anon_fcn_handle (tree_parameter_list *param_list,
2563 tree_expression *expr) 2561 tree_expression *expr)
2564 { 2562 {
2565 // FIXME: need to get these from the location of the @ symbol. 2563 // FIXME: need to get these from the location of the @ symbol.
2566 int l = m_lexer.m_input_line_number; 2564 int l = m_lexer.m_filepos.line ();
2567 int c = m_lexer.m_current_input_column; 2565 int c = m_lexer.m_filepos.column ();
2568 2566
2569 // FIXME: We need to examine EXPR and issue an error if any 2567 // FIXME: We need to examine EXPR and issue an error if any
2570 // sub-expression contains an assignment, compound assignment, 2568 // sub-expression contains an assignment, compound assignment,
2571 // increment, or decrement operator. 2569 // increment, or decrement operator.
2572 2570
4519 } 4517 }
4520 4518
4521 void 4519 void
4522 base_parser::bison_error (const std::string& str, int l, int c) 4520 base_parser::bison_error (const std::string& str, int l, int c)
4523 { 4521 {
4524 int err_line = l < 0 ? m_lexer.m_input_line_number : l; 4522 int err_line = l < 0 ? m_lexer.m_filepos.line () : l;
4525 int err_col = c < 0 ? m_lexer.m_current_input_column - 1 : c; 4523 int err_col = c < 0 ? m_lexer.m_filepos.column () - 1 : c;
4526 4524
4527 std::ostringstream output_buf; 4525 std::ostringstream output_buf;
4528 4526
4529 if (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file 4527 if (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file
4530 || m_lexer.m_reading_classdef_file) 4528 || m_lexer.m_reading_classdef_file)
4542 4540
4543 if (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file 4541 if (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file
4544 || m_lexer.m_reading_classdef_file) 4542 || m_lexer.m_reading_classdef_file)
4545 curr_line = get_file_line (m_lexer.m_fcn_file_full_name, err_line); 4543 curr_line = get_file_line (m_lexer.m_fcn_file_full_name, err_line);
4546 else 4544 else
4547 curr_line = m_lexer.m_current_input_line; 4545 curr_line = m_lexer.m_filepos.line ();
4548 4546
4549 if (! curr_line.empty ()) 4547 if (! curr_line.empty ())
4550 { 4548 {
4551 // FIXME: we could do better if we just cached lines from the 4549 // FIXME: we could do better if we just cached lines from the
4552 // input file in a list. See also functions for managing input 4550 // input file in a list. See also functions for managing input