Rename the crate, binary, core crate, font families, env vars, and internal commands from texcraft/tex-engine to texrra. Serve the separately versioned texrra-web frontend from TEXRRA_WEB_DIR, ../web, or ./web instead of embedding index.html. Add starred section heading support and an arXiv template conformance fixture.
86 lines
2.4 KiB
Rust
86 lines
2.4 KiB
Rust
/// Assignment scope selected by TeX prefixes and `\\globaldefs`.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub enum AssignmentScopeKind {
|
|
Local,
|
|
Global,
|
|
}
|
|
|
|
impl Default for AssignmentScopeKind {
|
|
fn default() -> Self {
|
|
Self::Local
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
|
pub struct AssignmentScope {
|
|
global_defs: i32,
|
|
global_prefix_pending: bool,
|
|
long_prefix_pending: bool,
|
|
outer_prefix_pending: bool,
|
|
groups: Vec<AssignmentScopeGroup>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
|
struct AssignmentScopeGroup {
|
|
global_defs: Option<i32>,
|
|
}
|
|
|
|
impl AssignmentScope {
|
|
pub fn global_defs(&self) -> &i32 {
|
|
&self.global_defs
|
|
}
|
|
|
|
pub fn request_prefixes(&mut self, global: bool, long: bool, outer: bool) {
|
|
self.global_prefix_pending |= global;
|
|
self.long_prefix_pending |= long;
|
|
self.outer_prefix_pending |= outer;
|
|
}
|
|
|
|
pub fn take_prefixed_scope(&mut self) -> AssignmentScopeKind {
|
|
if std::mem::take(&mut self.global_prefix_pending) {
|
|
AssignmentScopeKind::Global
|
|
} else {
|
|
AssignmentScopeKind::Local
|
|
}
|
|
}
|
|
|
|
pub fn take_macro_prefixes(&mut self) -> (bool, bool) {
|
|
(
|
|
std::mem::take(&mut self.long_prefix_pending),
|
|
std::mem::take(&mut self.outer_prefix_pending),
|
|
)
|
|
}
|
|
|
|
pub fn global_defs_mut(&mut self, global: bool) -> &mut i32 {
|
|
if global {
|
|
for group in &mut self.groups {
|
|
group.global_defs = None;
|
|
}
|
|
} else if let Some(group) = self.groups.last_mut() {
|
|
group.global_defs.get_or_insert(self.global_defs);
|
|
}
|
|
&mut self.global_defs
|
|
}
|
|
|
|
pub fn override_scope(&self, requested: AssignmentScopeKind) -> AssignmentScopeKind {
|
|
match self.global_defs.cmp(&0) {
|
|
std::cmp::Ordering::Less => AssignmentScopeKind::Local,
|
|
std::cmp::Ordering::Equal => requested,
|
|
std::cmp::Ordering::Greater => AssignmentScopeKind::Global,
|
|
}
|
|
}
|
|
|
|
pub fn begin_group(&mut self) {
|
|
self.groups.push(AssignmentScopeGroup::default());
|
|
}
|
|
|
|
pub fn end_group(&mut self) {
|
|
let Some(group) = self.groups.pop() else {
|
|
return;
|
|
};
|
|
if let Some(global_defs) = group.global_defs {
|
|
self.global_defs = global_defs;
|
|
}
|
|
}
|
|
}
|