prism_parser/core/
context.rs

1use crate::grammar::action_result::ActionResult;
2use crate::parser::var_map::VarMap;
3use std::hash::{Hash, Hasher};
4use std::ops::{Deref, DerefMut};
5
6#[derive(Clone)]
7pub struct PR<'arn, 'grm> {
8    pub free: VarMap<'arn, 'grm>,
9    pub rtrn: &'arn ActionResult<'arn, 'grm>,
10}
11
12impl<'arn, 'grm> PR<'arn, 'grm> {
13    pub fn with_rtrn(rtrn: &'arn ActionResult<'arn, 'grm>) -> Self {
14        Self {
15            free: VarMap::default(),
16            rtrn,
17        }
18    }
19}
20
21#[derive(Eq, PartialEq, Hash, Clone, Copy)]
22pub struct ParserContext {
23    pub(crate) recovery_disabled: bool,
24    pub(crate) layout_disabled: bool,
25}
26
27impl Default for ParserContext {
28    fn default() -> Self {
29        Self::new()
30    }
31}
32
33impl ParserContext {
34    pub fn new() -> Self {
35        Self {
36            recovery_disabled: false,
37            layout_disabled: false,
38        }
39    }
40}
41
42#[derive(Clone, Copy)]
43pub struct Ignore<T>(pub T);
44
45impl<T> Hash for Ignore<T> {
46    fn hash<H: Hasher>(&self, _: &mut H) {}
47}
48
49impl<T> PartialEq for Ignore<T> {
50    fn eq(&self, _: &Self) -> bool {
51        true
52    }
53}
54
55impl<T> Eq for Ignore<T> {}
56
57impl<T> Deref for Ignore<T> {
58    type Target = T;
59
60    fn deref(&self) -> &Self::Target {
61        &self.0
62    }
63}
64
65impl<T> DerefMut for Ignore<T> {
66    fn deref_mut(&mut self) -> &mut Self::Target {
67        &mut self.0
68    }
69}