goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Special characters such as `\n` are not interpreted #196

Closed hachi8833 closed 7 years ago

hachi8833 commented 7 years ago

Special characters with backslash such as \n \r \t \v are not treated. Looks like string literals are actually just a byte stream.

a = "Hello\nWorld"
puts(a)  
# => "Hello\nWorld"
a = "Hello\nWorld"
puts(a)  
# => Hello
# => World
Alexius-Huang commented 7 years ago

189 meets some sort of same problem, such as when implementing the String#strip, it need to handle the case such that:

"\n\t Hello World\t \r\n".strip # => "Hello World"
hachi8833 commented 7 years ago

Actually, I met the same issue when trying to implement String#strip ;-)

Well, I suppose we should also change string type in Golang to rune type.

st0012 commented 7 years ago

I'll let @Maxwell-Alexius work on this first.

Alexius-Huang commented 7 years ago

@st0012 @hachi8833 I'm not sure whether to also convert string type to rune type in initStringObject? What are your opinions? (If this conversion is needed, then it should open another PR to implement it.)

st0012 commented 7 years ago

I'm not very familiar with rune type, need to spend some to do some research.

Alexius-Huang commented 7 years ago

Me, too. There's a lot to learn, then leave this issue for a moment. (I'll keep on implementing other string api in #184 )

st0012 commented 7 years ago

@hachi8833 I think @Maxwell-Alexius already fixed this, can you help verify?

hachi8833 commented 7 years ago

Confirmed \n \t works now! I close the issue.