Skip to content

Commit

Permalink
fix gkz#844 by backporting satyr/coco@45d3ea36
Browse files Browse the repository at this point in the history
  • Loading branch information
summivox committed Feb 7, 2016
1 parent 2c69167 commit 7ec8c5c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lexer.ls
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ exports <<<
if t.0 is 'TOKENS'
tokens.push ...t.1
else
val = t.1.replace HEREGEX_OMIT, ''
val = deheregex t.1
continue if one and not val
one = tokens.push t <<< ['STRNUM' @string '\'' enslash val]
tokens.push ['+-' '+' tokens[*-1].2, tokens[*-1].3]
Expand All @@ -415,7 +415,7 @@ exports <<<
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
@regex reslash(deheregex parts.0.1), flag
parts.size + flag.length

# Matches a word literal, or ignores a sequence of whitespaces.
Expand Down Expand Up @@ -944,6 +944,12 @@ reslash = (.replace /(\\.)|\//g -> &1 or \\\/)
# Transforms hyphenated-words to camelCase.
camelize = (.replace /-[a-z]/ig -> it.char-at 1 .to-upper-case!)

# ESifies a heregex.
deheregex = (.replace do
/\s+(?:#.*)?|(\\[\s\S])/g
(, bs || '') -> if \\n is bs.charAt 1 then \\\n else bs
)

# Deletes the first character if newline.
function lchomp then it.slice 1 + it.last-index-of '\n' 0

Expand Down
7 changes: 7 additions & 0 deletions test/regex.ls
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ eq '\\\\#{}\\\\\\\"', //
\\ \"
//.source

# [coffee#3059](https://github.com/jashkenas/coffee-script/pull/3059)
# Keep escaped whitespaces.
ok //^
a \ b \ c \
d
$//test 'a b\u3000c\nd'

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

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

0 comments on commit 7ec8c5c

Please sign in to comment.