Page 1 of 1 1
Topic Options
#142878 - 2005-07-04 11:00 AM Environment variable causes parser failure
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
In specific conditions the parser will fail when an environment variable is the first element of an expression.

Originally reported by John_c here: http://www.kixtart.org/ubbthreads/showfl...;gonew=1#UNREAD

This code:
Code:
"Version: " @KIX ?
"1 " "%WINDIR%" ?
"2 " (%WINDIR%) ?
"3 " CStr(%WINDIR%) ?
"4 " ""+%WINDIR% ?
"5 " %WINDIR% ?



Produces:
Code:
C:\Temp>kix32 err.kix
Version: 4.50
1 C:\Windows
2 C:\Windows
3 C:\Windows
4 C:\Windows
5
ERROR : unknown command [%WINDIR%]!
Script: C:\Temp\err.kix
Line : 6



It may also fail when the environment variable is the first part of an expression, such as:
Code:
%WINDIR%+"" ?


Top
#142879 - 2005-07-04 03:29 PM Re: Environement variable causes parser failure
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
AFAIK, KiX has always behaved this way. Why do you consider it an issue?

If wrapped in quotes it is well behaved.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142880 - 2005-07-04 03:42 PM Re: Environement variable causes parser failure
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I think 4.20 was out about the time I started using kixtart. I remember trying to convert one of my batch scripts and having trouble using the system variables without quotes. Since then, I've always assumed you had to use quotes. (which now is obviously not true) Anyway, if this is a bug, its been around a while.
Top
#142881 - 2005-07-04 03:48 PM Re: Environement variable causes parser failure
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the issue is that manual lets one think it's a variable that can used just like that.
and the examples show, it can be used anywhere as textstring, except in some odd places.

% is kixtart reserved character and so it should not say unknown command.
instead it should handle string inside %-marks as the text in normal kixtart variable, with the difference that it can't be set directly.

now... it might be that the current free usage of system vars as part of an expression is just a production of free format language parser
but that does not remove the fact that it's confusing.
_________________________
!

download KiXnet

Top
#142882 - 2005-07-04 04:09 PM Re: Environement variable causes parser failure
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Confusing, maybe... bug, questionable!

I would call it a "feature". The possibility exists that someone out there may have leveraged the "feature" and to change it would break it for them.

I suggest only some verbage in the manual.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142883 - 2005-07-04 04:15 PM Re: Environement variable causes parser failure
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, that's why it was called an issue, not bug
and, who would leverage a feature that does error out kixtart every time?
I mean, if the handling of the env vars is already there, why not fix it to work in all situations.
that would not break any scripts but it would save many from greef during n00b debugging hours.
_________________________
!

download KiXnet

Top
#142884 - 2005-07-04 04:20 PM Re: Environement variable causes parser failure
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

AFAIK, KiX has always behaved this way. Why do you consider it an issue?

If wrapped in quotes it is well behaved.




Well, you should reasonably expect to be able to use an environment variable in exactly the same way that you would a KiXtart variable or macro (notwithstanding the fact that it is read only)

I don't believe that the current action is intentional which is why I've highlighted it here.

Top
#142885 - 2005-07-04 08:11 PM Re: Environement variable causes parser failure
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Quote:


Well, you should reasonably expect to be able to use an environment variable in exactly the same way that you would a KiXtart variable or macro




No, it is not, IMHO. One indication would be that there is the EXPANDENVIRONMENTVARS() function, which would be mostly superfluous then. also, nowhere in the KiXtart Manual is mentioned that one can use environment variables just like KiXtart variables or macros.
_________________________
There are two types of vessels, submarines and targets.

Top
#142886 - 2005-07-05 09:28 AM Re: Environement variable causes parser failure
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

No, it is not, IMHO. One indication would be that there is the EXPANDENVIRONMENTVARS() function, which would be mostly superfluous then.




Not at all.

The primary purpose of ExpandEnvironmentVars() is used to expand environment variables when they are already in strings. A good example (and I'd guess what ExpandEnvironmentVars was originally coded for) is when they are read from the registry. The only other easy way to do this is to use Execute(), which hasn't always been available in KiXtart.

Quote:

also, nowhere in the KiXtart Manual is mentioned that one can use environment variables just like KiXtart variables or macros.




No, nor does it mention that you cannot A reasonable assumption unless you're told otherwise would be that an environment variable can be used wherever a KiXtart variable can.


Consider the examples. Why does this code work:
Code:
(%VARIABLE%) ?


But this code causes the parser to fail:
Code:
%VARIABLE% ?



The parentheses are redundant so it's not affecting the script process at all. It's a parser failure, not a code failure.

You can turn the argument on it's head of course and ask yourself if it is reasonable for the parser to fail in this way. If you think that it is, what are the reasons that this is a good thing? Do you think that this action should be preserved?

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.058 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.