Forwards-compatible syntax proposal
Waldemar Horwat
waldemar at google.com
Tue May 13 11:42:05 PDT 2008
This wouldn't work. Without syntactically distinguishing a / that is a division from a / that starts a regexp, there is no way to find the end of the block. To make this distinction you need to be able to parse the contents of the block without errors.
To complicate matters further, various language extension proposals, ranging from ES3.1 to various ES4 extensions, muck with the regexp syntax.
Waldemar
Ian Hickson wrote:
> 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?
>
More information about the Es4-discuss
mailing list