At the beginning of the parsing, I run this block of code
var strings = aCode.match(/".*"/g);
for ( var i = 0; /".*"/.test(aCode); i++)
{
aCode = aCode.replace(/".*"/, "<STRING " + i + ">");
}
This, first, goes through all the code, and grabs all strings, and saves them in an array. Then, I loop through the code, applying
Then, at the end of the code, after all other parsing has been done, before I return aCode, I reapply all the strings like this
for( var i = 0; l = i < strings.length; i++ ){
var ex = new RegExp("\<STRING " + i + "\>");
aCode = aCode.replace(ex, strings[i]);
}
This goes through the array of strings, one at a time, until they have all been gone through, each time, applying that string to the proper
I believe this is pretty solid and can be demonstrated here. You should see three alert boxes, displaying messages that would normally be parsed out, then the usual black box of success. Also notice how I put a string inside the comment, to make sure it was able to handle that, as I parse the string before I parse a comment, as to avoid removing some string that happens to contain // in it. I also tested a multi line string, as I was curious, it handles it fine just so long as it's not written like this.
alert("first line
second line");
which to my knowledge, should not work anyway, plus, it's horrible code!
I think I'm done this bug, and I think the next step is to figure out how to submit my code...
Scott, could you please explain how this piece of code:
ReplyDeletevar ex = new RegExp("\");
aCode = aCode.replace(ex, strings[i]);
works.
If you substituted all the strings with "" (which is 2 quotes or an empty string?), then how are you looking for the position, where you want to put the initial string back?
Thanks!
Ah, this is embarrassing. I first thought I copied and pasted it wrong, but it seems to be blogspot simply parsing it, in it's own little way. I'll edit the main post now.
ReplyDeleteFixed, and, thank you.
ReplyDelete