pub struct Mouth { /* private fields */ }Implementations§
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).
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 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
pub fn read_raw_line(&mut self, noread: bool) -> Option<String>
Sourcepub fn is_eol(&mut self) -> bool
pub fn is_eol(&mut self) -> bool
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
pub fn at_eof(&self) -> bool
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().