Strict Syntax Checking for Scripts

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

SammaySarkar wrote:

Code: Select all

$a = 'string'; eval($a);
But to me it seems eval() has complete disregard for any kind of quotes... :?
1) Hmm, tricky. Cannot fix that one. But I mean, eval($a) is a nonsense line so it is fair to call it dubious. :)

2) disregard of quotes? No, there are no quotes to regard in your code. $a is set to "string" (*without* the quotes), then "string" (*without* the quotes) is passed to eval.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

Okay.

2) don't worry, it was a lighthearted comment. :kidding:
The confusion stem from code like this: eval('$a'); it looks like $a is going to be passed as a literal string, but it's still evalled.
And you have to double-escape quotes inside eval() : eval("""<xypath>""")

This used to trouble me in the eearly days.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

Just in case anybody is wondering, here is a usage of eval($a) that will not be regarded as "dubious":

Code: Select all

$b = 6;
  $a = '$b';
  echo eval($a);  //6

  $a = '$b + $b';
  echo eval($a);  //12

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

or

Code: Select all

$a = 'string'; text eval('''$a'''); text eval("""$a"""); //although this is pointless
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Strict Syntax Checking for Scripts

Post by PeterH »

TheQwerty wrote:
PeterH wrote:Here I would love "Setting Strict, 0" to switch it off for part of this script!

Code: Select all

$a = '$i';
 *$a++;
 $tsss = tweak('ScriptStrictSyntax', 0);
 *$a++;
 tweak('ScriptStrictSyntax', $tsss);
 *$a++;
Doku of tweak() says:
... The change is effective immediately.

I say:
I didn't know this!

:oops: Sorry for not knowing, :oops: and sorry for crying :oops:
:mrgreen: Maybe my neighbours will ring a bell soon :mrgreen:

Text StrRepeat("Remember!<crlf>", 12);

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

The Strict Syntax Checking for Scripts seems to be a useful thing. I want to add it to the Scripting menu. Do have suggestions for the name of this toggle?

- Syntax Validation
- Syntax Checking
- Strict Syntax Checking
- Dubious Syntax Warning
- Strict Mode
...
?

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Call to undefined function: cbtstate

Post by admin »

SammaySarkar wrote:Don't hate the idea of stopping and broadcasting my mistakes at every other line, but I'd love to skip over all the warnings (when I'm sure the mistakes won't kill the script) by CTRL+continue, just like in stepmode.
Coming next version. :tup:

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

Thank you! :tup:

I pick Syntax Checking from your options. Another Suggestion : Bad Syntax Warning/Syntax Warning.


After this setting is upgraded to GUI level, please bind it to SC setting/settingp. ( it will probably be disengaged from tweak() ).
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

admin wrote:
SammaySarkar wrote:

Code: Select all

$a = 'string'; eval($a);
But to me it seems eval() has complete disregard for any kind of quotes... :?
1) Hmm, tricky. Cannot fix that one. But I mean, eval($a) is a nonsense line so it is fair to call it dubious. :)
should a variable passed inside eval() be auto-double-quoted? variables are auto-quoted/quote-escaped as needed elsewhere, but since eval() requires extra set of quotes, shouldn't this also be handled automatically?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Strict Syntax Checking for Scripts

Post by PeterH »

@Don: I think the sense of it is "Syntax Error Reporting". But don't know if that's a good caption.
(I think syntax always is checked - the difference is how to react on errors?)

@Sammay: I don't exactly understand - so just a try:

The quotes we seem to be talking about are nothing for inside the contents of the variables. They are just for the scripting interpreter to know what a string is, and to put the string (without the quotes) into the variable. So, on this level, double and single quoting is exact identical.

I could write on, but as I don't know if I'm getting your point it doesn't make sense, I think.

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

I'm fine with "Syntax Checking".

You have a non-weird use of Eval() where any quotes should be added? I doubt it.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

admin wrote:You have a non-weird use of Eval() where any quotes should be added? I doubt it.
Oh sure, found 35 cases where eval() usage will cause syntax hiccups.
Here's one example:

Code: Select all

 $varBaseName_1 = 'value1'; $DynamicPart = '1';
 eval($varBaseName_$DynamicPart);
most cases have similar eval() usage, used to build and obtain a dynamic variable value.

btw, about that auto-quoting: if this is introduced, maybe it should be restricted to in places like this where running-as-is will cause fatal abortion.

Code: Select all

 $d = <xypath>; eval($d); 
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

1) quoting helps:

Code: Select all

$varBaseName_1 = 'value1'; $DynamicPart = '1';
  echo eval("$varBaseName_$DynamicPart");
2) nonsense script. Punishment okay. :)

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Strict Syntax Checking for Scripts

Post by bdeshi »

Alright. Guess new scripts will have those quotes from now on. :wink:




Here' another bother. I know this is bad form, but it works (whose fault is that? :P )

Code: Select all

 text "text text.
  more text"; echo "I'm a-okay!"; //cmt
Either outlaw this crazy syntax, or hide the "'//cmt' is not a valid command" error.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 66323
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Strict Syntax Checking for Scripts

Post by admin »

Sorry, I cannot spend more time remote-fixing any crazy anarcho scripts. It's your choice. :cup:

Post Reply