Author Topic: Detecting a Syntax Error  (Read 960 times)

Simple question,
How do I check if a file being executed has a syntax error.

It'll explicitly state in the console that the file was not executed because there were syntax error(s).

and it won't state if there is more than one error.

If you want to do it by code you can do the following:
function fileHasError(%x) {
   %f = new FileObject();
   %f.openForRead(%x);
   while(!%f.isEOF())
      %lines = %lines NL %f.readLine();
   %f.close();
   %f.delete();

   eval(%lines NL "%assmonkeypoundervaginarandomtext=2331;");
   if(%assmonkeypoundervaginarandomtext != 2331)
      return false;
   return true;
}


please note the file will be executed.

function fileHasError(%file){return !compile(%file);}

?

function fileHasError(%file){return !compile(%file);}

?
lol, wow

If you want to do it by code you can do the following:
function fileHasError(%x) {
   %f = new FileObject();
   %f.openForRead(%x);
   while(!%f.isEOF())
      %lines = %lines NL %f.readLine();
   %f.close();
   %f.delete();

   eval(%lines NL "%assmonkeypoundervaginarandomtext=2331;");
   if(%assmonkeypoundervaginarandomtext != 2331)
      return false;
   return true;
}


please note the file will be executed.

This guy knows what I meant.
 :cookieMonster: To you!

function fileHasError(%file){return !compile(%file);}

?
Disregard previous post this works better! Thanks Zeblote!

Unlocked due to several messages requesting that I leave them open

Unlocked due to several messages requesting that I leave them open
Why are you cross-posting this

exec returns false if the script has errors i'm p sure

maybe my tests were rong

exec returns false if the script has errors i'm p sure

maybe my tests were rong
Yes, and you could also do what Zeblote put

exec returns false if the script has errors i'm p sure

maybe my tests were rong
exec also executes the script which you might not want to do when just checking for errors

exec also executes the script which you might not want to do when just checking for errors
yeah you're right

op did state that the script was being executed though