diff --git a/src/CGenerator.cpp b/src/CGenerator.cpp index f7eb4c6..b6e68a3 100644 --- a/src/CGenerator.cpp +++ b/src/CGenerator.cpp @@ -516,7 +516,9 @@ CCodeTriple CGenerator::generate(NodeTree* from, NodeTree* enc } // The actual passthrough string is the last child now, as we might // have passthrough_params be the first child - return pre_passthrough + strSlice(generate(children.back(), enclosingObject, justFuncName).oneString(), 3, -4) + post_passthrough; + // we don't generate, as that will escape the returns and we don't want that. We'll just grab the string + //return pre_passthrough + strSlice(generate(children.back(), enclosingObject, justFuncName).oneString(), 3, -4) + post_passthrough; + return pre_passthrough + strSlice(children.back()->getDataRef()->symbol.getName(), 3, -4) + post_passthrough; } case function_call: { @@ -628,7 +630,24 @@ CCodeTriple CGenerator::generate(NodeTree* from, NodeTree* enc return output; } case value: + { + // ok, we now check for it being a string and escape all returns if it is (so that multiline strings work) + if (data.symbol.getName()[0] == '"') { + std::string innerString = strSlice(data.symbol.getName(), 0, 3) == "\"\"\"" + ? strSlice(data.symbol.getName(), 3, -4) + : strSlice(data.symbol.getName(), 1, -2); + std::string newStr; + for (auto character: innerString) + if (character == '\n') + newStr += "\\n"; + else if (character == '"') + newStr += "\\\""; + else + newStr += character; + return "\"" + newStr + "\""; + } return data.symbol.getName(); + } default: std::cout << "Nothing!" << std::endl; diff --git a/tests/test_multiline_strings.expected_results b/tests/test_multiline_strings.expected_results new file mode 100644 index 0000000..f903469 --- /dev/null +++ b/tests/test_multiline_strings.expected_results @@ -0,0 +1,10 @@ +multi +line +first +second +third + +How about this? +multi line? +inner quote " + diff --git a/tests/test_multiline_strings.krak b/tests/test_multiline_strings.krak new file mode 100644 index 0000000..a109687 --- /dev/null +++ b/tests/test_multiline_strings.krak @@ -0,0 +1,18 @@ +import io:* + +fun main():int { + println("multi +line") + var str = "first +second +third" + println(str) + var tripQute = """ +How about this? +multi line? +inner quote " +""" + + println(tripQute) + return 0 +}