Mercurial > hg > octave-lyh
diff src/variables.cc @ 4179:8734ba917fea
[project @ 2002-11-14 04:31:19 by jwe]
author | jwe |
---|---|
date | Thu, 14 Nov 2002 04:31:19 +0000 |
parents | 62afb31c1f85 |
children | fa3482b34599 |
line wrap: on
line diff
--- a/src/variables.cc +++ b/src/variables.cc @@ -271,6 +271,24 @@ return retval; } +static inline bool +is_variable (const std::string& name) +{ + bool retval = false; + + if (! name.empty ()) + { + symbol_record *sr = curr_sym_tab->lookup (name); + + if (! sr) + sr = fbi_sym_tab->lookup (name); + + retval = (sr && sr->is_variable ()); + } + + return retval; +} + string_vector generate_struct_completions (const std::string& text, std::string& prefix, std::string& hint) @@ -287,34 +305,48 @@ hint = text.substr (pos+1); prefix = text.substr (0, pos); - } - int parse_status; + std::string base_name = prefix; + + pos = base_name.find_first_of ("{(."); - unwind_protect::begin_frame ("generate_struct_completions"); + if (pos != NPOS) + base_name = base_name.substr (0, pos); - unwind_protect_str (Vwarning_option); - unwind_protect_bool (discard_error_messages); - unwind_protect_int (error_state); + if (is_variable (base_name)) + { + int parse_status; + + unwind_protect::begin_frame ("generate_struct_completions"); - Vwarning_option = "off"; - discard_error_messages = true; + unwind_protect_str (Vwarning_option); + unwind_protect_bool (discard_error_messages); + unwind_protect_int (error_state); - octave_value tmp = eval_string (prefix, true, parse_status); + Vwarning_option = "off"; + discard_error_messages = true; - unwind_protect::run_frame ("generate_struct_completions"); + octave_value tmp = eval_string (prefix, true, parse_status); + + unwind_protect::run_frame ("generate_struct_completions"); - if (tmp.is_defined () && tmp.is_map ()) - names = tmp.map_keys (); + if (tmp.is_defined () && tmp.is_map ()) + names = tmp.map_keys (); + } + } return names; } +// XXX FIXME XXX -- this will have to be much smarter to work +// "correctly". + bool looks_like_struct (const std::string& text) { bool retval = false; +#if 0 symbol_record *sr = curr_sym_tab->lookup (text); if (sr && ! sr->is_function ()) @@ -336,6 +368,7 @@ retval = (tmp.is_defined () && tmp.is_map ()); } +#endif return retval; }