Re: Spurious undefined variable error generated for certain valid ternary expressions
Brett Stahlman wrote: The following expression var10?var:10 generates the following errors: E121: Undefined variable: var:10 E15: Invalid expression: var10?var:10 The reason is that find_name_end uses eval_isnamec unconditionally to decide whether a character is a valid variable name character, with the result that `:' is always gobbled up as part of the variable name, even if it's not the second character in the name string (ie, even if it doesn't separate the scope prefix from the variable name). find_var_ht, on the other hand, will not permit a colon anywhere but at character index 1 in the variable name; hence, E121, and ultimately, E15. Since `:' is part of a valid VimL operator, and is not valid anywhere other than at index 1 in a non-curly-brace variable name, there is no ambiguity in the expression shown above. For expressions such as b10?b:a the ambiguity would be resolved according to the relative precedence of the ternary operator and the variable scope separator (`:'). I would assume that the precedence of the scope operator would be higher (since Vim treats it as part of 'variable', whose precedence is much higher than that of the ternary operator); hence, in the preceding example, the expression would be evaluated as (b10)?(b:a) which would indeed be a syntax error... Should eval_isnamec (or perhaps its caller) take into consideration the character index when deciding whether `:' is to be considered part of the variable name? The docs clearly state: You should always put a space before the ':', otherwise it can be mistaken for use in a variable such as a:1. In some cases var:10 can be recognized as not being a variable name, but this leads to undetected mistakes and makes it difficult to add more scopes later. It's a good habit to put spaces around ? and : anyway. Unless you never read back what you've written perhaps. -- hundred-and-one symptoms of being an internet addict: 182. You may not know what is happening in the world, but you know every bit of net-gossip there is. /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: Spurious undefined variable error generated for certain valid ternary expressions
- Original Message - From: Bram Moolenaar [EMAIL PROTECTED] To: Stahlman Family [EMAIL PROTECTED] Cc: vim@vim.org Sent: Wednesday, November 08, 2006 2:00 PM Subject: Re: Spurious undefined variable error generated for certain valid ternary expressions Brett Stahlman wrote: The following expression var10?var:10 generates the following errors: E121: Undefined variable: var:10 E15: Invalid expression: var10?var:10 The reason is that find_name_end uses eval_isnamec unconditionally to decide whether a character is a valid variable name character, with the result that `:' is always gobbled up as part of the variable name, even if it's not the second character in the name string (ie, even if it doesn't separate the scope prefix from the variable name). find_var_ht, on the other hand, will not permit a colon anywhere but at character index 1 in the variable name; hence, E121, and ultimately, E15. Since `:' is part of a valid VimL operator, and is not valid anywhere other than at index 1 in a non-curly-brace variable name, there is no ambiguity in the expression shown above. For expressions such as b10?b:a the ambiguity would be resolved according to the relative precedence of the ternary operator and the variable scope separator (`:'). I would assume that the precedence of the scope operator would be higher (since Vim treats it as part of 'variable', whose precedence is much higher than that of the ternary operator); hence, in the preceding example, the expression would be evaluated as (b10)?(b:a) which would indeed be a syntax error... Should eval_isnamec (or perhaps its caller) take into consideration the character index when deciding whether `:' is to be considered part of the variable name? The docs clearly state: You should always put a space before the ':', otherwise it can be mistaken for use in a variable such as a:1. Hmm. Ok. I didn't find that text with helpgrep, but I've got Vim7 beta version still on this computer. Perhaps it was added since then... Thanks, Brett S. In some cases var:10 can be recognized as not being a variable name, but this leads to undetected mistakes and makes it difficult to add more scopes later. It's a good habit to put spaces around ? and : anyway. Unless you never read back what you've written perhaps. -- hundred-and-one symptoms of being an internet addict: 182. You may not know what is happening in the world, but you know every bit of net-gossip there is. /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\download, build and distribute -- http://www.A-A-P.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org///
Re: Spurious undefined variable error generated for certain valid ternary expressions
Stahlman Family [EMAIL PROTECTED] 写于 2006-11-09 09:40:49: The docs clearly state: You should always put a space before the ':', otherwise it can be mistaken for use in a variable such as a:1. Hmm. Ok. I didn't find that text with helpgrep, but I've got Vim7 beta version still on this computer. Perhaps it was added since then... Thanks, Brett S. By the way, you should also know that you should never add a space before [ ]. the abc [1] works in Vim6, but in Vim 7 there should not be a space so there must be abc[1]. I don't know why there is such a requirement in Vim 7, but it breaks one of my script. -- Sincerely, Pan, Shi Zhu. ext: 2606
Spurious undefined variable error generated for certain valid ternary expressions
The following expression var10?var:10 generates the following errors: E121: Undefined variable: var:10 E15: Invalid expression: var10?var:10 The reason is that find_name_end uses eval_isnamec unconditionally to decide whether a character is a valid variable name character, with the result that `:' is always gobbled up as part of the variable name, even if it's not the second character in the name string (ie, even if it doesn't separate the scope prefix from the variable name). find_var_ht, on the other hand, will not permit a colon anywhere but at character index 1 in the variable name; hence, E121, and ultimately, E15. Since `:' is part of a valid VimL operator, and is not valid anywhere other than at index 1 in a non-curly-brace variable name, there is no ambiguity in the expression shown above. For expressions such as b10?b:a the ambiguity would be resolved according to the relative precedence of the ternary operator and the variable scope separator (`:'). I would assume that the precedence of the scope operator would be higher (since Vim treats it as part of 'variable', whose precedence is much higher than that of the ternary operator); hence, in the preceding example, the expression would be evaluated as (b10)?(b:a) which would indeed be a syntax error... Should eval_isnamec (or perhaps its caller) take into consideration the character index when deciding whether `:' is to be considered part of the variable name? Thanks, Brett Stahlman