Multiline strings work now, both single and triple quotes. Triple quotes also correctly escapes other quotes.
This commit is contained in:
@@ -516,7 +516,9 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* 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<ASTData>* from, NodeTree<ASTData>* 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;
|
||||
|
||||
10
tests/test_multiline_strings.expected_results
Normal file
10
tests/test_multiline_strings.expected_results
Normal file
@@ -0,0 +1,10 @@
|
||||
multi
|
||||
line
|
||||
first
|
||||
second
|
||||
third
|
||||
|
||||
How about this?
|
||||
multi line?
|
||||
inner quote "
|
||||
|
||||
18
tests/test_multiline_strings.krak
Normal file
18
tests/test_multiline_strings.krak
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user