Skip to content

Commit

Permalink
allowed triple-or-more-slash as heregex delimiter; closes satyr#219
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Apr 26, 2013
1 parent 9d51d65 commit cb8c732
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,11 @@ exports.doRegex = function(code, index){
return input.length;
};
exports.doHeregex = function(code, index){
var tokens, last, parts, rest, flag, i, t, dynaflag, len$, val, one;
var tokens, last, delim, ref$, parts, rest, flag, i, t, dynaflag, len$, val, one;
tokens = this.tokens, last = this.last;
parts = this.interpolate(code, index, '//');
rest = code.slice(index + 2 + parts.size);
delim = (ref$ = /\/*/g, ref$.lastIndex = index, ref$).exec(code)[0];
parts = this.interpolate(code, index, delim);
rest = code.slice(index + delim.length + parts.size);
flag = this.validate(/^(?:[gimy]{1,4}|[?$]?)/.exec(rest)[0]);
if (parts[1]) {
if (flag === '$') {
Expand Down Expand Up @@ -444,7 +445,7 @@ exports.doHeregex = function(code, index){
} else {
this.regex(reslash(parts[0][1].replace(HEREGEX_OMIT, '')), flag);
}
return 2 + parts.size + flag.length;
return delim.length + parts.size + flag.length;
};
exports.doBackslash = function(code, lastIndex){
var ref$, input, word;
Expand Down
7 changes: 4 additions & 3 deletions src/lexer.co
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ exports import
# Matches a multiline, extended regex literal.
doHeregex: (code, index) ->
{tokens, last} = this
parts = @interpolate code, index, \//
rest = code.slice index + 2 + parts.size
delim = (/\/*/g <<< lastIndex: index)exec(code)0
parts = @interpolate code, index, delim
rest = code.slice index + delim.length + parts.size
flag = @validate /^(?:[gimy]{1,4}|[?$]?)/exec(rest)0
if parts.1
if flag is \$
Expand All @@ -319,7 +320,7 @@ exports import
if dynaflag then tokens.push ...dynaflag else @token \STRNUM "'#flag'"
@token (if flag is \$ then \) else \)CALL), ''
else @regex reslash(parts.0.1.replace HEREGEX_OMIT, ''), flag
2 + parts.size + flag.length
delim.length + parts.size + flag.length

# Matches a word literal, or ignores a sequence of whitespaces.
doBackslash: (code, BSTOKEN.lastIndex) ->
Expand Down
10 changes: 9 additions & 1 deletion test/regex.co
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ eq '\\\\#{}\\\\\\\"', //
\\ \"
//.source

eq '(?:)' ////source
eq '(?:)' // //source

eq // _ #{if 1 then \g else \m}//? + '', '/_/g'

Expand Down Expand Up @@ -90,3 +90,11 @@ eq \string typeof //^#{''}$//$
eq /\\\//$ /\\\//source
eq //\\\///$ //\\\///source
eq //#{\\}\///$ //#{\\}\///source


### Triple-or-more-slash as delimeter
ok ///
^ https?:// \w+ \. \w+
///test 'https://github.com'

ok /////(?:////){7}/////test \/ * 42

0 comments on commit cb8c732

Please sign in to comment.