Skip to content

Commit fa377db

Browse files
Vexuandrewrk
authored andcommitted
fix c tokenizer bug
1 parent 1fb7049 commit fa377db

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/std/c/tokenizer.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ pub const Tokenizer = struct {
651651
state = .StringLiteral;
652652
},
653653
else => {
654+
self.index -= 1;
654655
state = .Identifier;
655656
},
656657
},
@@ -660,6 +661,7 @@ pub const Tokenizer = struct {
660661
state = .StringLiteral;
661662
},
662663
else => {
664+
self.index -= 1;
663665
state = .Identifier;
664666
},
665667
},
@@ -673,6 +675,7 @@ pub const Tokenizer = struct {
673675
state = .StringLiteral;
674676
},
675677
else => {
678+
self.index -= 1;
676679
state = .Identifier;
677680
},
678681
},
@@ -686,6 +689,7 @@ pub const Tokenizer = struct {
686689
state = .StringLiteral;
687690
},
688691
else => {
692+
self.index -= 1;
689693
state = .Identifier;
690694
},
691695
},

test/translate_c.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13621362
cases.add("basic macro function",
13631363
\\extern int c;
13641364
\\#define BASIC(c) (c*2)
1365+
\\#define FOO(L,b) (L + b)
13651366
, &[_][]const u8{
13661367
\\pub extern var c: c_int;
13671368
,
13681369
\\pub inline fn BASIC(c_1: var) @TypeOf(c_1 * 2) {
13691370
\\ return c_1 * 2;
13701371
\\}
1372+
,
1373+
\\pub inline fn FOO(L: var, b: var) @TypeOf(L + b) {
1374+
\\ return L + b;
1375+
\\}
13711376
});
13721377

13731378
cases.add("macro defines string literal with hex",

0 commit comments

Comments
 (0)