Struct flexi_parse::group::Group

source ·
pub struct Group<D> { /* private fields */ }
Expand description

A delimited group.

For more information, see the module documentation.

Implementations§

source§

impl<D: Delimiters> Group<D>

source

pub fn into_token_stream(self) -> TokenStream

Returns the contained TokenStream.

Examples found in repository?
examples/calc.rs (line 89)
81
82
83
84
85
86
87
88
89
90
91
92
93
fn primary(input: ParseStream) -> Result<Expr> {
    let lookahead = input.lookahead();
    if lookahead.peek(token::LitFloat) {
        Ok(Expr::Num(input.parse::<token::LitFloat>()?.value()))
    } else if lookahead.peek(token::LitInt) {
        Ok(Expr::Num(input.parse::<token::LitInt>()?.value() as f64))
    } else if lookahead.peek(token::LeftParen) {
        let group: Group<Parentheses> = input.parse()?;
        parse(group.into_token_stream())
    } else {
        Err(lookahead.error())
    }
}
More examples
Hide additional examples
examples/lox/main.rs (line 438)
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    fn parse(input: ParseStream) -> Result<Self> {
        let name: Ident = input.parse()?;
        let mut contents: Group<Parentheses> = input.parse()?;
        contents.remove_whitespace();
        let Parentheses(span) = contents.delimiters();
        let tokens = contents.into_token_stream();
        let params: Vec<Ident> = if tokens.is_empty() {
            vec![]
        } else {
            let params: Punctuated<Ident, Punct![","]> =
                Punctuated::parse_separated.parse(tokens)?;
            params.into_iter().collect()
        };
        if params.len() >= 255 {
            input.add_error(input.new_error(
                "Can't have more than 254 parameters".to_string(),
                span,
                error_codes::TOO_MANY_ARGS,
            ));
        }
        let mut contents: Group<Braces> = input.parse()?;
        contents.remove_whitespace();
        let body = block.parse(contents.into_token_stream())?;
        Ok(Function { name, params, body })
    }
source

pub fn delimiters(&self) -> D

Returns a token representing the delimiters of this group.

Examples found in repository?
examples/lox/main.rs (line 437)
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    fn parse(input: ParseStream) -> Result<Self> {
        let name: Ident = input.parse()?;
        let mut contents: Group<Parentheses> = input.parse()?;
        contents.remove_whitespace();
        let Parentheses(span) = contents.delimiters();
        let tokens = contents.into_token_stream();
        let params: Vec<Ident> = if tokens.is_empty() {
            vec![]
        } else {
            let params: Punctuated<Ident, Punct![","]> =
                Punctuated::parse_separated.parse(tokens)?;
            params.into_iter().collect()
        };
        if params.len() >= 255 {
            input.add_error(input.new_error(
                "Can't have more than 254 parameters".to_string(),
                span,
                error_codes::TOO_MANY_ARGS,
            ));
        }
        let mut contents: Group<Braces> = input.parse()?;
        contents.remove_whitespace();
        let body = block.parse(contents.into_token_stream())?;
        Ok(Function { name, params, body })
    }
source

pub fn remove_whitespace(&mut self)

Removes all whitespace from the TokenStream in self.

Examples found in repository?
examples/lox/main.rs (line 436)
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    fn parse(input: ParseStream) -> Result<Self> {
        let name: Ident = input.parse()?;
        let mut contents: Group<Parentheses> = input.parse()?;
        contents.remove_whitespace();
        let Parentheses(span) = contents.delimiters();
        let tokens = contents.into_token_stream();
        let params: Vec<Ident> = if tokens.is_empty() {
            vec![]
        } else {
            let params: Punctuated<Ident, Punct![","]> =
                Punctuated::parse_separated.parse(tokens)?;
            params.into_iter().collect()
        };
        if params.len() >= 255 {
            input.add_error(input.new_error(
                "Can't have more than 254 parameters".to_string(),
                span,
                error_codes::TOO_MANY_ARGS,
            ));
        }
        let mut contents: Group<Braces> = input.parse()?;
        contents.remove_whitespace();
        let body = block.parse(contents.into_token_stream())?;
        Ok(Function { name, params, body })
    }
source

pub fn without_whitespace(self) -> Group<D>

Consumes self, returning a new Group<D> with all whitespace removed.

Trait Implementations§

source§

impl<D: Clone> Clone for Group<D>

source§

fn clone(&self) -> Group<D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<D: Debug> Debug for Group<D>

source§

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

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

impl<D> Hash for Group<D>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<D: Delimiters> Parse for Group<D>

source§

fn parse(input: ParseStream<'_>) -> Result<Self>

Parses the input into this type. Read more
source§

impl<D> PartialEq for Group<D>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<D> PartialOrd for Group<D>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<D> Eq for Group<D>

Auto Trait Implementations§

§

impl<D> RefUnwindSafe for Group<D>
where D: RefUnwindSafe,

§

impl<D> Send for Group<D>
where D: Send,

§

impl<D> Sync for Group<D>
where D: Sync,

§

impl<D> Unpin for Group<D>
where D: Unpin,

§

impl<D> UnwindSafe for Group<D>
where D: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.