MontysCoconut / moco

The Monty to LLVM compiler
http://www.informatik.uni-bremen.de/monty/
GNU General Public License v3.0
10 stars 5 forks source link

Fix strings #16

Closed cpfr closed 9 years ago

cpfr commented 9 years ago

Hi there,

I implemented the escape sequences in String literals, as suggested by the language specification. The current version in the master branch does not support escape sequences like print("Hello\nWorld") etc. Instead one had to literally break the String like that:

print("Hello
World")

This merge request fixes that issue and also introduces the following escape sequences:

All of the mentioned escape sequences, except the unicode one are also implemented for Char literals. Unicode is not implemented for Char since the current implementation of this type seems to be restricted to 8 bit.

lummax commented 9 years ago

Hey, could you add some test cases using these escape sequences and a print() statement?

cpfr commented 9 years ago

I modified the PrintString test case so that it now also consideres escape sequences

lummax commented 9 years ago

The code looks fine. I would merge it within the next few days if noone else objects.

It would be nice to have a lot more test cases:

Each of those are different control paths within the source code. With different variances I mean at least all the special cases of control sequenes ('\t', '\b', '\n', ...).

cpfr commented 9 years ago

The most recent commit adds test cases for all special escape sequences. I also noticed that my first attempt to parse \uXXXX escape sequences was wrong, since it expected the 16 bit code to be UTF-8 encoded already. However, the XXXX code is expected to be a unicode index (different from the actual UTF-8 codes). I fixed this and also added unicode support for String literals (meaning that you can directly type "Hällo Wörld").