use super::*;
impl Parser<'_, '_, '_, '_> {
pub(in crate::parser) fn current_function(&self) -> &FunctionContext {
self.contexts
.functions
.last()
.unwrap_or(&self.contexts.root_function)
}
pub(in crate::parser) fn current_function_mut(&mut self) -> &mut FunctionContext {
if let Some(function) = self.contexts.functions.last_mut() {
function
} else {
&mut self.contexts.root_function
}
}
pub(in crate::parser) fn in_loop(&self) -> bool {
self.current_function().loop_depth > 0
}
pub(in crate::parser) fn in_vararg_function(&self) -> bool {
self.current_function().vararg
}
pub(in crate::parser) fn update_end_mismatch_suspect(&mut self) {
let Some(context) = self.contexts.blocks.last().copied() else {
return;
};
if self.current_line() == context.line || self.current_column() == context.column {
return;
}
if context.opener == "then" {
return;
}
if self.contexts.end_mismatch_suspect.is_none() {
self.contexts.end_mismatch_suspect = Some(context);
}
}
pub(in crate::parser) fn enter_recursion(&mut self, context: &'static str) -> Result<usize> {
let old = self.contexts.recursion_counter;
self.contexts.recursion_counter += 1;
if self.contexts.recursion_counter > flags::LuauRecursionLimit.get() as usize {
return Err(self.located(format!(
"Exceeded allowed recursion depth; simplify your {context} to make the code compile"
)));
}
Ok(old)
}
}