Skip to main content

rustex_lib/engine/
state.rs

1use crate::engine::commands::CLOSE_FONT;
2use crate::engine::{CSName, Font, Types};
3use tex_engine::commands::primitives::{PrimitiveCommands, PrimitiveIdentifier};
4use tex_engine::commands::{PrimitiveCommand, TeXCommand};
5use tex_engine::engine::mouth::Mouth;
6use tex_engine::engine::state::{GroupType, State, StateChangeTracker, StateStack};
7use tex_engine::engine::{EngineAux, EngineTypes, state};
8use tex_engine::prelude::*;
9use tex_engine::tex::catcodes::{CategoryCode, CategoryCodeScheme};
10use tex_engine::tex::nodes::boxes::TeXBox;
11use tex_engine::tex::numerics::{Dim32, Mu, MuSkip, Skip};
12use tex_engine::tex::tokens::CompactToken;
13use tex_engine::tex::tokens::Token;
14use tex_engine::tex::tokens::control_sequences::CSNameVec;
15
16#[derive(Clone)]
17pub struct RusTeXState(state::tex_state::DefaultState<Types>);
18impl RusTeXState {
19    pub fn destruct(self) -> CSNameVec<u8, TeXCommand<Types>> {
20        self.0.commands
21    }
22    pub fn set_command_direct(&mut self, name: CSName, cmd: Option<TeXCommand<Types>>) {
23        self.0.set_command_direct(name, cmd)
24    }
25}
26impl StateChangeTracker<Types> for RusTeXState {
27    fn stack(&mut self) -> &mut StateStack<Types> {
28        self.0.stack()
29    }
30}
31impl State<Types> for RusTeXState {
32    fn new(nullfont: Font, aux: &mut EngineAux<Types>) -> Self {
33        Self(state::tex_state::DefaultState::new(nullfont, aux))
34    }
35    fn register_primitive(
36        &mut self,
37        aux: &mut EngineAux<Types>,
38        name: &'static str,
39        cmd: PrimitiveCommand<Types>,
40    ) {
41        self.0.register_primitive(aux, name, cmd);
42    }
43
44    fn get_par_token(&self) -> <Types as EngineTypes>::CSName {
45        self.0.get_par_token()
46    }
47    fn set_par_token(&mut self, par: <Types as EngineTypes>::CSName) {
48        self.0.set_par_token(par);
49    }
50
51    fn primitives(&self) -> &PrimitiveCommands<Types> {
52        self.0.primitives()
53    }
54
55    fn aftergroup(&mut self, token: CompactToken) {
56        self.0.aftergroup(token);
57    }
58
59    fn push(&mut self, aux: &mut EngineAux<Types>, group_type: GroupType, line_number: usize) {
60        self.0.push(aux, group_type, line_number);
61        aux.extension.push();
62    }
63
64    fn pop(&mut self, aux: &mut EngineAux<Types>, mouth: &mut <Types as EngineTypes>::Mouth) {
65        self.0.pop(aux, mouth);
66        let closefont = CompactToken::from_cs(aux.memory.cs_interner_mut().cs_from_str(CLOSE_FONT));
67        for _ in 0..aux.extension.pop() {
68            mouth.requeue(closefont);
69        }
70    }
71
72    fn get_group_type(&self) -> Option<GroupType> {
73        self.0.get_group_type()
74    }
75
76    fn get_group_level(&self) -> usize {
77        self.0.get_group_level()
78    }
79
80    fn get_current_font(&self) -> &Font {
81        self.0.get_current_font()
82    }
83
84    fn get_textfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
85        self.0.get_textfont(i)
86    }
87
88    fn set_textfont(
89        &mut self,
90        aux: &mut EngineAux<Types>,
91        idx: u8,
92        fnt: <Types as EngineTypes>::Font,
93        globally: bool,
94    ) {
95        self.0.set_textfont(aux, idx, fnt, globally);
96    }
97
98    fn get_scriptfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
99        self.0.get_scriptfont(i)
100    }
101
102    fn set_scriptfont(
103        &mut self,
104        aux: &mut EngineAux<Types>,
105        idx: u8,
106        fnt: <Types as EngineTypes>::Font,
107        globally: bool,
108    ) {
109        self.0.set_scriptfont(aux, idx, fnt, globally);
110    }
111
112    fn get_scriptscriptfont(&self, i: u8) -> &<Types as EngineTypes>::Font {
113        self.0.get_scriptscriptfont(i)
114    }
115
116    fn set_scriptscriptfont(
117        &mut self,
118        aux: &mut EngineAux<Types>,
119        idx: u8,
120        fnt: <Types as EngineTypes>::Font,
121        globally: bool,
122    ) {
123        self.0.set_scriptscriptfont(aux, idx, fnt, globally);
124    }
125
126    fn set_current_font(&mut self, aux: &mut EngineAux<Types>, fnt: Font, globally: bool) {
127        self.0.set_current_font(aux, fnt, globally);
128    }
129
130    fn get_catcode_scheme(&self) -> &CategoryCodeScheme<u8> {
131        self.0.get_catcode_scheme()
132    }
133
134    fn set_catcode(&mut self, aux: &EngineAux<Types>, c: u8, cc: CategoryCode, globally: bool) {
135        self.0.set_catcode(aux, c, cc, globally);
136    }
137
138    fn get_sfcode(&self, c: u8) -> u16 {
139        self.0.get_sfcode(c)
140    }
141
142    fn set_sfcode(&mut self, aux: &EngineAux<Types>, c: u8, sfcode: u16, globally: bool) {
143        self.0.set_sfcode(aux, c, sfcode, globally);
144    }
145
146    fn get_lccode(&self, c: u8) -> u8 {
147        self.0.get_lccode(c)
148    }
149
150    fn set_lccode(&mut self, aux: &EngineAux<Types>, c: u8, lccode: u8, globally: bool) {
151        self.0.set_lccode(aux, c, lccode, globally);
152    }
153
154    fn get_uccode(&self, c: u8) -> u8 {
155        self.0.get_uccode(c)
156    }
157
158    fn set_uccode(&mut self, aux: &EngineAux<Types>, c: u8, uccode: u8, globally: bool) {
159        self.0.set_uccode(aux, c, uccode, globally);
160    }
161
162    fn get_delcode(&self, c: u8) -> i32 {
163        self.0.get_delcode(c)
164    }
165
166    fn set_delcode(&mut self, aux: &EngineAux<Types>, c: u8, delcode: i32, globally: bool) {
167        self.0.set_delcode(aux, c, delcode, globally);
168    }
169
170    fn get_mathcode(&self, c: u8) -> u32 {
171        self.0.get_mathcode(c)
172    }
173
174    fn set_mathcode(&mut self, aux: &EngineAux<Types>, c: u8, mathcode: u32, globally: bool) {
175        self.0.set_mathcode(aux, c, mathcode, globally);
176    }
177
178    fn get_endline_char(&self) -> Option<u8> {
179        self.0.get_endline_char()
180    }
181
182    fn set_endline_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
183        self.0.set_endline_char(aux, c, globally);
184    }
185
186    fn get_escape_char(&self) -> Option<u8> {
187        self.0.get_escape_char()
188    }
189
190    fn set_escape_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
191        self.0.set_escape_char(aux, c, globally);
192    }
193
194    fn get_newline_char(&self) -> Option<u8> {
195        self.0.get_newline_char()
196    }
197
198    fn set_newline_char(&mut self, aux: &EngineAux<Types>, c: Option<u8>, globally: bool) {
199        self.0.set_newline_char(aux, c, globally);
200    }
201
202    fn get_parshape(&self) -> &Vec<(Dim32, Dim32)> {
203        self.0.get_parshape()
204    }
205
206    fn take_parshape(&mut self) -> Vec<(Dim32, Dim32)> {
207        self.0.take_parshape()
208    }
209
210    fn set_parshape(
211        &mut self,
212        aux: &EngineAux<Types>,
213        parshape: Vec<(Dim32, Dim32)>,
214        globally: bool,
215    ) {
216        self.0.set_parshape(aux, parshape, globally);
217    }
218
219    fn get_int_register(&self, idx: usize) -> i32 {
220        self.0.get_int_register(idx)
221    }
222
223    fn set_int_register(&mut self, aux: &EngineAux<Types>, idx: usize, v: i32, globally: bool) {
224        self.0.set_int_register(aux, idx, v, globally);
225    }
226
227    fn get_primitive_int(&self, name: PrimitiveIdentifier) -> i32 {
228        self.0.get_primitive_int(name)
229    }
230
231    fn set_primitive_int(
232        &mut self,
233        aux: &EngineAux<Types>,
234        name: PrimitiveIdentifier,
235        v: i32,
236        globally: bool,
237    ) {
238        self.0.set_primitive_int(aux, name, v, globally);
239    }
240
241    fn get_dim_register(&self, idx: usize) -> Dim32 {
242        self.0.get_dim_register(idx)
243    }
244
245    fn set_dim_register(&mut self, aux: &EngineAux<Types>, idx: usize, v: Dim32, globally: bool) {
246        self.0.set_dim_register(aux, idx, v, globally);
247    }
248
249    fn get_skip_register(&self, idx: usize) -> Skip<Dim32> {
250        self.0.get_skip_register(idx)
251    }
252
253    fn set_skip_register(
254        &mut self,
255        aux: &EngineAux<Types>,
256        idx: usize,
257        v: Skip<Dim32>,
258        globally: bool,
259    ) {
260        self.0.set_skip_register(aux, idx, v, globally);
261    }
262
263    fn get_muskip_register(&self, idx: usize) -> MuSkip<Mu> {
264        self.0.get_muskip_register(idx)
265    }
266
267    fn set_muskip_register(
268        &mut self,
269        aux: &EngineAux<Types>,
270        idx: usize,
271        v: MuSkip<Mu>,
272        globally: bool,
273    ) {
274        self.0.set_muskip_register(aux, idx, v, globally);
275    }
276    fn get_toks_register(&self, idx: usize) -> &TokenList<CompactToken> {
277        self.0.get_toks_register(idx)
278    }
279    fn set_toks_register(
280        &mut self,
281        aux: &EngineAux<Types>,
282        idx: usize,
283        v: TokenList<CompactToken>,
284        globally: bool,
285    ) {
286        self.0.set_toks_register(aux, idx, v, globally);
287    }
288
289    fn get_box_register(&self, idx: usize) -> Option<&TeXBox<Types>> {
290        self.0.get_box_register(idx)
291    }
292
293    fn get_box_register_mut(&mut self, idx: usize) -> Option<&mut TeXBox<Types>> {
294        self.0.get_box_register_mut(idx)
295    }
296
297    fn take_box_register(&mut self, idx: usize) -> Option<TeXBox<Types>> {
298        self.0.take_box_register(idx)
299    }
300
301    fn set_box_register(
302        &mut self,
303        aux: &EngineAux<Types>,
304        idx: usize,
305        v: Option<TeXBox<Types>>,
306        globally: bool,
307    ) {
308        self.0.set_box_register(aux, idx, v, globally);
309    }
310
311    fn get_primitive_dim(&self, name: PrimitiveIdentifier) -> Dim32 {
312        self.0.get_primitive_dim(name)
313    }
314
315    fn set_primitive_dim(
316        &mut self,
317        aux: &EngineAux<Types>,
318        name: PrimitiveIdentifier,
319        v: Dim32,
320        globally: bool,
321    ) {
322        self.0.set_primitive_dim(aux, name, v, globally);
323    }
324
325    fn get_primitive_skip(&self, name: PrimitiveIdentifier) -> Skip<Dim32> {
326        self.0.get_primitive_skip(name)
327    }
328
329    fn set_primitive_skip(
330        &mut self,
331        aux: &EngineAux<Types>,
332        name: PrimitiveIdentifier,
333        v: Skip<Dim32>,
334        globally: bool,
335    ) {
336        self.0.set_primitive_skip(aux, name, v, globally);
337    }
338
339    fn get_primitive_muskip(&self, name: PrimitiveIdentifier) -> MuSkip<Mu> {
340        self.0.get_primitive_muskip(name)
341    }
342
343    fn set_primitive_muskip(
344        &mut self,
345        aux: &EngineAux<Types>,
346        name: PrimitiveIdentifier,
347        v: MuSkip<Mu>,
348        globally: bool,
349    ) {
350        self.0.set_primitive_muskip(aux, name, v, globally);
351    }
352
353    fn get_primitive_tokens(&self, name: PrimitiveIdentifier) -> &TokenList<CompactToken> {
354        self.0.get_primitive_tokens(name)
355    }
356
357    fn set_primitive_tokens(
358        &mut self,
359        aux: &EngineAux<Types>,
360        name: PrimitiveIdentifier,
361        v: TokenList<CompactToken>,
362        globally: bool,
363    ) {
364        self.0.set_primitive_tokens(aux, name, v, globally);
365    }
366
367    fn get_command(&self, name: &CSName) -> Option<&TeXCommand<Types>> {
368        self.0.get_command(name)
369    }
370
371    fn set_command(
372        &mut self,
373        aux: &EngineAux<Types>,
374        name: CSName,
375        cmd: Option<TeXCommand<Types>>,
376        globally: bool,
377    ) {
378        self.0.set_command(aux, name, cmd, globally);
379    }
380
381    fn get_ac_command(&self, c: u8) -> Option<&TeXCommand<Types>> {
382        self.0.get_ac_command(c)
383    }
384
385    fn set_ac_command(
386        &mut self,
387        aux: &EngineAux<Types>,
388        c: u8,
389        cmd: Option<TeXCommand<Types>>,
390        globally: bool,
391    ) {
392        self.0.set_ac_command(aux, c, cmd, globally);
393    }
394}