diff --git a/src/stage1/parser.cpp b/src/stage1/parser.cpp index 60189a210b..a49773e9ca 100644 --- a/src/stage1/parser.cpp +++ b/src/stage1/parser.cpp @@ -513,6 +513,8 @@ static Token *ast_parse_multiline_string_literal(ParseContext *pc, Buf *buf) { // if not, we have to revert back to before the doc comment if (peek_token(pc)->id != TokenIdMultilineStringLiteral) { pc->current_token = cur_token; + } else { + buf_append_char(buf, '\n'); // Add a newline between comments } } return first_str_token; diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index 04087dd4af..269db18579 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -166,6 +166,48 @@ test "multiline string" { expect(mem.eql(u8, s1, s2)); } +test "multiline string comments at start" { + const s1 = + //\\one + \\two) + \\three + ; + const s2 = "two)\nthree"; + expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments at end" { + const s1 = + \\one + \\two) + //\\three + ; + const s2 = "one\ntwo)"; + expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments in middle" { + const s1 = + \\one + //\\two) + \\three + ; + const s2 = "one\nthree"; + expect(mem.eql(u8, s1, s2)); +} + +test "multiline string comments at multiple places" { + const s1 = + \\one + //\\two + \\three + //\\four + \\five + ; + const s2 = "one\nthree\nfive"; + expect(mem.eql(u8, s1, s2)); +} + test "multiline C string" { const s1 = \\one