changeset 21065:e1ee2203efe0

allow location info to be passed to octave_base_parser::bison_error * parse.h, oct-parse.in.yy (octave_base_parser::bison_error): Accept line and column arguments. Use std::string instead of char * for message argument.
author John W. Eaton <jwe@octave.org>
date Thu, 14 Jan 2016 06:20:28 -0500
parents a9f2c2d72892
children 258c787cd9ce
files libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h
diffstat 2 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.in.yy	Thu Jan 14 05:28:27 2016 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Thu Jan 14 06:20:28 2016 -0500
@@ -3976,20 +3976,21 @@
 }
 
 void
-octave_base_parser::bison_error (const char *s)
+octave_base_parser::bison_error (const std::string& str, int l, int c)
 {
-  int err_col = lexer.current_input_column - 1;
+  int err_line = l < 0 ? lexer.input_line_number : l;
+  int err_col = c < 0 ? lexer.current_input_column - 1 : c;
 
   std::ostringstream output_buf;
 
   if (lexer.reading_fcn_file || lexer.reading_script_file || lexer.reading_classdef_file)
-    output_buf << "parse error near line " << lexer.input_line_number
+    output_buf << "parse error near line " << err_line
                << " of file " << lexer.fcn_file_full_name;
   else
     output_buf << "parse error:";
 
-  if (s && strcmp (s, "parse error") != 0)
-    output_buf << "\n\n  " << s;
+  if (str != "parse error")
+    output_buf << "\n\n  " << str;
 
   output_buf << "\n\n";
 
--- a/libinterp/parse-tree/parse.h	Thu Jan 14 05:28:27 2016 -0500
+++ b/libinterp/parse-tree/parse.h	Thu Jan 14 06:20:28 2016 -0500
@@ -389,7 +389,7 @@
                          tree_statement *stmt, bool warn_missing_semi);
 
   // Generic error messages.
-  void bison_error (const char *s);
+  void bison_error (const std::string& s, int l = -1, int c = -1);
 
   // Have we found an explicit end to a function?
   bool endfunction_found;