Mercurial > octave
diff src/lex.ll @ 10052:5813ec5077b5
don't allow e, i, j, inf, or nan to be commands
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 04 Jan 2010 03:00:19 -0500 |
parents | e6441e13acb2 |
children | 412464619f9c |
line wrap: on
line diff
--- a/src/lex.ll Mon Jan 04 02:11:07 2010 -0500 +++ b/src/lex.ll Mon Jan 04 03:00:19 2010 -0500 @@ -2833,6 +2833,19 @@ } static bool +can_be_command (const std::string& tok) +{ + // Don't allow these names to be treated as commands to avoid + // surprises when parsing things like "NaN ^2". + + return ! (tok == "e" + || tok == "I" || tok == "i" + || tok == "J" || tok == "j" + || tok == "Inf" || tok == "inf" + || tok == "NaN" || tok == "nan"); +} + +static bool looks_like_command_arg (void) { bool retval = true; @@ -3251,7 +3264,8 @@ if (! is_variable (tok)) { - if (at_bos && spc_gobbled && looks_like_command_arg ()) + if (at_bos && spc_gobbled && can_be_command (tok) + && looks_like_command_arg ()) { BEGIN (COMMAND_START); }