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

Add \a escape sequence #5864

Merged
merged 33 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3148078
Add \a escape sequence
wooster0 Mar 25, 2018
2b20c37
Update lexer_spec.cr
wooster0 Mar 25, 2018
b22d159
7.chr
wooster0 Mar 25, 2018
fdbe891
\u{7}
wooster0 Mar 25, 2018
e0922ea
Update string.cr
wooster0 Mar 25, 2018
46e8fa6
Update char_spec.cr
wooster0 Mar 25, 2018
556f4a1
Update parser_spec.cr
wooster0 Mar 25, 2018
1fd04ab
Update string_spec.cr
wooster0 Mar 25, 2018
499f326
Update builder.cr
wooster0 Mar 25, 2018
3eeba60
Update lexer.cr
wooster0 Mar 25, 2018
07933cb
Update serialization_spec.cr
wooster0 Mar 25, 2018
13d0ae3
Update lexer_spec.cr
wooster0 Mar 26, 2018
771cab1
Update lexer.cr
wooster0 Mar 26, 2018
ef3ba45
Update string.cr
wooster0 Mar 26, 2018
e0f1cef
Update char_spec.cr
wooster0 Mar 26, 2018
a1ab033
Update string_spec.cr
wooster0 Mar 26, 2018
3d84815
Update builder.cr
wooster0 Mar 26, 2018
8020d77
Update lexer.cr
wooster0 Mar 26, 2018
17ad4b3
Update string_spec.cr
wooster0 Mar 26, 2018
8ee81da
Update lexer_spec.cr
wooster0 Mar 26, 2018
81435b6
Update serialization_spec.cr
wooster0 Mar 26, 2018
b709308
Update lexer_string_spec.cr
wooster0 Mar 26, 2018
89b5c7e
Update lexer_spec.cr
wooster0 Mar 26, 2018
8363dbb
Update serialization_spec.cr
wooster0 Mar 26, 2018
29d3787
Update char_spec.cr
wooster0 Mar 26, 2018
e1314db
Update string_spec.cr
wooster0 Mar 26, 2018
5249c75
Update lexer.cr
wooster0 Mar 26, 2018
04ced04
Update builder.cr
wooster0 Mar 26, 2018
208c9b8
Update string.cr
wooster0 Mar 26, 2018
a37c81f
Remove \a in json lexer.cr
wooster0 Apr 28, 2018
8e51d58
Remove \a in json lexer_spec.cr
wooster0 Apr 28, 2018
9f5073b
Remove \a in json serialization_spec.cr
wooster0 Apr 28, 2018
672bea2
Remove \a in json builder.cr
wooster0 Apr 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/compiler/lexer/lexer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ describe "Lexer" do
it_lexes_number :i8, ["0i8", "0"]

it_lexes_char "'a'", 'a'
it_lexes_char "'\\a'", 7.chr
it_lexes_char "'\\b'", 8.chr
it_lexes_char "'\\n'", '\n'
it_lexes_char "'\\t'", '\t'
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/lexer/lexer_string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe "Lexer string" do

tester.string_should_start_correctly
tester.next_token_should_be(:NEWLINE)
tester.next_string_token_should_be("abc")
tester.next_string_token_should_be("\abc")
tester.string_should_have_an_interpolation_of("foo")
tester.string_should_end_correctly
end
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe "Parser" do
it_parses %(:"\\\\foo"), "\\foo".symbol
it_parses %(:"\\\"foo"), "\"foo".symbol
it_parses %(:"\\\"foo\\\""), "\"foo\"".symbol
it_parses %(:"\\b\\n\\r\\t\\v\\f\\e"), "\b\n\r\t\v\f\e".symbol
it_parses %(:"\\a\\b\\n\\r\\t\\v\\f\\e"), "\a\b\n\r\t\v\f\e".symbol
it_parses %(:"\\u{61}"), "a".symbol

it_parses "[1, 2]", ([1.int32, 2.int32] of ASTNode).array
Expand Down
1 change: 1 addition & 0 deletions spec/std/char_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe "Char" do
end

it "escapes" do
7.chr.ord.should eq(7) # TODO: use \a
'\b'.ord.should eq(8)
'\t'.ord.should eq(9)
'\n'.ord.should eq(10)
Expand Down
3 changes: 3 additions & 0 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ describe "String" do
"a".dump.should eq %("a")
"\\".dump.should eq %("\\\\")
"\"".dump.should eq %("\\\"")
# TODO: "\a".dump.should eq %("\\a")
Copy link
Member

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?

Copy link
Contributor Author

@wooster0 wooster0 Apr 28, 2018

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.

"\b".dump.should eq %("\\b")
"\e".dump.should eq %("\\e")
"\f".dump.should eq %("\\f")
Expand Down Expand Up @@ -1471,6 +1472,7 @@ describe "String" do
"a".inspect.should eq %("a")
"\\".inspect.should eq %("\\\\")
"\"".inspect.should eq %("\\\"")
# TODO: "\a".inspect.should eq %("\\a")
"\b".inspect.should eq %("\\b")
"\e".inspect.should eq %("\\e")
"\f".inspect.should eq %("\\f")
Expand Down Expand Up @@ -1649,6 +1651,7 @@ describe "String" do
end

it "escapes chars" do
# TODO: "\a"[0].should eq('\a')
"\b"[0].should eq('\b')
"\t"[0].should eq('\t')
"\n"[0].should eq('\n')
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ module Crystal
case char
when '\\'
case char = next_char
when 'a'
io << "\u{7}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these were not touched by #5882 @Sija?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, just an omission.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

when 'b'
io << "\u{8}"
when 'n'
Expand Down Expand Up @@ -611,6 +613,8 @@ module Crystal
@token.value = '\\'
when '\''
@token.value = '\''
when 'a'
@token.value = 7.chr # TODO: use \a
when 'b'
@token.value = '\b'
when 'e'
Expand Down Expand Up @@ -1789,6 +1793,8 @@ module Crystal
end
else
case char = next_char
when 'a'
string_token_escape_value "\u{7}"
when 'b'
string_token_escape_value "\u{8}"
when 'n'
Expand Down
19 changes: 10 additions & 9 deletions src/string.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3937,15 +3937,16 @@ class String
while reader.has_next?
current_char = reader.current_char
case current_char
when '"' then io << "\\\""
when '\\' then io << "\\\\"
when '\b' then io << "\\b"
when '\e' then io << "\\e"
when '\f' then io << "\\f"
when '\n' then io << "\\n"
when '\r' then io << "\\r"
when '\t' then io << "\\t"
when '\v' then io << "\\v"
when '"' then io << "\\\""
when '\\' then io << "\\\\"
when (7.chr) then io << "\\a" # TODO: use \a
when '\b' then io << "\\b"
when '\e' then io << "\\e"
when '\f' then io << "\\f"
when '\n' then io << "\\n"
when '\r' then io << "\\r"
when '\t' then io << "\\t"
when '\v' then io << "\\v"
when '#'
current_char = reader.next_char
if current_char == '{'
Expand Down