Skip to content

Add a for .. from .. loop for generators, see #4306, #3832#4355

Merged
GeoffreyBooth merged 20 commits intojashkenas:masterfrom
GeoffreyBooth:for-from
Nov 8, 2016
Merged

Add a for .. from .. loop for generators, see #4306, #3832#4355
GeoffreyBooth merged 20 commits intojashkenas:masterfrom
GeoffreyBooth:for-from

Conversation

@GeoffreyBooth
Copy link
Collaborator

Trying to get #4306 over the finish line. There’s one significant change between that PR and this one: I moved the "own is not supported in for-from loops" test into error_messages.coffee, and improved the error message generated for that error.

Previously, code like x for own x from [1, 2, 3] would throw the above error but with x underlined. Since the error is about the own, it seems to me that the own is what should get emphasized. Getting the location data for the own tag (token?) entailed some trickery, though, as that token was basically discarded by the parser. See the new code added to grammar.coffee regarding ownTag@lydell, is this kosher? Should I be calling this ownToken or something else? Or is there a better way to get this location data into For?

The other changes since #4306 involve fixing style and minimizing the impact of this PR, removing unnecessary changes.

@GeoffreyBooth GeoffreyBooth added this to the 2.0.0 milestone Nov 8, 2016
@GeoffreyBooth GeoffreyBooth removed this from the 2.0.0 milestone Nov 8, 2016
Copy link
Collaborator

@lydell lydell left a comment

Choose a reason for hiding this comment

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

Good job!

The ownTag hack looks good to me.

EsrefDurna pushed a commit to EsrefDurna/coffeescript that referenced this pull request Nov 12, 2025
…enas#3832 (jashkenas#4355)

* Added support for for-from loop, see jashkenas#3832

* for-from: remove extra newline and add support for ranges

* for-from: tidy up the lexer

* for-from: add support for patterns

* for-from: fix bad alignment

* for-from: add two more tests

* for-from: fix test "for-from loops over generators"

See explanation here: jashkenas#4306 (comment)

* for-from: delete leftover console.log

* Refactor the big `if` block in the lexer to be as minimal a change from `master` as we can get away with

* Cleanup to make more idiomatic, remove trailing whitespace, minor performance improvements

* for-from: move code from one file to another

* for-from: clean up whitespace

* for-from: lexer bikeshedding

* Move "own is not supported in for-from loops" test into error_messages.coffee; improve error message so that "own" is underlined

* Revert unnecessary changes, to minimize the lines of code modified by this PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants