1use boxworks_text as bwt;
2use texlang::prelude as txl;
3use texlang::traits::*;
4use texlang::*;
5
6#[derive(Default)]
7pub struct Component {
8 text_preprocessor: bwt::TextPreprocessorImpl,
9}
10
11pub fn get_sfcode<S: HasComponent<Component>>() -> command::BuiltIn<S> {
13 variable::Command::new_array(
14 ref_fn,
15 mut_fn,
16 variable::IndexResolver::Dynamic(resolver_fn),
17 )
18 .into()
19}
20
21fn ref_fn<S: HasComponent<Component>>(state: &S, index: variable::Index) -> &i32 {
22 state
23 .component()
24 .text_preprocessor
25 .space_factor_codes
26 .0
27 .get(index.0)
28 .unwrap()
29}
30
31fn mut_fn<S: HasComponent<Component>>(state: &mut S, index: variable::Index) -> &mut i32 {
32 state
33 .component_mut()
34 .text_preprocessor
35 .space_factor_codes
36 .0
37 .get_mut(index.0)
38 .unwrap()
39}
40
41fn resolver_fn<S: HasComponent<Component>>(
42 _: token::Token,
43 input: &mut vm::ExpandedStream<S>,
44) -> txl::Result<variable::Index> {
45 let index = parse::Uint::<256>::parse(input)?;
46 Ok(index.0.into())
47}