texscanning.h /size: 10 Kb    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_SCANNING_H
6# define LMT_SCANNING_H
7
8typedef enum value_level_code {
9    posit_val_level,
10    integer_val_level,       /*tex integer values */
11    attribute_val_level,     /*tex integer values */
12    dimension_val_level,     /*tex dimension values */
13    glue_val_level,          /*tex glue specifications */
14    muglue_val_level,        /*tex math glue specifications */
15    token_val_level,         /*tex token lists */
16    font_val_level ,         /*tex font identifier */
17    mathspec_val_level ,
18    fontspec_val_level ,
19    specification_val_level, /*tex special purpose identifier */
20    list_val_level,
21    no_val_level,
22} value_level_code;
23
24# define first_value_level integer_val_level
25# define last_value_level  muglue_val_level
26
27typedef struct scanner_state_info {
28    int      current_cmd;       /*tex current command set by |get_next| */
29    halfword current_chr;       /*tex operand of current command */
30    halfword current_cs;        /*tex control sequence found here, zero if none foucan_tond */
31 // halfword current_flag;
32    halfword current_tok;       /*tex packed representative of |cur_cmd| and |cur_chr| */
33    int      current_val;       /*tex value returned by numeric scanners */
34    int      current_val_level; /*tex the level of this value */
35    halfword current_box;       /*tex the box to be placed into its context: */
36    halfword last_cs_name;      /*tex used in |\csname| and |\ifcsname| */
37    int      arithmic_error;
38    int      expression_depth;
39} scanner_state_info;
40
41extern scanner_state_info lmt_scanner_state;
42
43/*tex
44    These are rather basic \TEX\ The Program variables (aliases) so for now we stick to the
45    unqualified short names.
46*/
47
48# define cur_cmd       lmt_scanner_state.current_cmd
49# define cur_chr       lmt_scanner_state.current_chr
50# define cur_cs        lmt_scanner_state.current_cs
51# define cur_tok       lmt_scanner_state.current_tok
52# define cur_val       lmt_scanner_state.current_val
53# define cur_val_level lmt_scanner_state.current_val_level
54# define cur_box       lmt_scanner_state.current_box
55
56typedef struct full_scanner_status {
57    int      save_scanner_status;
58    halfword save_def_ref;
59    halfword save_warning_index;
60} full_scanner_status;
61
62static inline full_scanner_status tex_save_full_scanner_status(void)
63{
64    full_scanner_status a;
65    a.save_scanner_status = lmt_input_state.scanner_status;
66    a.save_def_ref        = lmt_input_state.def_ref;
67    a.save_warning_index  = lmt_input_state.warning_index;
68    return a;
69}
70
71static inline void tex_unsave_full_scanner_status(full_scanner_status a)
72{
73    lmt_input_state.warning_index  = a.save_warning_index;
74    lmt_input_state.def_ref        = a.save_def_ref;
75    lmt_input_state.scanner_status = a.save_scanner_status;
76}
77
78extern void        tex_scan_something_simple          (halfword cmd, halfword code);
79extern void        tex_scan_left_brace                (void);
80extern void        tex_scan_optional_equals           (void);
81extern int         tex_scan_cardinal                  (int optional_equal, unsigned *value, int dontbark);
82extern halfword    tex_scan_integer                   (int optional_equal, int *radix);
83extern void        tex_scan_integer_validate          (void);
84extern halfword    tex_scan_positive_integer          (int optional_equal);
85extern halfword    tex_scan_scale                     (int optional_equal);
86extern halfword    tex_scan_scale_factor              (int optional_equal);
87extern halfword    tex_scan_posit                     (int optional_equal);
88extern halfword    tex_scan_dimension                 (int mu, int inf, int shortcut, int optional_equal, halfword *order);
89extern void        tex_scan_dimension_validate        (void);
90extern halfword    tex_scan_glue                      (int level, int optional_equal, int options_too);
91extern halfword    tex_scan_font                      (int optional_equal);
92extern halfword    tex_scan_general_text              (halfword *tail);
93/*     halfword    tex_scan_toks                      (int macrodef, int xpand, int left_brace_found); */
94extern halfword    tex_scan_toks_normal               (int left_brace_found, halfword *tail);
95extern halfword    tex_scan_toks_expand               (int left_brace_found, halfword *tail, int expandconstant, int keepparameters);
96extern halfword    tex_scan_macro_normal              (void); // (int tolerant);
97extern halfword    tex_scan_macro_expand              (void); // (int tolerant);
98extern halfword    tex_scan_font_identifier           (halfword *spec);
99extern halfword    tex_scan_fontspec_identifier       (void);
100extern halfword    tex_scan_math_style_identifier     (int tolerant, int styles);
101extern halfword    tex_scan_math_parameter            (void);
102extern halfword    tex_scan_limited_scale             (int optional_equal);
103extern halfword    tex_scan_positive_scale            (int optional_equal);
104extern halfword    tex_scan_positive_number           (int optional_equal);
105extern halfword    tex_scan_parameter_index           (void);
106
107extern void        tex_initialize_units               (void);
108
109extern quarterword tex_scan_direction                 (int optional_equal);
110extern halfword    tex_scan_geometry                  (int optional_equal);
111extern halfword    tex_scan_orientation               (int optional_equal);
112extern halfword    tex_scan_anchor                    (int optional_equal);
113extern halfword    tex_scan_anchors                   (int optional_equal);
114
115extern int         tex_scanned_expression             (int level);
116
117extern halfword    tex_scan_integer_register_number   (void);
118extern halfword    tex_scan_dimension_register_number (void);
119extern halfword    tex_scan_attribute_register_number (void);
120extern halfword    tex_scan_posit_register_number     (void);
121extern halfword    tex_scan_glue_register_number      (void);
122extern halfword    tex_scan_muglue_register_number    (void);
123extern halfword    tex_scan_toks_register_number      (void);
124extern halfword    tex_scan_box_register_number       (void);
125extern halfword    tex_scan_unit_register_number      (int optional_equal);
126extern halfword    tex_scan_mark_number               (void);
127extern halfword    tex_scan_char_number               (int optional_equal);
128extern halfword    tex_scan_math_char_number          (void);
129extern halfword    tex_scan_math_family_number        (void);
130extern halfword    tex_scan_math_class_number         (int optional_equal);
131extern halfword    tex_scan_math_properties_number    (void);
132extern halfword    tex_scan_math_group_number         (void);
133extern halfword    tex_scan_math_index_number         (void);
134extern halfword    tex_scan_math_discretionary_number (int optional_equal);
135extern halfword    tex_scan_category_code             (int optional_equal);
136extern halfword    tex_scan_space_factor              (int optional_equal);
137extern singleword  tex_scan_box_index                 (void); /*tex For local boxes: small for now! */
138extern singleword  tex_scan_box_axis                  (void);
139extern halfword    tex_scan_function_reference        (int optional_equal);
140extern halfword    tex_scan_bytecode_reference        (int optional_equal);
141
142extern halfword    tex_the_value_toks                 (int unit, halfword *tail, halfword property); /* returns head */
143extern halfword    tex_the_toks                       (int code, halfword *tail); /* returns head */
144extern halfword    tex_the_detokenized_toks           (halfword *tail, int expand, int protect);
145extern void        tex_detokenize_list                (halfword head);
146extern strnumber   tex_the_scanned_result             (void);
147
148extern void        tex_set_font_dimension             (void);
149extern halfword    tex_get_font_dimension             (void);
150extern void        tex_set_scaled_font_dimension      (void);
151extern halfword    tex_get_scaled_font_dimension      (void);
152
153extern int         tex_get_unit_class                 (halfword index);
154
155extern int         tex_fract                          (int x, int n, int d, int max_answer);
156
157extern halfword    tex_scan_lua_value                 (int index);
158
159extern int         tex_scan_tex_value                 (halfword level, halfword *value);
160
161extern halfword    tex_scan_attribute                 (halfword attrlist);
162
163extern int         tex_valid_userunit                 (halfword cmd, halfword chr, halfword cs);
164extern int         tex_get_userunit                   (halfword index, scaled *value);
165
166extern int         tex_quotient                       (int n, int d, int round);
167
168/*
169# define token_is_digit(t)       ((t >= zero_token  ) && (t <= nine_token ))
170# define token_is_xdigit(t)     (((t >= zero_token  ) && (t <= nine_token )) || \
171                                 ((t >= a_token_l   ) && (t <= f_token_l  )) || \
172                                 ((t >= A_token_l   ) && (t <= F_token_l  )) || \
173                                 ((t >= a_token_o   ) && (t <= f_token_o  )) || \
174                                 ((t >= A_token_o   ) && (t <= F_token_o  )))
175# define token_is_exponent(t)    ((t == E_token_l   ) || (t == e_token_l  ) || \
176                                  (t == E_token_o   ) || (t == e_token_o  ))
177# define token_is_xexponent(t)   ((t == P_token_l   ) || (t == p_token_l  )  || \
178                                  (t == P_token_o   ) || (t == p_token_o  ))
179# define token_is_hexadecimal(t) ((t == X_token_l   ) || (t == x_token_l  )  || \
180                                  (t == X_token_o   ) || (t == x_token_o  ))
181# define token_is_sign(t)        ((t == minus_token ) || (t == plus_token ))
182# define token_is_seperator(t)   ((t == period_token) || (t == comma_token))
183*/
184
185static inline int tex_token_is_digit(halfword t)
186{
187    return (t >= zero_token) && (t <= nine_token);
188}
189
190static inline int tex_token_is_xdigit(halfword t) {
191    return ((t >= zero_token) && (t <= nine_token))
192        || ((t >= a_token_l ) && (t <= f_token_l))
193        || ((t >= A_token_l ) && (t <= F_token_l))
194        || ((t >= a_token_o ) && (t <= f_token_o))
195        || ((t >= A_token_o ) && (t <= F_token_o));
196}
197
198static inline int tex_token_is_exponent(halfword t)
199{
200    return (t == E_token_l) || (t == e_token_l)
201        || (t == E_token_o) || (t == e_token_o);
202}
203
204static inline int tex_token_is_xexponent(halfword t)
205{
206    return (t == P_token_l) || (t == p_token_l)
207        || (t == P_token_o) || (t == p_token_o);
208}
209
210 static inline int tex_token_is_hexadecimal(halfword t)
211{
212    return (t == X_token_l) || (t == x_token_l)
213        || (t == X_token_o) || (t == x_token_o);
214}
215
216static inline int tex_token_is_sign(halfword t) {
217    return (t == minus_token) || (t == plus_token);
218}
219
220static inline int tex_token_is_seperator(halfword t) {
221    return (t == period_token) || (t == comma_token);
222}
223
224static inline int tex_token_is_operator(halfword t) {
225    return (t == plus_token) || (t == minus_token) || (t == asterisk_token) || (t == slash_token) || (t == colon_token);
226}
227
228# endif
229
230