puffnfresh / roy

Small functional language that compiles to JavaScript.
http://roy.brianmckenna.org/
MIT License
834 stars 74 forks source link

Issue using operators on plain old JS method invocations #159

Open dbousamra opened 11 years ago

dbousamra commented 11 years ago

My apologies on the tittle - I struggled to come up with a useful description.

Take this code:

roy> let a = 10
roy> let c = 9

If one tries to perform the following:

roy> a - Math.sqrt(c)

the compiler errors with:

Error: Parse error on line 1: Unexpected '('
    at Object.parseError (/Users/domlebo70/Documents/workspace/Roy/roy/lib/parser.js:335:11)
    at Object.parse (/Users/domlebo70/Documents/workspace/Roy/roy/lib/parser.js:411:22)
    at Interface.nodeRepl (/Users/domlebo70/Documents/workspace/Roy/roy/src/compile.js:619:30)
    at Interface.EventEmitter.emit (events.js:96:17)
    at Interface._onLine (readline.js:200:10)
    at Interface._line (readline.js:518:8)
    at Interface._ttyWrite (readline.js:736:14)
    at ReadStream.onkeypress (readline.js:97:10)
    at ReadStream.EventEmitter.emit (events.js:126:20)
    at emitKey (readline.js:1058:12)

No combination of bracket placement seems to get around it.

puffnfresh commented 11 years ago

The deep issue is that it looks like operator parsing is a bit broken.

But anyway, function application doesn't need parentheses. You want to use a - (Math.sqrt c).

dbousamra commented 11 years ago

Ah cheers.

rtfeldman commented 10 years ago

To confirm, is a - Math.sqrt(c) supposed to be valid, except the parser is rejecting it? Or is only a - (Math.sqrt c) intended to be allowed?