Forwards-compatible syntax proposal
Ian Hickson
ian at hixie.ch
Thu May 8 20:18:08 PDT 2008
One of the problems with ES4 relative to ES3 is that the new syntax means
that a script using ES4 features doesn't work in ES3 compilers.
There's not much we can do in the ES3-ES4 language migration about this.
But we _can_ prevent this problem from existing again in ES5 and up.
I propose that ES4 clients, when they hit a syntax error, back up to the
start of the current block, and then look for the end of the block, which
is the "}" corresponding to the last token in this grammar:
block = "{" tokens* "}"
tokens = block | string | comment | regexp | other
string = single-quote [ no-backslash | escape ]* [ single-quote | end of line ]
string = double-quote [ no-backslash | escape ]* [ double-quote | end of line ]
string = (triple-quoted string)
no-backslash = anything but "\"
escape = "\" followed by anything
comment = "/*" ... "*/"
comment = "//" ... end of line
comment = "<!--" ... end of line
regexp = "/" [ no-backslash | escape ]* [ "/" | end of line ]
other = anything else
...and then compile the whole block to one "throw SyntaxError" statement.
I may have missed some things we should include, and the grammar above may
be too simple and may have to have changes made, but hopefully it conveys
the basic idea.
Comments?
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the Es4-discuss
mailing list