Skip to main content

read_primitive_token

Function read_primitive_token 

Source
pub fn read_primitive_token() -> Result<Option<Token>>
Expand description

Read a token as a primitive reads one: tex.web §365 get_token under the current ScannerStatus (\let, \futurelet, \afterassignment, \aftergroup, \expandafter, a Token parameter). An input level that ends here closes (§362 end_file_reading) and §336 check_outer_validity looks at the status:

  • normal: no runaway; the read goes on in the enclosing input, as read_token_across_input_ends reads, so a primitive that is the last token of an \input file takes its token from the input that follows;
  • defining, absorbing, aligning: the scan in progress ran off the file, and the primitive’s read meets it: the runaway is reported there and TeX’s recovery tokens are read (recover_at_file_end), so an \edef\x{\expandafter at a file’s end reads the inserted } and \x is empty, as in pdflatex;
  • matching: TeX reads a macro’s arguments without expanding, so it gives no primitive’s read this status, but Rust does: an expandable primitive with typed parameters (\csname CSName, \number Number, \readline … Token) reads them at matching, set by Expandable::read_call_arguments. The read stops at the file’s end (a residual: \csname a\expandafter as a file’s last tokens does not cross), and so does a macro’s Token argument (the macro gets \relax, the Token parameter’s end value).

\ifx and \ifdefined read at normal whatever the status (§507), with read_token_across_input_ends. The status is consulted only once the current input has run out.

Guards: token_kernel_gaps::*.