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

Error on REPL with implicit parens #1420

Closed
TrevorBurnham opened this issue Jun 6, 2011 · 4 comments
Closed

Error on REPL with implicit parens #1420

TrevorBurnham opened this issue Jun 6, 2011 · 4 comments
Labels

Comments

@TrevorBurnham
Copy link
Collaborator

The code

a(b) -> c

is perfectly legit, equivalent to a(b)(-> c). But on the REPL, it fails with the message

Error: In repl, too many ) on line 2

(as of the current master; error message is on line 1 on 1.1.1). Note that this is the same error that was happening in #1398 with comments (since fixed by Michael).

To be clear,

func ->

works fine, but

func() ->

fails.

@michaelficarra
Copy link
Collaborator

It doesn't look like it's the REPL's fault: (fn() ->) fails to compile, but I see nothing wrong with it. Take away the trailing right-parenthesis and it still complains (as it should this time).

edit: It looks like pretty much everything that's similar but slightly different compiles fine. So it's a bug, but definitely not the REPL's fault.

@TrevorBurnham
Copy link
Collaborator Author

Ah, so the root cause of the problem is that

(fn() ->)

gives you an error. Gotcha.

Any idea how the unbalance is happening? These all work:

(fn() (->))
(fn() a, ->)

and this gets the same error:

(fn()->)

So the major commonality in all the error cases is that () immediately precedes ->. I'm guessing some part of the lexer is mistakenly seeing the () as an argument list.

@michaelficarra
Copy link
Collaborator

A little debugging output:

$;coffee -te "(fn() a)" (a normal token stream):

tokens: 
 [ [ '(', '(', 0 ],
  [ 'IDENTIFIER', 'fn', 0 ],
  [ 'CALL_START', '(', 0 ],
  [ 'CALL_END', ')', 0, spaced: true ],
  [ 'CALL_START', '(', 0 ],
  [ 'IDENTIFIER', 'a', 0 ],
  [ 'CALL_END', ')', 0 ],
  [ ')', ')', 0 ],
  [ 'TERMINATOR', '\n', 0 ] ]
pair counts: 
 { '(': 0,
  '[': 0,
  '{': 0,
  INDENT: 0,
  CALL_START: 0,
  PARAM_START: 0,
  INDEX_START: 0 }
[( (] [IDENTIFIER fn] [CALL_START (] [CALL_END )] [CALL_START (] [IDENTIFIER a] [CALL_END )] [) )] [TERMINATOR \n]

So everything gets paired up at the end (all the counts end at zero and never dip below zero).

$;coffee -te "(fn() ->)" (our errant case):

coffee -te "(fn() ->)"
tokens: 
 [ [ 'PARAM_START', '(', 0 ],
  [ 'IDENTIFIER', 'fn', 0 ],
  [ 'CALL_START', '(', 0 ],
  [ 'CALL_END', ')', 0, spaced: true ],
  [ 'CALL_START', '(', 0 ],
  [ '->', '->', 0 ],
  [ 'INDENT', 2, 0, generated: true ],
  [ 'OUTDENT', 2, 0, generated: true ],
  [ 'CALL_END', ')', 0 ],
  [ ')', ')', 0 ],
  [ 'TERMINATOR', '\n', 0 ] ]
pair counts: 
 { '(': -1,
  '[': 0,
  '{': 0,
  INDENT: 0,
  CALL_START: 0,
  PARAM_START: 1,
  INDEX_START: 0 }
Error: too many ) on line 1

Here, we see a PARAM_START as the first token (at the time of the ensureBalance rewriting phase) instead of (, so the final ) causes the ( count to dip below zero, triggering the error. Now we just need to see what's putting that PARAM_START token there... probably the lexer, since the rewriter hardly mentions it..

update: the problem is definitely in the lexer, most likely the tagParameters method.

@michaelficarra
Copy link
Collaborator

@TrevorBurnham: should be fixed by the above commit.

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

2 participants