pub struct Mouth { /* private fields */ }Implementations§
Source§impl Mouth
impl Mouth
Sourcepub fn copy_for_a_rollback(&mut self) -> Mouth
pub fn copy_for_a_rollback(&mut self) -> Mouth
A copy of this mouth, to read on while this one stays where it is (state::input_stream_to_change): a file it reads from
disk is opened again at the same offset; one that cannot be ends where the lines it holds end, enough for a run about to
be undone.
Source§impl Mouth
impl Mouth
pub fn create(source: &str, options: MouthOptions) -> Result<Self>
Sourcepub fn foodtype(&self) -> FoodType
pub fn foodtype(&self) -> FoodType
What kind of source feeds this mouth (file vs literal/string injection).
Sourcepub fn is_file_level(&self) -> bool
pub fn is_file_level(&self) -> bool
Whether this mouth reads a file (see MouthOptions::file_level).
Sourcepub fn is_document_text(&self) -> bool
pub fn is_document_text(&self) -> bool
Whether this mouth reads the document’s own text: a content file (binding::content::load_tex_content, the
converter’s in-memory source), its notes on and not read for definitions — no package’s, class’s or binding’s.
pub fn new(text: &str, options: Option<MouthOptions>) -> Result<Self>
Sourcepub fn with_bib_data_literals(self) -> Self
pub fn with_bib_data_literals(self) -> Self
Read % & # as ordinary characters (catcode 12) instead of comment,
alignment tab and parameter, for the whole life of this mouth.
Treatment 1 of two (see OXIDIZED_DESIGN #74): this is “be bibtex”.
BibTeX’s lexer interprets only braces and the entry/field delimiters — it
has no comment syntax inside an entry (% is significant only in the junk
BETWEEN entries, Pre::BibTeX::skipJunk), no alignment and no parameters.
So a field value it hands back is a string in which all three are ordinary
characters: a percent-encoded URL, a publisher’s name (“Taylor &
Francis”), an issue number.
Re-injected as TeX source (BibTeX.pool’s \bibentry@create) under the
default catcodes, each misfires: % (14) comments out the rest of its
line — the field’s own closing brace included — so the entry’s group never
closes; & (4) is a stray alignment tab and is dropped; # (6) reaches
the Stomach as a parameter token. Reading the injected text with all three
neutralized preserves the value BibTeX actually parsed, without altering
a byte of it.
_ is deliberately NOT in this set, and the reason is the boundary
between the two treatments. A catcode is decided at tokenization, before
anything knows whether it is inside $…$ — and a subscript in a .bib
title’s math (title = {Bounds on $x_1+x_2$}) is legitimate TeX that
must keep working. _ therefore belongs to treatment 2
(bibtex.rs::escape_bib_data_specials), which walks the value and skips
math spans. Measured: putting _ here silently flattened every
subscript in a bibliography title. The other three have no legitimate
meaning inside a .bib field, in math or out.
A \catcode in the injected text cannot do this job either: the catcode
would still be a State assignment, so a raw .sty opened from inside a
field handler would inherit it — and so would the document. Scoping to the
Mouth keeps the rule attached to the text that BibTeX lexed, which is
exactly where it belongs.
Only the TeX-special meaning is removed: a character that has been given
some other catcode (LETTER, say) keeps it. And \%, \&, \# still
work, because the backslash is untouched.
pub fn get_source(&self) -> &str
pub fn open(&mut self, content: &str) -> Result<()>
Sourcepub fn stop_reading(&mut self)
pub fn stop_reading(&mut self)
Stop reading from this mouth: clear buffers and close file handle. Called by flush_mouth (\endinput) to prevent further reading. Does NOT restore catcodes — that’s done by finish().
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Fully finish this mouth: stop reading AND restore catcodes/state. Called by close_mouth when the mouth is popped from the stack.
Sourcepub fn read_position(&self) -> (usize, usize, usize, usize)
pub fn read_position(&self) -> (usize, usize, usize, usize)
How far this mouth has read: its line, its column, the characters of the line still to read, and the lines still
buffered. Only compared with an earlier reading of the same mouth (gullet::input_unread_since): it changes
whenever a character or a line is read.
Sourcepub fn has_more_input(&mut self) -> bool
pub fn has_more_input(&mut self) -> bool
Checks if there is more input to process.
Note: we need mutability, as we may refill the internal BufReader when performing the check.
Sourcepub fn read_token(&mut self) -> Option<Token>
pub fn read_token(&mut self) -> Option<Token>
Read the next token, or undef if exhausted. Note that this also returns COMMENT tokens containing source comments, and also locator comments (file, line# info). LaTeXML::Core::Gullet intercepts them and passes them on at appropriate times.
Sourcepub fn read_tokens(&mut self) -> Tokens
pub fn read_tokens(&mut self) -> Tokens
Read all tokens until a token equal to $until (if given), or until exhausted. Returns an empty Tokens list, if there is no input
Sourcepub fn read_raw_line_from_start(&mut self) -> Option<String>
pub fn read_raw_line_from_start(&mut self) -> Option<String>
The WHOLE current line as raw text, from column 0 — including the part
already tokenized — and consume the rest of it. None when no line is
loaded. Used by the listings raw-line reader when an optional-argument
probe has already tokenized the body’s first token (OXIDIZED_DESIGN #162).
Sourcepub fn read_raw_line_decoded(&mut self, noread: bool) -> Option<String>
pub fn read_raw_line_decoded(&mut self, noread: bool) -> Option<String>
read_raw_line with the line’s input bytes turned
into the characters the declared input encoding makes of them
(eight_bit_input_char, as the tokenizer does for a byte line). For a
consumer that parses raw lines itself: a .bib, whose bytes real bibtex
copies into the .bbl for the document’s inputenc to decode. A cp1251
.bib under \usepackage[cp1251]{inputenc} read Ò. Ñ. Ãåéäåìàí for
“Т. С. Гейдеман” (shipunov/rusnat-ex1-ru, sweep #121).
Sourcepub fn decode_eight_bit(&self, text: String) -> String
pub fn decode_eight_bit(&self, text: String) -> String
text with its upper-half bytes (read as U+0080..U+00FF) turned into
the characters the declared input encoding makes of them, when this
mouth reads a byte line; unchanged otherwise.
Sourcepub fn restore_line_rest(&mut self, rest: &str)
pub fn restore_line_rest(&mut self, rest: &str)
Make rest — the end of the line a raw read just took — the current line again, with the \endlinechar a
line is read with (Self::read_token), so tokens and raw lines are read from it before the next line. Its
columns count from the start of rest (the line number is the line’s).
Sourcepub fn peek_text(&self, max_lines: usize, max_chars: usize) -> String
pub fn peek_text(&self, max_lines: usize, max_chars: usize) -> String
The source text this mouth will read next — the rest of the current line, then up to max_lines lines after it,
joined by \n, at most max_chars characters in all — without reading it: nothing is consumed, tokenized or
decoded in place. A look-ahead for a decision about what follows (stomach.rs formula_continues_past_par,
OXIDIZED_DESIGN #553); max_chars keeps its cost bounded on a source whose current line is the whole document.
Lines not yet decoded are read as UTF-8, lossily; their structure ($, \int, _) is all a look-ahead needs.
A current line read to its end contributes nothing: its end-of-line character is read already, and an empty line
in its place would tokenize as one more (a \par, or under \obeylines an active ^^M; hep-ph9809328).
pub fn read_raw_line(&mut self, noread: bool) -> Option<String>
Sourcepub fn finish_physical_line(&mut self)
pub fn finish_physical_line(&mut self)
Checks if Mouth read is at the end of a line.
Careful:
used BOTH for flushing input for \endinput
and for detecting line end for \read
tex.web §485-486: a \read consumes the WHOLE physical line
(input_ln); the catcode regime only decides which tokens the line
yields. Called by \read after its token loop so a residual
\endlinechar character left behind under one regime (an IGNORE-catcode
space under \ExplSyntaxOn) is never re-read as a spurious empty line by
a later \read under another (l3prefixes: header \ior_get in the
preamble, \ior_map_inline in the body → an empty first row →
Until:, runaway).
pub fn is_eol(&mut self) -> bool
pub fn at_eof(&self) -> bool
Sourcepub fn line_number(&self) -> usize
pub fn line_number(&self) -> usize
The number of the line the Mouth is reading (1-based once the first line is fetched).
Sourcepub fn last_token_start(&self) -> (usize, usize)
pub fn last_token_start(&self) -> (usize, usize)
Where the most recently begun token starts: (line, 0-based column).
Sourcepub fn get_locator_from_start(&self) -> Locator
pub fn get_locator_from_start(&self) -> Locator
§1 accurate-start locator (docs/performance/SOURCE_PROVENANCE.md): from = the captured
start of the most recently begun token (last_token_start), to = the
mouth’s current position. Unlike get_locator, whose from is the
eating-disorder heuristic (line start vs current col), this from is exact
for the token currently being processed — the basis for accurate
construct-start ranges under --source-map. lineno is already 1-indexed
(it counts from 1 after the first line fetch); colno is 0-indexed, +1 to
1-indexed columns, matching get_locator.
pub fn get_location(&self) -> String
Trait Implementations§
Source§impl Object for Mouth
impl Object for Mouth
fn stringify(&self) -> String
Source§fn get_locator(&self) -> Option<Locator>
fn get_locator(&self) -> Option<Locator>
None is the honest
“no recorded source position” (replacing the old Locator::default()
file!()/line!() sentinel). For “where the parser is now” (error
reporting, box creation), use the free fn gullet::get_locator().fn isa_box(&self) -> bool
fn is_expandable(&self) -> bool
fn is_definition(&self) -> bool
fn is_comment(&self) -> bool
fn be_digested(self) -> Result<Digested>
Source§fn get_origin(&self) -> DefinitionOrigin
fn get_origin(&self) -> DefinitionOrigin
definition::origin). The
default is Unknown, which counts as LaTeXML’s own.