Open yberreby opened 8 years ago
Going to have a look at interpreting strings/runes now
Great! Thank you again for your contributions, @MovingtoMars.
After looking into it, I don't think string literals can be stored inside String
s. This is because Go allows us to have invalid ASCII/UTF-8 inside string literals through the use of octal and hex escapes.
Go allows us to have invalid ASCII/UTF-8 inside string literals through the use of octal and hex escapes.
Do you have a source for that?
From the spec:
'\uDFFF' // illegal: surrogate half
'\U00110000' // illegal: invalid Unicode code point
It does seem invalid Unicode is rejected: playground link
\u
escapes that represent invalid codepoints are rejected. However, you can use hex and octal escapes to get invalid UTF-8, eg: https://play.golang.org/p/Af16vaFvZA
This is the relevant bit in the spec
The three-digit octal (\nnn) and two-digit hexadecimal (\xnn) escapes represent individual bytes of the resulting string; all other escapes represent the (possibly multi-byte) UTF-8 encoding of individual characters.
Also, see https://blog.golang.org/strings
Alright, got it! Thanks.
A problem I see for if
is how to tell if we have a simple statement or an expression first.
Edit: this is actually not that hard, I just forgot to implement ExprStmt with SimpleStmt. I've added it now, which simplifies this a lot.
The base of the parser is there, but it still needs a lot work. The bulk of the remaining work is expression parsing and composite types.
Remaining work (incomplete list):
go
statementsif
statementsswitch
statementsselect
statementsfor
statements\n
) - they are currently treated as raw string literals