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

Syntax issues with hexadecimal prefix #16356

Closed
omus opened this issue May 13, 2016 · 8 comments
Closed

Syntax issues with hexadecimal prefix #16356

omus opened this issue May 13, 2016 · 8 comments
Assignees
Labels
breaking This change will break code parser Language parsing and surface syntax
Milestone

Comments

@omus
Copy link
Member

omus commented May 13, 2016

I was messing around with how the syntax for the hexadecimal prefix works while thinking about #15731 and I found something entertaining:

julia> 0xenomorph
ERROR: UndefVarError: nomorph not defined

julia> xenomorph = 1
1

julia> 0xenomorph
ERROR: UndefVarError: nomorph not defined

julia> nomorph = 2
2

julia> 0xenomorph
28

julia> 0xgnomorph
ERROR: syntax: malformed expression

julia> 0xefnomorph
478

Maybe we should disallow juxtaposition with hexadecimals? Seems like it will just lead to confusion.

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label May 13, 2016
@JeffBezanson
Copy link
Member

My favorite part is that the syntax coloring in github gets it exactly right :P

@omus
Copy link
Member Author

omus commented May 13, 2016

Syntax highlighting makes it obvious what is going on. In the REPL however it isn't very clear.

@Keno
Copy link
Member

Keno commented May 13, 2016

The solution is clear: Add syntax highlighting to the REPL.

@omus
Copy link
Member Author

omus commented May 13, 2016

I agree that adding syntax highlighting to the REPL would be great and would solve this issue. For this issue however I slightly lean towards disallowing juxtaposed hexadecimals as it avoids any potential confusion when syntax highlighting is unavailable.

@toivoh
Copy link
Contributor

toivoh commented May 14, 2016 via email

@omus
Copy link
Member Author

omus commented Jun 23, 2016

If we're disallowing juxtaposed hexadecimals we probably also want to do the same for binary and octals

julia> xep = 3
3

julia> 0xep0xep
42.0

julia> b0 = 2
2

julia> 0b1b0
2

julia> o0 = 3
3

julia> 0o1o0
3

@KristofferC
Copy link
Member

The solution is clear: Add syntax highlighting to the REPL.

image

@omus
Copy link
Member Author

omus commented Jun 30, 2017

Looks like the syntax highlighting isn't quite right for the second last example. I believe it should highlight 0x and not just 0:

julia> 0x
ERROR: syntax: invalid numeric constant "0x"

julia> 0xg
ERROR: syntax: invalid numeric constant "0x"

julia> g = 1
1

julia> 0xg
ERROR: syntax: invalid numeric constant "0x"

julia> xg = 1
1

julia> 0xg
ERROR: syntax: invalid numeric constant "0x"

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

No branches or pull requests

5 participants