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

Better error message for invalid syntax followed by valid syntax #318

Open
LilithHafner opened this issue Jun 27, 2023 · 3 comments
Open
Labels
error messages Better, more actionable diagnostics

Comments

@LilithHafner
Copy link
Member

LilithHafner commented Jun 27, 2023

julia> import a, b, c=d e, f, g, h
ERROR: ParseError:
# Error @ REPL[50]:1:17
import a, b, c=d e, f, g, h
#               └─────────┘ ── extra tokens after end of expression

julia> 1 = 2 3
ERROR: ParseError:
# Error @ REPL[58]:1:6
1 = 2 3
#    └┘ ── extra tokens after end of expression

I believe that the "extra tokens after end of expression" error should only occur if the expression preceding the extra tokens is complete and valid.

Maybe the real issue here is that this should throw?

julia> Meta.parse("import a = 1")
:(import a = 1)
@c42f
Copy link
Member

c42f commented Jun 27, 2023

Maybe the real issue here is that this should throw

Yes I think that's the reason you find this surprising.

A lot of expressions which aren't valid Julia are allowed by the parser because "macros might want to manipulate them" and turn them into valid syntax. So we can't be very strict about validation during parsing!

Arguably this form of import could be allowed for those reasons. Or not. It's not an obvious case to me. The old parser thinks it's ok:

julia> using JuliaSyntax

julia> JuliaSyntax.fl_parse("import a = 1")
:(import a = 1)

@fingolfin
Copy link

Apologies if this is total nonsense, but: would it perhaps be possible to have a "macro mode": while in macro mode, import a = 1 would be accepted; but in "regular mode" it would raise an error.

Of course a separate question is whether this is desirable in terms of code complexity for JuliaSyntax; and a third one whether it is desirable in terms of user confusion ;-).

@LilithHafner LilithHafner added the error messages Better, more actionable diagnostics label Jul 31, 2023
@ShalokShalom
Copy link

Given that macros are rare, and purposefully so, I think a dedicated macro mode would make sense. Whenever we have a macro, the error message changes. Sounds easy enough?

Is there any downside, besides that it is not implemented yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable diagnostics
Projects
None yet
Development

No branches or pull requests

4 participants