Brett Stahlman wrote:

> The following expression
> 
>     var>10?var:10
> 
> generates the following errors:
> 
>     E121: Undefined variable: var:10
>     E15: Invalid expression: var>10?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
> 
> b>10?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
> 
> (b>10)    ?    (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    ///

Reply via email to