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

some better debug-mode parse diagnostics on syntax error #10707

Merged
merged 2 commits into from
Dec 15, 2020
Merged

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Dec 14, 2020

I worked with @auduchinok today to discuss how to improve parser error recovery

This adds a debug-mode test flag to show the parser stack on parse failure, for use when debugging parser rules
parser stack:

fsc.exe --test:ShowParserStackOnParseError

Also rejigs the internal-use-only flag --ast to show the ast even if parsing has failed, so we can inspect the nodes produced

Typical output of --test:ShowParserStackOnParseError is as follows. The information is limited but actually very useful to understand what's going on. fsprojects/FsLexYacc#138 covers actually printing the full rules but needs an FsLex update

What this shows is that at the point where the syntax error happens, one of four unionCaseReprElements parser rules is still active (this is after an OF token). We got to this state by the states shown from the bottom up (only 12 are shown). That is we were parsing one of these:

tyconDefnRhsBlock  
classDefnBlockKindUnspecified

then tokens arrived that pushed the various further states involving rules for unionTypeRepr and attrUnionCaseDecls and unionCaseReprElements on to the stack.

   ----
       non-terminal NONTERM_unionCaseReprElements: ...
   ----
       non-terminal NONTERM_unionCaseReprElements: ...
       non-terminal NONTERM_unionCaseReprElements: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
       non-terminal NONTERM_attrUnionCaseDecl: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecls: ...
   ----
       non-terminal NONTERM_attrUnionCaseDecls: ...
       non-terminal NONTERM_attrUnionCaseDecls: ...
   ----
       non-terminal NONTERM_unionTypeRepr: ...
   ----
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
   ----
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_classDefnMember: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
       non-terminal NONTERM_tyconDefnOrSpfnSimpleRepr: ...
   ----
       non-terminal NONTERM_tyconDefnRhsBlock: ...
       non-terminal NONTERM_tyconDefnRhsBlock: ...
       non-terminal NONTERM_classDefnBlockKindUnspecified: ...
       non-terminal NONTERM_classDefnBlockKindUnspecified: ...

Copy link
Member

@KevinRansom KevinRansom left a comment

Choose a reason for hiding this comment

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

Looks good

@dsyme dsyme merged commit a3fbdd9 into dotnet:main Dec 15, 2020
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.

2 participants