-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves RegExp literal lexing. (Fixes #7)
- Whitespace within the regexp is now allowed. - Escaped forward slashes (/) are now allowed. - Use the previous token to decide between a division and a RegExp literal. This reasoning works in the majority of cases but there are exceptions that will need a revisit (e.g. ++). - Can now parse underscore.js and the test262 harness without errors.
- Loading branch information
1 parent
a652cf5
commit 0032adf
Showing
2 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// test_regexp.js | ||
// -------------- | ||
// Verify that these RegExp literals can all be parsed. | ||
|
||
/*this comment shouldn't cause problems*/ | ||
/*orthisone/ */ | ||
|
||
var re; | ||
|
||
re = /abc/; | ||
re = / abc /; | ||
re = /\/abc/; | ||
re = /\\/.exec("/"); | ||
re = /ab\/c/; | ||
re = /a{1,3}/; | ||
re = /\\\\/; | ||
re = /abc/igm; | ||
re = /\\/g; | ||
re = /^0/; | ||
re = /(.)^/i; | ||
re = /./g; | ||
re = /x(?:...|(...))\1x/i; | ||
re = /\\|'|\r|\n|\t|\u2028|\u2029/g; | ||
re = /<%([\s\S]+?)%>/g; | ||
re = /\(\d{2}.\w{3}.\d{4}\)[\s\-.,]{0,3}\b\w+\b/i; | ||
re = /^(.+?)(\d+)\.(\S+)$/; | ||
|
||
if (true) /regex/.exec('regex'); | ||
|
||
// Division should not be confused with a RegExp literal. | ||
var x = 12 / 3 / 2; | ||
console.assert(x === 2); | ||
|
||
var a = 12, b = 2; | ||
a++ / b; | ||
|
||
// FIXME: This final example doesn't work because when the preceding token is a | ||
// ++, we assume that it is a division, but it could be either. | ||
// | ||
// ++/foo/.abc; |