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 for trailing commas in using #108

Open
c42f opened this issue Oct 4, 2022 · 2 comments
Open

Better error for trailing commas in using #108

c42f opened this issue Oct 4, 2022 · 2 comments
Labels
error messages Better, more actionable diagnostics

Comments

@c42f
Copy link
Member

c42f commented Oct 4, 2022

Leaving a trailing comma after the last element of using is a mistake I've made a few times. The parser only catches this error later, resulting in a fairly poor error message. For example, it can gobble up the function keyword in the next part of the file:

julia> using A: b,

       function foo()
       end

ERROR: ParseError:
Error: extra tokens after end of expression
@ REPL[4]:3:9
using A: b,

function foo()
--------^^^^^^---
end
@c42f c42f added the error messages Better, more actionable diagnostics label Oct 4, 2022
@pfitzseb
Copy link
Member

pfitzseb commented Oct 4, 2022

This is made slightly trickier by the fact that function can be used as a valid identifier there:

julia> module A
       b = 2
       var"function" = 3
       end
Main.A

julia> using .A: b,
       function

julia> using .A: b,
       function foo()
ERROR: syntax: extra token "foo" after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1

Then again, this is a really good use case for post-hoc diagnostics instead of limited lookahead during parsing :)

@c42f
Copy link
Member Author

c42f commented Oct 4, 2022

Yes exactly 👍 The same kind of problem happens for struct definitions or other keywords like if.

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

2 participants