Page 3 of 4

Re: Strict Syntax Checking for Scripts

Posted: 05 May 2015 16:15
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.

Re: Strict Syntax Checking for Scripts

Posted: 05 May 2015 16:31
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.

Re: Strict Syntax Checking for Scripts

Posted: 05 May 2015 16:36
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

Re: Strict Syntax Checking for Scripts

Posted: 05 May 2015 16:40
by bdeshi
or

Code: Select all

$a = 'string'; text eval('''$a'''); text eval("""$a"""); //although this is pointless

Re: Strict Syntax Checking for Scripts

Posted: 05 May 2015 23:07
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);

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 07:56
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
...
?

Re: Call to undefined function: cbtstate

Posted: 06 May 2015 09:09
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:

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 10:00
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() ).

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 10:09
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?

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 11:05
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.

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 11:41
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.

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 15:22
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); 

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 15:48
by admin
1) quoting helps:

Code: Select all

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

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 15:56
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.

Re: Strict Syntax Checking for Scripts

Posted: 06 May 2015 16:03
by admin
Sorry, I cannot spend more time remote-fixing any crazy anarcho scripts. It's your choice. :cup: