Escape sequences in string literals #274
Labels
Component: code base
The code quality of the project (does not affect functionality)
Component: code generation
Something that concerns the generated code
Component: DSL
Something that concerns the design of PIE DSL
Priority: medium
Status: proposal
Enhancement in the proposal stage
Type: bug
Something isn't working
Type: enhancement
New feature or request
Summary
Implement and document proper escape characters in string literals
Todo
Reason
Compiler generates incorrect Java code when using an escape sequence which is not legal in Java.
Reproduction steps
Given the string literal
"\c"
Expected: it compiles to
"c"
(with possibly a warning that\c
does not do anything) or is an errorActual: compiles to it compiles to
"\c"
, which gives the following error in Java: "Illegal escape character in string literal"Description
Currently it just allows everything, and directly passes it to Java (with exception of
\$
). This does not work because apparently java does not allow invalid escape sequences.Should decide whether to allow invalid escape sequences (and give a warning that it does not do anything) or to make it an error (like Java).
Probably easiest to just copy the sequences from Java, plus
\$
Implementation
Probably best to desugar to the actual character code, and then compile back to escape sequence when generating Java.
This means that the string used internally in the compiler and static semantics is always the literal string without escape sequences.
The text was updated successfully, but these errors were encountered: