Skip to content

Instantly share code, notes, and snippets.

@g-k
Last active October 12, 2015 07:18
Show Gist options
  • Save g-k/3990593 to your computer and use it in GitHub Desktop.
Save g-k/3990593 to your computer and use it in GitHub Desktop.
Coffeescript - Unexpected MATH

Trying to test for spaces in a string using a regex. Ran into unexpected math in an if block. Nice to see that the coffeescript lexer is annotated though: http://coffeescript.org/documentation/docs/lexer.html#section-14

» coffee --version
CoffeeScript version 1.4.0
» coffee
coffee> / /
Error: In repl, Parse error on line 1: Unexpected 'MATH'
    at Object.parseError (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:477:11)
    at Object.parse (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/parser.js:554:22)
    at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:47:20
    at Object.eval (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:144:10)
    at Interface.<anonymous> (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/repl.js:145:40)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)
    at Interface._line (readline.js:426:8)
    at Interface._ttyWrite (readline.js:603:14)
    at ReadStream.<anonymous> (readline.js:82:12)
coffee> /[ ]/ # workaround
/[ ]/
» node
> / /
/ /

Apparently, / can mean divides (Unexpected MATH) or the beginning of a regular expression. See How to read macros.

@levelone
Copy link

/[ ]/ worked for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment