-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add \a escape sequence #5864
Add \a escape sequence #5864
Conversation
The escape sequence that makes a beep.
I think when the original developer was deciding for the first time what escape sequences to include, they made an educated decision on which ones are important. I don't think it's a matter of forgetting to include it or anything like that. More is not always better. Ruby having it is not a good argument. |
Now that I look at it more carefully, this does seem like an unusual omission, because Crystal has all other escape sequences from these two |
spec/compiler/lexer/lexer_spec.cr
Outdated
@@ -230,6 +230,7 @@ describe "Lexer" do | |||
it_lexes_number :i8, ["0i8", "0"] | |||
|
|||
it_lexes_char "'a'", 'a' | |||
it_lexes_char "'\\a'", '\a' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to keep release compatibility you would have to write 7.chr
not '\a'
src/compiler/crystal/syntax/lexer.cr
Outdated
@@ -493,6 +493,8 @@ module Crystal | |||
case char | |||
when '\\' | |||
case char = next_char | |||
when 'a' | |||
io << "\x07" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep "\u{7}"
format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah basically you have to do whatever the \b
addition does. New source code must still compile with the old compiler.
src/compiler/crystal/syntax/lexer.cr
Outdated
@@ -1789,6 +1793,8 @@ module Crystal | |||
end | |||
else | |||
case char = next_char | |||
when 'a' | |||
string_token_escape_value "\x07" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Ok now I did whatever the But CircleCI says: Syntax error in src/string.cr:3942: invalid char escape sequence
when '\a' then io << "\\a"
^ |
Can't use |
@RX14 |
Agree, there are also some languages that support it like Ruby and Python, and others don't like Rust |
Go supports |
@Sija we should remove |
It seems rust supports only |
@RX14 or add |
|
@RX14 How is |
I absolutely agree we should add all of them or remove all of them except r, n, t. I just think we should remove complexity, and arcane, typically unused escape sequences. |
I'd say |
@RX14 What's the point of removing well-known functionalities (even if they indeed have arcane heritage), just for removal sake? Wouldn't be better to stay compatible with other languages and be modern in ways that are meaningful? |
I didn't include "\a" because I don't find it useful. I wouldn't mind having it in the language, though. |
I don't care enough to bikeshed over it. If this many people feel it should be in the language, then just add it and I won't use it. Either way this PR (clearly done from the github web UI) wasn't very good. |
(if someone approves this and wants to merge this, please squash :-) |
Also, json additions need to be removed, since |
@@ -1444,6 +1444,7 @@ describe "String" do | |||
"a".dump.should eq %("a") | |||
"\\".dump.should eq %("\\\\") | |||
"\"".dump.should eq %("\\\"") | |||
# TODO: "\a".dump.should eq %("\\a") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a note uncomment after 0.24.2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is enough. Right after 0.25.0 gets released, I will finish this with another PR and there I will just look here to see what I need to do.
@@ -493,6 +493,8 @@ module Crystal | |||
case char | |||
when '\\' | |||
case char = next_char | |||
when 'a' | |||
io << "\u{7}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just an omission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I make a PR to also make these strings chars?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to merge this one first.
The escape sequence that beeps/bells.
Right now when you do
then you can hear a beep/bell and it already works because
07
is the HEX value in ASCII of\a
.But I still think that we should add the escape sequence
\a
directly because it's really some kind of special feature. Thats pretty much the only thing you can hear in a terminal.This escape sequence can be useful for example when you are making an timer or something like that. So you can notify the user while he's doing something else. And it can be also helpful at debugging something without a display. Or generally debugging.