Mercurial > hg > octave-nkf
changeset 4426:51a0dcde8778
[project @ 2003-06-13 19:16:37 by jwe]
author | jwe |
---|---|
date | Fri, 13 Jun 2003 19:16:38 +0000 |
parents | 82f8aae8cf20 |
children | 8040775cf0a9 |
files | src/ChangeLog src/lex.l src/parse.h src/parse.y |
diffstat | 4 files changed, 49 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2003-06-13 John W. Eaton <jwe@bevo.che.wisc.edu> + * parse.y (frob_function, parse_fcn_file): Handle help_buf as + stack of strings. + * lex.l ({CCHAR}): Handle help_buf as stack of strings. + Store text returned from grab_help_text in help_buf here. + (reset_parser): Handle help_buf as stack of strings. + (prep_for_nested_function): Push empty string onto help_buf stack. + (grab_help_text): Return help text instead of storing it in help_buf. + * parse.h, parse.y (help_buf): Now a stack of strings. + * oct-stream.cc (printf_value_cache::string_value): Don't attempt to extract values when none are available.
--- a/src/lex.l +++ b/src/lex.l @@ -201,7 +201,7 @@ static void prep_for_nested_function (void); static std::string plot_style_token (const std::string& s); static symbol_record *lookup_identifier (const std::string& s); -static void grab_help_text (void); +static std::string grab_help_text (void); static bool match_any (char c, const char *s); static bool next_token_is_sep_op (void); static bool next_token_is_bin_op (bool spc_prev); @@ -628,15 +628,25 @@ %} {CCHAR} { - if (help_buf.empty () + std::string help_txt; + + if (! help_buf.empty ()) + help_txt = help_buf.top (); + + if (help_txt.empty () && lexer_flags.beginning_of_function && nesting_level.none ()) { lexer_flags.beginning_of_function = false; - grab_help_text (); - - octave_comment_buffer::append (help_buf); + std::string txt = grab_help_text (); + + if (! help_buf.empty ()) + help_buf.pop (); + + help_buf.push (txt); + + octave_comment_buffer::append (txt); } else { @@ -883,7 +893,8 @@ yyrestart (stdin); // Clear the buffer for help text. - help_buf.resize (0); + while (! help_buf.empty ()) + help_buf.pop (); // Reset other flags. lexer_flags.init (); @@ -1105,6 +1116,7 @@ prep_for_nested_function (void) { lexer_flags.parsing_nested_function = 1; + help_buf.push (std::string ()); prep_for_function (); // We're still only expecting one end token for this set of functions. end_tokens_expected--; @@ -1378,16 +1390,15 @@ sr->define (octave_value ()); } -// Grab the help text from an function file. Always overwrites the -// current contents of help_buf. +// Grab the help text from an function file. // XXX FIXME XXX -- gobble_leading_white_space() in parse.y // duplicates some of this code! -static void +static std::string grab_help_text (void) { - help_buf.resize (0); + std::string buf; bool begin_comment = true; bool in_comment = true; @@ -1412,7 +1423,7 @@ if (in_comment) { - help_buf += static_cast<char> (c); + buf += static_cast<char> (c); if (c == '\n') { @@ -1445,6 +1456,8 @@ if (c) yyunput (c, yytext); + + return buf; } // Return 1 if the given character matches any character in the given
--- a/src/parse.h +++ b/src/parse.h @@ -27,6 +27,8 @@ #include <string> +#include <stack> + extern void reset_parser (void); extern int yylex (void); extern int yyparse (void); @@ -53,7 +55,7 @@ extern int current_input_column; // Buffer for help text snagged from function files. -extern std::string help_buf; +extern std::stack<std::string> help_buf; // TRUE means we are using readline. extern bool line_editing;
--- a/src/parse.y +++ b/src/parse.y @@ -112,7 +112,7 @@ int current_input_column = 1; // Buffer for help text snagged from function files. -std::string help_buf; +std::stack<std::string> help_buf; // Buffer for comments appearing before a function statement. static std::string fcn_comment_header; @@ -2621,13 +2621,15 @@ id->define (fcn, symbol_record::USER_FUNCTION); - id->document (help_buf); - - help_buf.resize (0); + if (! help_buf.empty ()) + { + id->document (help_buf.top ()); + help_buf.pop (); + } if (lexer_flags.parsing_nested_function < 0) lexer_flags.parsing_nested_function = 0; - + return fcn; } @@ -3343,9 +3345,12 @@ reset_parser (); - help_buf = gobble_leading_white_space (ffile, true, true, true); - - octave_comment_buffer::append (help_buf); + std::string txt + = gobble_leading_white_space (ffile, true, true, true); + + help_buf.push (txt); + + octave_comment_buffer::append (txt); // XXX FIXME XXX -- this should not be necessary. gobble_leading_white_space (ffile, false, true, false);