You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=23
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)
The text was updated successfully, but these errors were encountered:
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)
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 ;-).
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?
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?
The text was updated successfully, but these errors were encountered: