# HG changeset patch # User John W. Eaton # Date 1362004092 18000 # Node ID ed8ce5da525f31001fbda40b4be72c7c96facff3 # Parent b6050fc0a2d91bb755a24fabf9113359f8a0fd6c don't access lexer values directly when grabbing help text from .m files. * oct-parse.yy (text_getc): Don't update line number. (stdio_stream_reader::line_num, stdio_stream_reader:column_num): New data members. (stdio_stream_reader::stdio_stream_reader): New args for line and column numbers. (stdio_stream_reader::getc): Set line and column info here. (stdio_stream_reader:ungetc): Set local line number here. (gobble_leading_white_space): New args, line_num and column_num. Pass them to stdio_stream_reader constructor. (gobble_leading_white_space): Provide additional function without line and column number arguments. diff --git a/libinterp/parse-tree/oct-parse.yy b/libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy +++ b/libinterp/parse-tree/oct-parse.yy @@ -3154,9 +3154,6 @@ } } - if (c == '\n') - curr_lexer->input_line_number++; - return c; } @@ -3164,20 +3161,53 @@ stdio_stream_reader : public stream_reader { public: - stdio_stream_reader (FILE *f_arg) : stream_reader (), f (f_arg) { } - - int getc (void) { return ::text_getc (f); } + + stdio_stream_reader (FILE *f_arg, int& l, int& c) + : stream_reader (), f (f_arg), line_num (l), column_num (c) + { } + + int getc (void) + { + char c = ::text_getc (f); + + if (c == '\n') + { + line_num++; + column_num = 0; + } + else + { + // FIXME -- try to be smarter about tabs? + column_num++; + } + + return c; + } + int ungetc (int c) { if (c == '\n') - curr_lexer->input_line_number--; + { + line_num--; + column_num = 0; + } + else + { + // FIXME -- try to be smarter about tabs? + column_num--; + } return ::ungetc (c, f); } private: + FILE *f; + int& line_num; + + int& column_num; + // No copying! stdio_stream_reader (const stdio_stream_reader&); @@ -3196,11 +3226,7 @@ { case ' ': case '\t': - curr_lexer->current_input_column++; - break; - case '\n': - curr_lexer->current_input_column = 1; break; default: @@ -3234,7 +3260,8 @@ } static std::string -gobble_leading_white_space (FILE *ffile, bool& eof) +gobble_leading_white_space (FILE *ffile, bool& eof, int& line_num, + int& column_num) { std::string help_txt; @@ -3245,7 +3272,7 @@ std::string txt; - stdio_stream_reader stdio_reader (ffile); + stdio_stream_reader stdio_reader (ffile, line_num, column_num); while (true) { @@ -3274,6 +3301,15 @@ return help_txt; } +static std::string +gobble_leading_white_space (FILE *ffile, bool& eof) +{ + int line_num = 1; + int column_num = 1; + + return gobble_leading_white_space (ffile, eof, line_num, column_num); +} + static bool looking_at_function_keyword (FILE *ffile) {