1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// Generated by re2zig
// re2zig $INPUT -o $OUTPUT --header lexer/state.zig
const std = @import("std");
const state = @import("lexer/state.zig"); // the module is generated by re2c
fn lex(yyrecord: *state.State) usize {
var t: usize = 0;
var yych: u8 = 0;
var yystate: u32 = 0;
yyl: while (true) {
switch (yystate) {
0 => {
yych = yyrecord.yyinput[yyrecord.yycursor];
switch (yych) {
0x61 => {
yyrecord.yycursor += 1;
yystate = 0;
continue :yyl;
},
0x62 => {
yyrecord.yyt1 = yyrecord.yycursor;
yyrecord.yycursor += 1;
yystate = 2;
continue :yyl;
},
else => {
yyrecord.yyt1 = yyrecord.yycursor;
yystate = 1;
continue :yyl;
},
}
},
1 => {
t = yyrecord.yyt1;
return t;
},
2 => {
yych = yyrecord.yyinput[yyrecord.yycursor];
switch (yych) {
0x62 => {
yyrecord.yycursor += 1;
yystate = 2;
continue :yyl;
},
else => {
yystate = 1;
continue :yyl;
},
}
},
else => { @panic("internal lexer error"); },
}
}
}
test {
var st = state.State {
.yyinput = "ab",
.yycursor = 0,
.yyt1 = 0,
};
try std.testing.expectEqual(lex(&st), 1);
}
// Generated by re2zig
pub const State = struct {
yyinput: [:0]const u8,
yycursor: usize,
yyt1: usize,
};
zig/headers/header.re:22:21: warning: rule matches empty string [-Wmatch-empty-string]
|