syntax highlighting editor exports

This commit is contained in:
jess 2026-05-30 20:55:33 -07:00
parent d30420324a
commit 48a871186b
2 changed files with 25 additions and 4 deletions

View File

@ -399,7 +399,7 @@ impl super::EditorState {
pub(super) fn build_eval_interpreter(&self, block_idx: usize) -> acord_core::interp::Interpreter {
use acord_core::interp;
let mut eval_interp = interp::Interpreter::new();
let mut eval_interp = self.new_eval_interpreter();
let block_id = match self.layout.get(block_idx) {
Some(&id) => id,
None => return eval_interp,
@ -451,7 +451,7 @@ impl super::EditorState {
return interp::ModuleExports::default();
}
let mut interp = interp::Interpreter::new();
let mut interp = self.new_eval_interpreter();
if !module.is_root {
if let Some(root) = self.modules.iter().find(|m| m.is_root) {
@ -541,7 +541,7 @@ impl super::EditorState {
});
if let Some(submod) = submodule_match {
let mut nested = interp::Interpreter::new();
let mut nested = self.new_eval_interpreter();
for d in interp::extract_use_declarations(&clean) {
self.apply_use_decl(&d, visited, &mut nested);
}
@ -557,7 +557,7 @@ impl super::EditorState {
return;
}
let mut nested = interp::Interpreter::new();
let mut nested = self.new_eval_interpreter();
for d in interp::extract_use_declarations(&clean) {
self.apply_use_decl(&d, visited, &mut nested);
}

View File

@ -115,6 +115,8 @@ pub struct EditorState {
pub(super) heavy_token: u64,
/// deferred-rebuild arm; set on edit, cleared on debounce fire.
pub(super) heavy_pending: bool,
/// setup applied to every interpreter the editor builds for eval.
pub(super) interp_setup: Option<std::rc::Rc<dyn Fn(&mut acord_core::interp::Interpreter)>>,
}
impl EditorState {
@ -184,9 +186,28 @@ impl EditorState {
syntax_rules: crate::syntax::SyntaxRules::cordial(),
heavy_token: 0,
heavy_pending: false,
interp_setup: None,
}
}
/// installs a routine run on each fresh eval interpreter — register hooks,
/// provide shared state, seed vars, add module paths.
pub fn set_interpreter_setup<F>(&mut self, setup: F)
where
F: Fn(&mut acord_core::interp::Interpreter) + 'static,
{
self.interp_setup = Some(std::rc::Rc::new(setup));
}
/// fresh interpreter with the registered project setup applied.
pub(super) fn new_eval_interpreter(&self) -> acord_core::interp::Interpreter {
let mut i = acord_core::interp::Interpreter::new();
if let Some(setup) = &self.interp_setup {
setup(&mut i);
}
i
}
/// replaces the active syntax rule set.
pub fn set_syntax_rules(&mut self, rules: crate::syntax::SyntaxRules) {
self.syntax_rules = rules;