mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
heregex: now allows bare slashes and empty body
This commit is contained in:
@@ -205,11 +205,12 @@
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
Lexer.prototype.heregexToken = function(match) {
|
Lexer.prototype.heregexToken = function(match) {
|
||||||
var _ref2, body, flags, heregex;
|
var _ref2, body, flags, heregex, re;
|
||||||
_ref2 = match, heregex = _ref2[0], body = _ref2[1], flags = _ref2[2];
|
_ref2 = match, heregex = _ref2[0], body = _ref2[1], flags = _ref2[2];
|
||||||
this.i += heregex.length;
|
this.i += heregex.length;
|
||||||
if (!(~body.indexOf('#{'))) {
|
if (!(~body.indexOf('#{'))) {
|
||||||
this.token('REGEX', '/' + body.replace(HEREGEX_OMIT, '') + '/' + flags);
|
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
|
||||||
|
this.token('REGEX', "/" + (re || '(?:)') + "/" + (flags));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
this.token('IDENTIFIER', 'RegExp');
|
this.token('IDENTIFIER', 'RegExp');
|
||||||
|
|||||||
@@ -198,7 +198,8 @@ exports.Lexer = class Lexer
|
|||||||
[heregex, body, flags] = match
|
[heregex, body, flags] = match
|
||||||
@i += heregex.length
|
@i += heregex.length
|
||||||
unless ~body.indexOf '#{'
|
unless ~body.indexOf '#{'
|
||||||
@token 'REGEX', '/' + body.replace(HEREGEX_OMIT, '') + '/' + flags
|
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/')
|
||||||
|
@token 'REGEX', "/#{ re or '(?:)' }/#{flags}"
|
||||||
return true
|
return true
|
||||||
@token 'IDENTIFIER', 'RegExp'
|
@token 'IDENTIFIER', 'RegExp'
|
||||||
@tokens.push ['CALL_START', '(']
|
@tokens.push ['CALL_START', '(']
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ ok ' '.match regexp
|
|||||||
|
|
||||||
ok (obj.width()/id - obj.height()/id) is -5
|
ok (obj.width()/id - obj.height()/id) is -5
|
||||||
|
|
||||||
eq /^I'm\s+Heregex?/gim + '', ///
|
eq /^I'm\s+Heregex?\/\/\//gim + '', ///
|
||||||
^ I'm \s+ Heregex? # or not
|
^ I'm \s+ Heregex? / // # or not
|
||||||
///gim + ''
|
///gim + ''
|
||||||
eq '\\\\#{}', ///
|
eq '\\\\#{}', ///
|
||||||
#{
|
#{
|
||||||
@@ -36,3 +36,4 @@ eq '\\\\#{}', ///
|
|||||||
}
|
}
|
||||||
\#{}
|
\#{}
|
||||||
///.source
|
///.source
|
||||||
|
eq /// /// + '', '/(?:)/'
|
||||||
|
|||||||
Reference in New Issue
Block a user