File: 01_basic_functions.re

package info (click to toggle)
re2c 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 50,052 kB
  • sloc: cpp: 32,477; ml: 8,279; sh: 5,265; makefile: 968; haskell: 612; python: 428; ansic: 227; javascript: 111; java: 3
file content (30 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (2)
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
// re2rust $INPUT -o $OUTPUT --no-unsafe -d

// Have to use Cell for cursor, otherwise borrow checker does not allow
// to have closures YYPEEK (that does immutable borrow of cursor) and
// YYSKIP (that does mutable borrow).
use std::cell::Cell;

#[allow(non_snake_case)]
fn lex(s: &[u8]) -> bool {
    let cur = Cell::new(0);
    let YYPEEK = || unsafe { *s.get_unchecked(cur.get()) };
    let YYSKIP = || { cur.set(cur.get() + 1); };
    let YYDEBUG = || { format!("lex: char '{}'", YYPEEK()); };

/*!re2c
    re2c:api:style = functions;
    re2c:define:YYCTYPE = u8;
    re2c:yyfill:enable = 0;

    alpha = [a-zA-Z];
    ident = alpha (alpha | [0-9])*;

    ident  { return true; }
    *      { return false; }
*/
}

fn main() {
    assert!(lex(b"qwerty42\0"));
}