Hi all
Check this out:
http://www.thespanner.co.uk/2012/11/07/sandboxing-and-parsing-jquery-in-100ms/
I have written a complete parser/sandbox based on tracking opening and
closing characters (I will be writing a paper on this in more detail) it
works by using the opening and closing states to store the current state.
For example:
o={
};
Here my parser looks at the state before "{" and labels it as a object
literal. I track that state and when a "}" is encountered I can use the
balanced nature of javascript to my advantage by looking up the current
count of characters which allows me to identify that "}" is in fact a
closing object literal. It isn't that simple I here you say and there are
complicated cases such as:
var xyz, xyz
{}
Here my parser takes an additional step using the characters it tracks such
as "{" and "(" etc I can use that to uniquely identify the var statement
context by using indexes of these characters to know the comma is in fact
part of a var statement. Lets look at another example and I'll illustrate
with comments how the tracking works.
//C = curly
//P = Paren
//C 1
{
function x
//P1
()
//P0
{//C2
var x, y // C2 + P0 = Var statement
//C3
{
}//C2
; // C2 + P0 = '';
}//C1
}//C0
By using these reference points no matter how many nested expressions you
have you can still know the statement it's part of or the character should
be a particular state. Please let me know your comments and I'll post the
paper when it's done.
Cheers
Gareth
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss