Skip to content

Conversation

@helixbass
Copy link
Collaborator

Fixes #5292

This PR updates addImplicitBracesAndParens() to correctly parse things like:

d: b or
  b: 1

if (stackTag is '{' or stackTag is 'INDENT' and @tag(stackIdx - 1) is '{') and
(startsLine or @tag(s - 1) is ',' or @tag(s - 1) is '{')
(startsLine or @tag(s - 1) is ',' or @tag(s - 1) is '{') and
@tag(s - 1) not in UNFINISHED
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Getting it to parse the nested object as a separate object wasn't that hard...

stackItem[2].sameLine = no if isImplicitObject stackItem

# End indented-continuation-line implicit objects once that indentation is over.
if tag is 'TERMINATOR' and token.endsContinuationLineIndentation
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

...the hard part was to then parse additional properties of the outer object as belonging to the outer (not inner) object, eg:

a: b or
  b: 1
c: 2 # this belongs to the top-level object, not the nested b: 1 object

In order to accomplish that, I added extra token data for "indented line continuations" like this to allow comparing the indentation levels to know when the nested line continuation indent is done (thus when the nested object is done)

].concat IMPLICIT_UNSPACED_CALL.concat IMPLICIT_END.concat CALL_CLOSERS.concat CONTROL_IN_IMPLICIT

# Tokens that, when appearing at the end of a line, suppress a following TERMINATOR/INDENT token
exports.UNFINISHED = UNFINISHED = ['\\', '.', '?.', '?::', 'UNARY', 'DO', 'DO_IIFE', 'MATH', 'UNARY_MATH', '+', '-',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I moved this here to avoid a circular dependency between lexer.coffee and rewriter.coffee

src/lexer.coffee Outdated
if size > @indent
if noNewlines
@indebt = size - @indent unless backslash
if @indebt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It might be nice to additionally rename @indebt to something more descriptive like @continuationLineAdditionalIndent?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, indebt is a pretty bad name (too close to indent).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok renamed indebt -> continuationLineAdditionalIndent

@GeoffreyBooth GeoffreyBooth merged commit 9cef39d into jashkenas:master Jan 30, 2020
@GeoffreyBooth GeoffreyBooth mentioned this pull request Jan 30, 2020
@helixbass helixbass deleted the iss5292-nested-implicit-object-after-continuer branch January 30, 2020 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Parser: implicit object as end of outer implicit object property value

2 participants