From b15958c557d3b29c8d4cee9951a8bfd30c215482 Mon Sep 17 00:00:00 2001 From: Vexu Date: Fri, 14 Feb 2020 23:41:18 +0200 Subject: [PATCH] fix c tokenizer bug --- lib/std/c/tokenizer.zig | 2 ++ test/translate_c.zig | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/std/c/tokenizer.zig b/lib/std/c/tokenizer.zig index 66e6d9d52..c3f50da13 100644 --- a/lib/std/c/tokenizer.zig +++ b/lib/std/c/tokenizer.zig @@ -616,6 +616,7 @@ pub const Tokenizer = struct { }, .BackSlash => switch (c) { '\n' => { + result.start = self.index + 1; state = .Start; }, '\r' => { @@ -631,6 +632,7 @@ pub const Tokenizer = struct { }, .BackSlashCr => switch (c) { '\n' => { + result.start = self.index + 1; state = .Start; }, else => { diff --git a/test/translate_c.zig b/test/translate_c.zig index bb2a310b0..b69142e86 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3,6 +3,13 @@ const builtin = @import("builtin"); const Target = @import("std").Target; pub fn addCases(cases: *tests.TranslateCContext) void { + cases.add("macro line continuation", + \\#define FOO -\ + \\BAR + , &[_][]const u8{ + \\pub const FOO = -BAR; + }); + cases.add("function prototype translated as optional", \\typedef void (*fnptr_ty)(void); \\typedef __attribute__((cdecl)) void (*fnptr_attr_ty)(void);