Skip to content

Fix class parsing (issue 3083)#3103

Merged
lzybkr merged 4 commits into
PowerShell:masterfrom
iSazonov:fix3083
Feb 14, 2017
Merged

Fix class parsing (issue 3083)#3103
lzybkr merged 4 commits into
PowerShell:masterfrom
iSazonov:fix3083

Conversation

@iSazonov
Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov commented Feb 6, 2017

Close #3083

This problem only appears in the interactive session with manual input
(or right click) and with PSReadLine loaded so no tests.

Close PowerShell#3083

This problem only appears in the interactive session with manual input
(or right click) and PSReadLine loaded so no tests.
@vors
Copy link
Copy Markdown
Collaborator

vors commented Feb 6, 2017

What's the error message on the motivation example now?
I think it would be better to modify parser to allow blank lines in the interactive session. That would greatly improve copy-paste story.

Essentially the smallest repro is

class foo {

}

@iSazonov
Copy link
Copy Markdown
Collaborator Author

iSazonov commented Feb 6, 2017

The fix just allow blank lines.

@vors
Copy link
Copy Markdown
Collaborator

vors commented Feb 6, 2017

Oh, that's very interesting. From the diff it seems that it just changes extent, but keeps reporting the error. Let me check with a local build.

@vors
Copy link
Copy Markdown
Collaborator

vors commented Feb 6, 2017

Verified. Great change!

@iSazonov
Copy link
Copy Markdown
Collaborator Author

iSazonov commented Feb 6, 2017

Yes it is slightly a trick. :-)
Perhaps we should replace ExtentOf on After?

vors
vors previously approved these changes Feb 6, 2017
Copy link
Copy Markdown
Collaborator

@vors vors left a comment

Choose a reason for hiding this comment

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

@lzybkr can you, please double-check?

@vors
Copy link
Copy Markdown
Collaborator

vors commented Feb 6, 2017

@iSazonov yeah, After seems more of a pattern in parser. I actually tried replace it by After, but it didn't work for me. And I didn't have ability to debug it at the moment.

@iSazonov
Copy link
Copy Markdown
Collaborator Author

iSazonov commented Feb 6, 2017

I found as apply After. Looks better for me.

@PowerShellTeam PowerShellTeam added the Review - Needed The PR is being reviewed label Feb 6, 2017
@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Feb 6, 2017

The use of After looks incorrect, or at least inconsistent to me. In that overload, the first parameter is where we want to report the error, so on the opening curly is fine, and consistent with most of the other places we report similar errors.

The important part is reporting where the error was detected, the second parameter - and that should be sufficient to fix the bug.

@vors
Copy link
Copy Markdown
Collaborator

vors commented Feb 6, 2017

where we want to report the error, so on the opening curly is fine

I think it's more usable to report non-closed curly closer to the expected place.
Imagine 100 lines class. Would you rather see error on the first open curly or on the last line?

Also, the fix itself exploits the implementation of ReportIncompleteInput: if reported extent happens at the last token, we actually don't error out and waiting for more input. So extent here has to be at the end. It's consistent with how do you treat things like

& { 1


}

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Feb 6, 2017

Yes, but it's somewhat difficult to infer where the closing brace should go. End of file is often the best we can do, and that's worse than pointing to the opening brace.

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Feb 6, 2017

Oh, the proposed fix moves the point where the error is reported by 1 character - the character after the curly - so it's not really much different, and it's not consistent with most other places we report the same error.

@iSazonov
Copy link
Copy Markdown
Collaborator Author

iSazonov commented Feb 7, 2017

I tried looking for if (rCurly.Kind != TokenKind.RCurly) and found:

  1. We should fix the same issue with Enum - Line
  2. We have working pattern for @{} - Line - Can we use this to fix Class and Enum?

@lzybkr
Copy link
Copy Markdown
Contributor

lzybkr commented Feb 7, 2017

The hash literal might be a bad example, I think the error should point to the @{.

Consider an example like:

function foo
{

function bar
{
}

foo is missing the matching brace, but it can't be detected until after bar. If we reported from opening brace to end of file, you get ugly red squiggles filing up the screen and it's a bit slow rendering that - not too useful for folks who don't like typing the closing brace right away.

By reporting the error on the opening brace, assuming sane indentation, it's usually easy to figure out where the missing brace goes.

So I'd say hash literals, class, and enum should all be modified to report the error after the opening brace, and make sure to pass the position the error is detected to ensure we correctly report an incomplete parse for interactive command line use.

Fix for class, enum and hash expression
@iSazonov
Copy link
Copy Markdown
Collaborator Author

iSazonov commented Feb 7, 2017

Fix for hash, class, and enum is ready. Now the error position is reported after the opening brace.

: (Expression<Func<string>>)(() => ParserStrings.IncompleteHashLiteral);
ReportIncompleteInput(keyValuePairs.Any() ? After(keyValuePairs.Last().Item2) : After(atCurlyToken), rCurly.Extent, errorMessageExpression);
: (Expression<Func<string>>)(() => ParserStrings.MissingEndCurlyBrace);
ReportIncompleteInput(After(atCurlyToken), rCurly.Extent, errorMessageExpression);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like it might degrade the quality of the error on:

@{
a =
}

or something like that - please try variants of this (for example: with and without the closing curly, with and without the =).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I see. I tried to fix.

After that there is another question: Are NewLine and Semi terminators having the same rights? Compare:

@{
a = 
b =1
c =2
}


@{
a = ;
b =1;
c =2;
}

If we will fix this (require that the expression begin immediately after the equal on the same line) of cause it will be a breaking change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting, I don't recall explicitly supporting multiple statement terminators (you can have multiple semicolons as well) - so we shouldn't break anybody even though that's kinda broken.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clear. Thanks!

@lzybkr lzybkr dismissed vors’s stale review February 8, 2017 23:05

Must re-approve when new commits pushed.

@lzybkr lzybkr self-assigned this Feb 8, 2017
@lzybkr lzybkr merged commit a16fead into PowerShell:master Feb 14, 2017
@daxian-dbw
Copy link
Copy Markdown
Member

@iSazonov Great commit description! It helps me quickly understand the problem and the fix. Thanks!

@iSazonov iSazonov deleted the fix3083 branch February 16, 2017 02:56
@iSazonov iSazonov removed the Review - Needed The PR is being reviewed label Mar 27, 2017
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.

6 participants