Skip to main content

Mouth

Struct Mouth 

Source
pub struct Mouth { /* private fields */ }

Implementations§

Source§

impl Mouth

Source

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

Source

pub fn create(source: &str, options: MouthOptions) -> Result<Self>

Source

pub fn foodtype(&self) -> FoodType

What kind of source feeds this mouth (file vs literal/string injection).

Source

pub fn is_file_level(&self) -> bool

Whether this mouth reads a file (see MouthOptions::file_level).

Source

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.

Source

pub fn new(text: &str, options: Option<MouthOptions>) -> Result<Self>

Source

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.

Source

pub fn get_source(&self) -> &str

Source

pub fn open(&mut self, content: &str) -> Result<()>

Source

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().

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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).

Source

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).

Source

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.

Source

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).

Source

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).

Source

pub fn read_raw_line(&mut self, noread: bool) -> Option<String>

Source

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).

Source

pub fn is_eol(&mut self) -> bool

Source

pub fn at_eof(&self) -> bool

Source

pub fn line_number(&self) -> usize

The number of the line the Mouth is reading (1-based once the first line is fetched).

Source

pub fn last_token_start(&self) -> (usize, usize)

Where the most recently begun token starts: (line, 0-based column).

Source

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.

Source

pub fn get_location(&self) -> String

Trait Implementations§

Source§

impl Debug for Mouth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mouth

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Mouth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Mouth> for Stored

Source§

fn from(value: Mouth) -> Self

Converts to this type from the input type.
Source§

impl Object for Mouth

Source§

fn stringify(&self) -> String

Source§

fn get_locator(&self) -> Option<Locator>

The object’s stored source locator, if it has one. 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().
Source§

fn isa_box(&self) -> bool

Source§

fn is_expandable(&self) -> bool

Source§

fn is_definition(&self) -> bool

Source§

fn is_comment(&self) -> bool

Source§

fn be_digested(self) -> Result<Digested>
where Self: Sized + Debug,

Source§

fn get_origin(&self) -> DefinitionOrigin

Who made this definition (K1 provenance, definition::origin). The default is Unknown, which counts as LaTeXML’s own.
Source§

fn revert(&self) -> Result<Tokens>

each concrete object needs to provide its own path back to tokens
Source§

impl PartialEq for Mouth

Source§

fn eq(&self, other: &Mouth) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !Send for Mouth

§

impl !Sync for Mouth

§

impl Freeze for Mouth

§

impl RefUnwindSafe for Mouth

§

impl Unpin for Mouth

§

impl UnsafeUnpin for Mouth

§

impl UnwindSafe for Mouth

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.