Saturday, February 6, 2010

processing.js bug #284 and #226

I've been doing some Processing.js debugging and testing, for tickets #226 and now #284 because of the close relation.

Originally, I did some tests for removing the comment regex, and these were the results source code. The problem is with the comments, the parser is having problems as it's not expecting a comment. I believe parsing out the comments is the easiest solution.

Here is my solution to both tickets. souce and a test.

What I am doing is first, creating an array that contains all the strings.
Then, masking all the strings, this will also grab any strings inside a comment

// Saves all strings into an array
// masks all strings into <STRING n>
// to be replaced with the array strings later
var strings = aCode.match(/("|').*("|')/g);
for ( var i = 0; /("|').*("|')/.test(aCode); i++)
{
aCode = aCode.replace(/("|').*("|')/, "<STRING " + i + ">");
}

Then, I parse away all comments.

// Remove end-of-line comments
aCode = aCode.replace(/\/\/.*\n/g, "\n");

Any strings inside a comment do not matter, and any // inside a string have already been converted to .
I then replace all the strings as the final step.

// replaces all masked strings from <STRING n> to the appropriate string
if (strings != null){
for( var i = 0; l = i < strings.length; i++ ){
var ex = new RegExp("\<STRING " + i + "\>");
aCode = aCode.replace(ex, strings[i]);
}
}

any strings that were removed because of being in a comment, are not replaced, and the program simply skips it.

I'm ready to upload it, and hope I have not missed anything as it's my first time! *fingers crossed*

1 comment:

  1. Hi friends, its great post about cultureand completely explained,
    keep it up all the time.

    My webpage - http://paddolker.com

    ReplyDelete