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
#![doc = include_str!("../README.md")]
#![no_std]
extern crate alloc;
extern crate either;
#[cfg(feature = "regex")]
extern crate once_cell;
#[cfg(feature = "regex")]
extern crate regex;

#[doc(hidden)]
pub use either::Either;
#[cfg(all(feature = "regex", feature = "std"))]
#[doc(hidden)]
pub use once_cell::sync::Lazy;
#[cfg(feature = "regex")]
#[doc(hidden)]
pub use regex::Regex;

#[macro_use]
pub(crate) mod utils;
pub mod ast;
pub mod parse;
pub mod token;
pub(crate) mod internal_prelude {
    pub use alloc::{boxed::Box, vec::Vec};
}
pub mod error;
pub mod string_matcher;

pub use ast::{display_tree, parse_tree, Rule};
pub use parse::ParseError;
pub use token::Token;

#[cfg(feature = "regex")]
#[doc(hidden)]
#[macro_export]
macro_rules! _lazy_regex {
    ($vis:vis static ref $NAME:ident => $regex:expr;) => {
        $vis static $NAME: $crate::Lazy<$crate::Regex> = $crate::Lazy::new(|| $crate::Regex::new($regex).unwrap());
    };
}

#[cfg(all(feature = "regex", not(feature = "std")))]
mod _lazy {
    pub struct Lazy<T> {
        inner: once_cell::race::OnceBox<T>,
        init: fn() -> T,
    }

    impl<T> Lazy<T> {
        pub const fn new(init: fn() -> T) -> Self {
            Self {
                inner: once_cell::race::OnceBox::new(),
                init,
            }
        }
    }

    impl<T> core::ops::Deref for Lazy<T> {
        type Target = T;

        fn deref(&self) -> &Self::Target {
            self.inner.get_or_init(|| (self.init)().into())
        }
    }
}

#[cfg(all(feature = "regex", not(feature = "std")))]
#[doc(hidden)]
pub use _lazy::Lazy;