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

Lexer: a = ; 5: Suppressed newline should be unsuppressed by semicolon #3098

Closed
vendethiel opened this issue Jul 30, 2013 · 11 comments
Closed
Labels

Comments

@vendethiel
Copy link
Collaborator

(from #3053)

# rule : 
'Assignable = TERMINATOR Expression'
# supposedly allowing that :
a =
5
# but also allows this
a = ; 5
@marchaefner
Copy link
Collaborator

That one is fun. (This is a function: f = (a; b; c) ->)

We could remove TERMINATOR tokens (if they're not semicolons) after = and COMPOUND_ASSIGN in the rewriter (and save two rules in the parser). For commas (as in the arglist above) it's a bit more complicated though.

@jashkenas
Copy link
Owner

Right, the other 'correct' way to fix this would be to treat = like other 'unfinished' bits, and have it suppress the newline, but I bet that'll cause more problems than it fixes.

@vendethiel
Copy link
Collaborator Author

This is a function: f = (a; b; c) ->

I guess it's to allow a = (x; y = f z) -> x

@marchaefner
Copy link
Collaborator

@Nami-Doc: Ha, very nice. It's actually useful. (We don't need no stinking parens! ;)

I think we should keep those OptComma TERMINATOR cases, they seem way too hard to fix anyway. (I really doubt this behavior is intended.)

@jashkenas: Better not. The (premature) "unfinished" bits don't not play nice with the rewriter (e.g. #3199).

@erisdev
Copy link

erisdev commented Nov 11, 2013

Haha, yeah no, suppressing newlines after = would break implicit object literals, wouldn't it?

@marchaefner
Copy link
Collaborator

@erisdiscord: Yes, but only in single-liners (IIRC), e.g.

  if c then x =
    a:b
    c:d

@erisdev
Copy link

erisdev commented Nov 12, 2013

@marchaefner would it not also break them in this case? or would the indentation be sufficient?

someNumbers =
  arbitraryNumber: 37
  randomNumber: Math.random()

@marchaefner
Copy link
Collaborator

@erisdiscord: The unfinished logic (plus the corresponding indebt "magic") also removes the indentation. normalizeLines (where single-liners are handled) subsequently adds indentation until it encounters a TERMINATOR, effectively splitting the object. (Plug: coffee-tap let's you look at the the un-rewritten token stream.)

@jashkenas
Copy link
Owner

Plug: coffee-tap let's you look at the the un-rewritten token stream.)

As does the helpful comment at the top of the rewriter file. You can drop that sucker in at any stage of the rewriter's passes, to see how well things are moving along.

@GeoffreyBooth GeoffreyBooth changed the title disallow a = ; 5 Lexer: a = ; 5: Suppressed newline should be unsuppressed by semicolon May 6, 2017
@GeoffreyBooth
Copy link
Collaborator

I’m assuming the solution for this is to have the semicolon “un-suppress” the newline that gets suppressed by the open =.

@GeoffreyBooth
Copy link
Collaborator

Fixed via #4669.

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

5 participants