Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex literals with leading spaces #874

Closed
tobyh opened this issue Nov 26, 2010 · 7 comments
Closed

Regex literals with leading spaces #874

tobyh opened this issue Nov 26, 2010 · 7 comments
Labels

Comments

@tobyh
Copy link

tobyh commented Nov 26, 2010

I think this bug was introduced in 0.95

$ coffee -bpe "r = / x/"
Error: Parse error on line 1: Unexpected 'MATH'
@tobyh
Copy link
Author

tobyh commented Nov 26, 2010

This has come up previously. Is it a regression, or a reversion to the old syntax rule, or am I imagining that this worked in 0.94?

@StanAngeloff
Copy link
Contributor

Bisecting seems to think cdd033ffb0b88eb6f00e is the first bad commit:

(stan) [coffee-script] % git checkout ^cdd033ffb0b88eb6f00e
(stan) [coffee-script] % bin/coffee -ep 'r = / x/'
(function() {
  var r;
  r = / x/;
}).call(this);
(stan) [coffee-script] % git checkout cdd033ffb0b88eb6f00e
Previous HEAD position was 493fa7d... heregex: now allows bare slashes and empty body
HEAD is now at cdd033f... disabled interpolations in normal regexes
(stan) [coffee-script] % bin/coffee -ep 'r = / x/'
Error: In console, Parse error on line 1: Unexpected 'MATH'
    at Object.parseError (/cygdrive/d/Workspace/public/coffee-script/lib/parser.js:513:11)
    at Object.parse (/cygdrive/d/Workspace/public/coffee-script/lib/parser.js:585:32)
    at Object.compile (/cygdrive/d/Workspace/public/coffee-script/lib/coffee-script.js:22:22)
    at /cygdrive/d/Workspace/public/coffee-script/lib/command.js:116:33
    at Object.run (/cygdrive/d/Workspace/public/coffee-script/lib/command.js:33:14)
    at Object.<anonymous> (/cygdrive/d/Workspace/public/coffee-script/bin/coffee:8:27)
    at Module._compile (node.js:462:23)
    at Module._loadScriptSync (node.js:469:10)
    at Module.loadSync (node.js:338:12)
    at Object.runMain (node.js:522:24)

Looking at the commit contents it was intended. However, it seems like hereregexes strip leading whitespace so /// x/// is not an option either. Anyone with a link to the discussion that axed this?

@satyr
Copy link
Collaborator

satyr commented Nov 26, 2010

This was killed because of inconsistency wrt parenless calls.
r = / x/ # worked
fun / x/ # worked not

Here are some workarounds for the case:

  • /\ x/
  • /// \x20 x ///

@tobyh
Copy link
Author

tobyh commented Nov 26, 2010

I think this might be a case where the less consistent behaviour was also less likely to cause surprises, but the change is understandable. Thanks for the answer.

@akidee
Copy link

akidee commented Nov 27, 2010

fun / x/  # worked not

So CS interpreted "/" as function name here?

@satyr
Copy link
Collaborator

satyr commented Nov 27, 2010

"/" as function name here?

A division operator, rather.

@akidee
Copy link

akidee commented Nov 27, 2010

Should be added to the doc.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants