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?

Thanks,
   Brett Stahlman


Reply via email to