Commit fa377dbd15

Vexu <git@vexu.eu>
2020-02-13 08:09:49
fix c tokenizer bug
1 parent 1fb7049
Changed files (2)
lib/std/c/tokenizer.zig
@@ -651,6 +651,7 @@ pub const Tokenizer = struct {
                         state = .StringLiteral;
                     },
                     else => {
+                        self.index -= 1;
                         state = .Identifier;
                     },
                 },
@@ -660,6 +661,7 @@ pub const Tokenizer = struct {
                         state = .StringLiteral;
                     },
                     else => {
+                        self.index -= 1;
                         state = .Identifier;
                     },
                 },
@@ -673,6 +675,7 @@ pub const Tokenizer = struct {
                         state = .StringLiteral;
                     },
                     else => {
+                        self.index -= 1;
                         state = .Identifier;
                     },
                 },
@@ -686,6 +689,7 @@ pub const Tokenizer = struct {
                         state = .StringLiteral;
                     },
                     else => {
+                        self.index -= 1;
                         state = .Identifier;
                     },
                 },
test/translate_c.zig
@@ -1362,12 +1362,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
     cases.add("basic macro function",
         \\extern int c;
         \\#define BASIC(c) (c*2)
+        \\#define FOO(L,b) (L + b)
     , &[_][]const u8{
         \\pub extern var c: c_int;
     ,
         \\pub inline fn BASIC(c_1: var) @TypeOf(c_1 * 2) {
         \\    return c_1 * 2;
         \\}
+    ,
+        \\pub inline fn FOO(L: var, b: var) @TypeOf(L + b) {
+        \\    return L + b;
+        \\}
     });
 
     cases.add("macro defines string literal with hex",