pest3_generator/
lib.rs

1//! Generator for [pest3].
2
3#![warn(rust_2018_idioms, rust_2021_compatibility, missing_docs)]
4#![allow(unused)]
5mod common;
6mod config;
7mod expr;
8mod state_builder;
9pub mod typed;
10mod types;
11
12struct State<'i> {
13    input: &'i [u8],
14    index: usize,
15    result: bool,
16}
17
18macro_rules! peek {
19    ( $state:expr, $callback:expr ) => {
20        match $state.input.get($state.index) {
21            Some(&val) => val,
22            None => return $callback($state),
23        }
24    };
25}
26
27macro_rules! pop {
28    ( $state:expr, $callback:expr ) => {
29        match $state.input.get($state.index) {
30            Some(&val) => {
31                let val = $state.input[$state.index];
32                $state.index += 1;
33                val
34            }
35            None => return $callback($state),
36        }
37    };
38}
39
40impl<'i> State<'i> {
41    pub fn new(input: &'i str) -> Self {
42        Self {
43            input: input.as_bytes(),
44            index: 0,
45            result: true,
46        }
47    }
48
49    pub fn json(state: &mut Self) {
50        const LUT: [fn(&mut State<'_>); 256] = [State::error; 256];
51
52        if peek!(state, Self::error) == b'c' {
53            println!("hi");
54        }
55
56        if pop!(state, Self::error) == b'c' {
57            println!("hi");
58        }
59    }
60
61    pub fn error(state: &mut State<'_>) {
62        state.result = false;
63    }
64}