Mercurial > octave
diff libinterp/parse-tree/lex.ll @ 26662:05fc703b419a
update handling of command-style function call syntax in eval
* lex.h, lex.ll (lexical_feedback::m_allow_command_syntax):
New data member.
(lexical_feedback::reset): Reset it.
(lexical_feedback::previous_token_may_be_command,
base_lexer::looks_like_command_arg): Return false immediately if
m_allow_command_syntax is false.
(base_lexer::is_variable): Check if name is a variable if parsing in
top level scope.
* parse.h, oct-parse.yy (base_parser::disallow_command_syntax):
New function.
(word_list_command): Mark index expression as a word list command.
* pt-eval.cc (tree_evaluator::eval_string): If nargout > 0, don't
allow evaluated code to be parsed as a command-style function call.
(tree_evaluator::visit_index_expression): Error if identifier is a
variable and index expression is a command-style function call.
* pt-idx.h, pt-idx.cc (tree_index_expression::m_word_list_cmd):
New member variable.
(tree_index_expression::mark_word_list_cmd,
tree_index_expression::is_word_list_cmd): New functions.
* clearvars.m: Avoid evaluating command-style function call when
assigning result of call to eval.
* test/eval-command.tst: New file.
* bug-38565.tst, bug-38576.tst: Delete obsolete tests.
* test/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 31 Jan 2019 18:45:37 +0000 |
parents | cf9e10ce3351 |
children | 581d01526b34 |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll Mon Jan 28 18:01:46 2019 +0000 +++ b/libinterp/parse-tree/lex.ll Thu Jan 31 18:45:37 2019 +0000 @@ -2085,6 +2085,7 @@ lexical_feedback::reset (void) { m_end_of_input = false; + m_allow_command_syntax = true; m_at_beginning_of_statement = true; m_looking_at_anon_fcn_args = false; m_looking_at_return_list = false; @@ -2197,6 +2198,9 @@ bool lexical_feedback::previous_token_may_be_command (void) const { + if (! m_allow_command_syntax) + return false; + const token *tok = m_tokens.front (); return tok ? tok->may_be_command () : false; } @@ -2473,8 +2477,9 @@ base_lexer::is_variable (const std::string& name, const symbol_scope& /*scope*/) { - return (/* (scope && scope.is_variable (name)) - || */ (m_pending_local_variables.find (name) + return ((m_interpreter.at_top_level () + && m_interpreter.is_variable (name)) + || (m_pending_local_variables.find (name) != m_pending_local_variables.end ())); } @@ -2947,6 +2952,9 @@ bool base_lexer::looks_like_command_arg (void) { + if (! m_allow_command_syntax) + return false; + bool space_before = space_follows_previous_token (); bool space_after = looking_at_space ();