[−][src]Struct rustc_parse_format::Parser

pub struct Parser<'a> {
    mode: ParseMode,
    input: &'a str,
    cur: Peekable<CharIndices<'a>>,
    pub errors: Vec<ParseError>,
    pub curarg: usize,
    style: Option<usize>,
    pub arg_places: Vec<InnerSpan>,
    skips: Vec<usize>,
    last_opening_brace: Option<InnerSpan>,
    append_newline: bool,
    pub is_literal: bool,
    cur_line_start: usize,
    pub line_spans: Vec<InnerSpan>,
}

The parser structure for interpreting the input format string. This is modeled as an iterator over Piece structures to form a stream of tokens being output.

This is a recursive-descent parser for the sake of simplicity, and if necessary there's probably lots of room for improvement performance-wise.

Fields

mode: ParseModeinput: &'a strcur: Peekable<CharIndices<'a>>errors: Vec<ParseError>

Error messages accumulated during parsing

curarg: usize

Current position of implicit positional argument pointer

style: Option<usize>

Some(raw count) when the string is "raw", used to position spans correctly

arg_places: Vec<InnerSpan>

Start and end byte offset of every successfully parsed argument

skips: Vec<usize>

Characters that need to be shifted

last_opening_brace: Option<InnerSpan>

Span of the last opening brace seen, used for error reporting

append_newline: bool

Whether the source string is comes from println! as opposed to format! or print!

is_literal: bool

Whether this formatting string is a literal or it comes from a macro.

cur_line_start: usize

Start position of the current line.

line_spans: Vec<InnerSpan>

Start and end byte offset of every line of the format string. Excludes newline characters and leading whitespace.

Implementations

impl<'a> Parser<'a>[src]

pub fn new(
    s: &'a str,
    style: Option<usize>,
    snippet: Option<String>,
    append_newline: bool,
    mode: ParseMode
) -> Parser<'a>ⓘ

Notable traits for Parser<'a>

impl<'a> Iterator for Parser<'a> type Item = Piece<'a>;
[src]

Creates a new parser for the given format string

pub(crate) fn err<S1: Into<String>, S2: Into<String>>(
    &mut self,
    description: S1,
    label: S2,
    span: InnerSpan
)
[src]

Notifies of an error. The message doesn't actually need to be of type String, but I think it does when this eventually uses conditions so it might as well start using it now.

pub(crate) fn err_with_note<S1: Into<String>, S2: Into<String>, S3: Into<String>>(
    &mut self,
    description: S1,
    label: S2,
    note: S3,
    span: InnerSpan
)
[src]

Notifies of an error. The message doesn't actually need to be of type String, but I think it does when this eventually uses conditions so it might as well start using it now.

pub(crate) fn consume(&mut self, c: char) -> bool[src]

Optionally consumes the specified character. If the character is not at the current position, then the current iterator isn't moved and false is returned, otherwise the character is consumed and true is returned.

pub(crate) fn consume_pos(&mut self, c: char) -> Option<usize>[src]

Optionally consumes the specified character. If the character is not at the current position, then the current iterator isn't moved and None is returned, otherwise the character is consumed and the current position is returned.

pub(crate) fn to_span_index(&self, pos: usize) -> InnerOffset[src]

pub(crate) fn must_consume(&mut self, c: char) -> Option<usize>[src]

Forces consumption of the specified character. If the character is not found, an error is emitted.

pub(crate) fn ws(&mut self)[src]

Consumes all whitespace characters until the first non-whitespace character

pub(crate) fn string(&mut self, start: usize) -> &'a str[src]

Parses all of a string which is to be considered a "raw literal" in a format string. This is everything outside of the braces.

pub(crate) fn argument(&mut self) -> Argument<'a>[src]

Parses an Argument structure, or what's contained within braces inside the format string.

pub(crate) fn position(&mut self) -> Option<Position>[src]

Parses a positional argument for a format. This could either be an integer index of an argument, a named argument, or a blank string. Returns Some(parsed_position) if the position is not implicitly consuming a macro argument, None if it's the case.

pub(crate) fn format(&mut self) -> FormatSpec<'a>[src]

Parses a format specifier at the current position, returning all of the relevant information in the FormatSpec struct.

pub(crate) fn inline_asm(&mut self) -> FormatSpec<'a>[src]

Parses an inline assembly template modifier at the current position, returning the modifier in the ty field of the FormatSpec struct.

pub(crate) fn count(&mut self, start: usize) -> (Count, Option<InnerSpan>)[src]

Parses a Count parameter at the current position. This does not check for 'CountIsNextParam' because that is only used in precision, not width.

pub(crate) fn word(&mut self) -> &'a str[src]

Parses a word starting at the current position. A word is the same as Rust identifier, except that it can't start with _ character.

pub(crate) fn integer(&mut self) -> Option<usize>[src]

Optionally parses an integer at the current position. This doesn't deal with overflow at all, it's just accumulating digits.

Trait Implementations

impl<'a> Iterator for Parser<'a>[src]

type Item = Piece<'a>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a> RefUnwindSafe for Parser<'a>

impl<'a> Send for Parser<'a>

impl<'a> Sync for Parser<'a>

impl<'a> Unpin for Parser<'a>

impl<'a> UnwindSafe for Parser<'a>

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator, 
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.