Skip to content

Commit

Permalink
fixed #1102; lexer: cleaned up unfinished
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Sep 6, 2011
1 parent 036fc56 commit 2ea51b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
8 changes: 3 additions & 5 deletions lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ exports.Lexer = class Lexer
# Are we in the midst of an unfinished expression?
unfinished: ->
LINE_CONTINUER.test(@chunk) or
(prev = last @tokens, 1) and prev[0] isnt '.' and
(value = @value()) and not value.reserved and
NO_NEWLINE.test(value) and not CODE.test(value) and not ASSIGNED.test(@chunk)
@tag() in ['\\', '.', '?.', 'UNARY', 'MATH', '+', '-', 'SHIFT', 'RELATION'
'COMPARE', 'LOGIC', 'COMPOUND_ASSIGN', 'THROW', 'EXTENDS']

# Converts newlines for string literals.
escapeLines: (str, heredoc) ->
Expand Down Expand Up @@ -610,18 +609,10 @@ HEREDOC_INDENT = /\n+([^\n\S]*)/g

HEREDOC_ILLEGAL = /\*\//

ASSIGNED = /^\s*@?([$A-Za-z_][$\w\x7f-\uffff]*|['"].*['"])[^\n\S]*?[:=][^:=>]/

LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?![.\d]) | :: ) ///

TRAILING_SPACES = /\s+$/

NO_NEWLINE = /// ^ (?: # non-capturing group
[-+*&|/%=<>!.\\][<>=&|]* | # symbol operators
and | or | is(?:nt)? | n(?:ot|ew) | # word operators
delete | typeof | instanceof
) $ ///

# Compound assignment tokens.
COMPOUND_ASSIGN = [
'-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='
Expand Down
4 changes: 4 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,7 @@ test "#1234: Applying a splat to :: applies the splat to the wrong object", ->

arr = []
eq nonce, C::method arr... # should be applied to `C::`

test "#1102: String literal prevents line continuation", ->
eq "': '", '' +
"': '"

4 comments on commit 2ea51b0

@jashkenas
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- should we pull that array of token tags out alongside the others at the bottom of the file?

@michaelficarra
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say so.

@satyr
Copy link
Collaborator Author

@satyr satyr commented on 2ea51b0 Sep 6, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like? I don't feel the need for that (unless the tag list is used elsewhere); it's optimized this way.

@jashkenas
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. Tidyness > saving a var declaration.

Please sign in to comment.