Strange javascript Script errors

Next
 From:  bemfarmer
5772.1 
While working on a new script, I discovered that placing comments with the /* and */, before the instruction
#include "GetPoint.js" caused a syntax error: parse error.
So place the command near the beginning, before using /* comments */

Using // for comments did not create a problem.

Also, last month, I learned not to use javascript reserved words as variable names...
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
5772.2 In reply to 5772.1 
Hi Brian, the #include statement is not actually part of regular JavaScript, it's something that MoI itself expands in place by scanning through the script code, and MoI's scanner is not a full fledged parser that handles comment characters itself.

So because of that if you put something like

/*
#include xxxx
*/

the include will still expand in place since MoI's "include expander" still finds that one line that says #include, it doesn't handle the comments around it so it doesn't know that it's not supposed to be processed. When you put:

//#include xxxx

it should then stop that include expander / script preprocessor from finding it.

One of the sort of poorer areas of Javascript is that it doesn't natively handle things like including one file into another, so that's why Moi has a custom mechanism for it, and it's that custom mechanism that tripped you up in this case since the custom mechanism doesn't handle that kind of separate-line commenting out.

Hope that helps explain what you were seeing here.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
5772.3 In reply to 5772.2 
Thank you Michael. So much to learn :-)

Your response improved my understanding of the #include, and the unfinished script is responding properly now.

What did not work, when I wanted the #include to be operational, and generated the error, was:
/*
Miscellaneous comments
*/
#include "GetPoint.js"

What did work, with the desired #include operational, was:
#include "GetPoint.js"
/*
Miscellaneous comments
*/

EDITED: 17 Mar 2013 by BEMFARMER

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
5772.4 In reply to 5772.3 
Hi Brian,

> What did not work, when I wanted the #include to be operational, and generated the error, was:
> /*
> Miscellaneous comments
> */
> #include "GetPoint.js"


This is because the include expander stops looking for #includes after it thinks it has seen some actual script content - it knows to skip any whitespace lines or any lines starting with // but it doesn't know about /* */ comments and so it thinks those are the start of some actual script, sorry about the confusion there.

I'll add a note to myself to try and get the include expander to handle /* */ comments too, to avoid this confusion in the future.

Thanks, - Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All