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

Basic parenthesis and bracket balance checking [] () {} #1546

Closed
rseymour opened this issue Oct 24, 2017 · 3 comments
Closed

Basic parenthesis and bracket balance checking [] () {} #1546

rseymour opened this issue Oct 24, 2017 · 3 comments
Labels
Error messages confusing, missing, or just weak error messages

Comments

@rseymour
Copy link

As a rather newb ReasonML I have found some of my most mysterious syntax errors to be caused by unbalanced parentheses, curly brackets, or square brackets.

While sometimes it will get the line number correct, other times it will go to the end of the block or sometimes the end of the file. I've had the worst results with missing opening [ on lists.

Sorry I don't have a lot of code examples, I've personally turned on RainbowParentheses in vim to see visually when I mess up, but it would be neat if the compiler could do the basic enclosure counting. My own research has shown this can be an interview question or a PhD thesis research topic, so I want to put this as a very light suggestion. GCC as late as 2016 has no such logic in it, nor does LLVM as far as I can tell. Also I don't know if this would go into refmt, merlin, or some other stage. Just putting it out there since it is useful, but as it can be a quite involved problem to do this efficiently I wouldn't want to put this on anyone to truly solve.

Program analysis via graph reachability -> http://www.dtic.mil/get-tr-doc/pdf?AD=ADA332493
and a later paper with an efficient algorithm for doing such CFL analysis:
https://www.cs.purdue.edu/homes/peugster/EventJava/Dyck-Trees.pdf

Or just stack, pop and count them. 🔢 😸

@jordwalke
Copy link
Member

Or just stack, pop and count them.
😃

IIRC, we already have a similar process that occurs before running the full parser, in order to infer which parens are the opening of ES6 style fat arrow functions. This might be a natural point to print very helpful messages about unbalanced parens.

@chenglou
Copy link
Member

cc @let-def ^ would be a great test for the new syntax error reporting! If it's even possible

@jaredly jaredly added the Error messages confusing, missing, or just weak error messages label Jun 14, 2018
@anmonteiro
Copy link
Member

Reerror (#2480) gives better error messages for unbalanced braces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error messages confusing, missing, or just weak error messages
Projects
None yet
Development

No branches or pull requests

5 participants