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
|
/* Generated by re2rust */
// re2rust $INPUT -o $OUTPUT --api simple
fn lex_unsigned(yyinput: &[u8]) -> bool {
let mut yycursor = 0;
{
#[allow(unused_assignments)]
let mut yych : u8 = 0;
let mut yystate : usize = 0;
'yyl: loop {
match yystate {
0 => {
yych = unsafe {*yyinput.get_unchecked(yycursor)};
yycursor += 1;
if yych >= 0xFF {
yystate = 1;
continue 'yyl;
}
{ return false; }
}
1 => { return true; },
_ => panic!("internal lexer error"),
}
}
}
}
#[allow(overflowing_literals)]
fn lex_signed(yyinput: &[u8]) -> bool {
let mut yycursor = 0;
{
#[allow(unused_assignments)]
let mut yych : i8 = 0;
let mut yystate : usize = 0;
'yyl: loop {
match yystate {
0 => {
yych = unsafe {*yyinput.get_unchecked(yycursor)} as i8;
yycursor += 1;
if yych >= 0xFF {
yystate = 1;
continue 'yyl;
}
{ return false; }
}
1 => { return true; },
_ => panic!("internal lexer error"),
}
}
}
}
fn main() {
assert!(!lex_unsigned(b"a\0")); // ok, 'a' should not match
assert!(lex_signed(b"a\0")); // error, 'a' does match
}
|