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

Excessive number of parser errors displayed #50223

Closed
jakobnissen opened this issue Jun 20, 2023 · 2 comments · Fixed by JuliaLang/JuliaSyntax.jl#344
Closed

Excessive number of parser errors displayed #50223

jakobnissen opened this issue Jun 20, 2023 · 2 comments · Fixed by JuliaLang/JuliaSyntax.jl#344
Labels
parser Language parsing and surface syntax

Comments

@jakobnissen
Copy link
Contributor

jakobnissen commented Jun 20, 2023

The following (invalid) Julia program:

==????======??

Gives the following parser error on 1.9:

ERROR: LoadError: syntax: "==" is not a unary operator
Stacktrace:
 [1] top-level scope
   @ /tmp/foo.jl:1
in expression starting at /tmp/foo.jl:1

But unnecessarily throws multiple errors after #46372:

ERROR: LoadError: ParseError:
# Error @ /tmp/foo.jl:1:1
==????======??
└┘ ── not a unary operator
# Error @ /tmp/foo.jl:1:3
==????======??
# ╙ ── not a unary operator
# Error @ /tmp/foo.jl:1:4
==????======??
#  ╙ ── not a unary operator
# Error @ /tmp/foo.jl:1:5
==????======??
#   ╙ ── not a unary operator
# Error @ /tmp/foo.jl:1:6
==????======??
#    ╙ ── not a unary operator
# Error @ /tmp/foo.jl:1:7
==????======??
#     └─┘ ── not a unary operator
# Error @ /tmp/foo.jl:1:10
==????======??
#        └─┘ ── not a unary operator
# Error @ /tmp/foo.jl:1:13
==????======??
#           ╙ ── not a unary operator
# Error @ /tmp/foo.jl:1:14
==????======??
#            ╙ ── invalid identifier
Stacktrace:
 [1] top-level scope
   @ /tmp/foo.jl:1
in expression starting at /tmp/foo.jl:1

Although it can be debated, I think only displaying the first parser error is less confusing than displaying them all. In particular, I can imagine an input file which could throw hundreds of parser errors.
cc @c42f

@giordano giordano added the parser Language parsing and surface syntax label Jun 20, 2023
@c42f
Copy link
Member

c42f commented Jun 20, 2023

We could just display the first one. That would generally be equivalent to the error emitted by the existing parser (except with precise source location info).

It's common that the latter errors aren't terribly useful (unless parser recovery is very, very good. Which obviously I'd like to do but it's a pile work which hasn't been done yet.) So maybe this would be better.

Maybe we could enable more verbose errors with a IOContext setting or something?

@jakobnissen
Copy link
Contributor Author

I'm not too knowledgeable about this thing, so take my view with a grain of salt, but: I think there are three major use cases:

  • Normal use: User does not want to configure anything. We should pick the overall nicest default, i.e. showing the first one to avoid spamming the terminal.
  • Some power users may want to learn all syntax errors in a file, so they don't have to fix them one by one.
  • For tooling, it's necessary to get all errors. However, these tools presumably will not rely on catching ParseErrors, but instead get the internal JuliaSyntax representation.

Perhaps the (hypothetical, and probably few) people in the second group should just use JuliaSyntax directly and not rely on the built-in parser if they want to customize parser errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants