yberreby / rgo

[STALLED] A Go compiler, written in Rust.
177 stars 11 forks source link

Finish implementing the parser #6

Open yberreby opened 8 years ago

yberreby commented 8 years ago

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):

MovingtoMars commented 8 years ago

Going to have a look at interpreting strings/runes now

yberreby commented 8 years ago

Great! Thank you again for your contributions, @MovingtoMars.

MovingtoMars commented 8 years ago

After looking into it, I don't think string literals can be stored inside Strings. This is because Go allows us to have invalid ASCII/UTF-8 inside string literals through the use of octal and hex escapes.

yberreby commented 8 years ago

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

MovingtoMars commented 8 years ago

\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

yberreby commented 8 years ago

Alright, got it! Thanks.

MovingtoMars commented 8 years ago

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.