nanvm_lib/parser/
const_state.rs

1use super::{
2    any_state::{AnyResult, AnyState},
3    json_state::JsonState,
4    root_state::{RootState, RootStatus},
5};
6use crate::{mem::manager::Manager, tokenizer::JsonToken};
7
8pub struct ConstState<M: Manager> {
9    pub key: String,
10    pub state: AnyState<M>,
11}
12
13impl<M: Manager> ConstState<M> {
14    pub fn parse(self, manager: M, token: JsonToken<M::Dealloc>) -> JsonState<M> {
15        match token {
16            JsonToken::Semicolon => todo!(),
17            _ => {
18                // TODO: use import_path in place of _ below to track possible errors -
19                // or provide an explanation on why it's not necessary.
20                let (any_result, _) = self.state.parse(manager, token);
21                match any_result {
22                    AnyResult::Continue(state) => JsonState::ParseConst(ConstState {
23                        key: self.key,
24                        state,
25                    }),
26                    AnyResult::Success(mut success) => {
27                        success.state.consts.insert(self.key, success.value);
28                        JsonState::ParseRoot(RootState {
29                            status: RootStatus::Initial,
30                            state: success.state,
31                            new_line: false,
32                        })
33                    }
34                    AnyResult::Error(error) => JsonState::Error(error),
35                }
36            }
37        }
38    }
39}