use std::ops::{Deref, DerefMut}; use crate::common::FileID; use super::{ CompilerMsg, CompilerOutput, MaybeParsable, Node, NodeParseResult, Parsable, ParsableWith, TokenCursor, }; pub struct ParserCtx<'a> { pub cursor: TokenCursor<'a>, pub output: &'a mut CompilerOutput, } impl<'a> Deref for ParserCtx<'a> { type Target = TokenCursor<'a>; fn deref(&self) -> &Self::Target { &self.cursor } } impl DerefMut for ParserCtx<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cursor } } impl<'a> ParserCtx<'a> { pub fn err(&mut self, msg: CompilerMsg) { self.output.err(msg); } pub fn hint(&mut self, msg: CompilerMsg) { self.output.hint(msg); } pub fn parse(&mut self) -> NodeParseResult { Node::parse(self) } pub fn parse_with(&mut self, data: T::Data) -> NodeParseResult { Node::parse_with(self, data) } pub fn maybe_parse(&mut self) -> Option> { Node::maybe_parse(self) } pub fn new(file: FileID, string: &'a str, output: &'a mut CompilerOutput) -> Self { Self { cursor: TokenCursor::from_file_str(file, string), output, } } }