Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse_parens, parse_braces, parse_brackets and structs returned by them are public API now. #1592

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@ use crate::token;
use proc_macro2::extra::DelimSpan;
use proc_macro2::Delimiter;

// Not public API.
#[doc(hidden)]
/// The rust code enclosed in parentheses
pub struct Parens<'a> {
#[doc(hidden)]
/// Paren token '(' and ')'
pub token: token::Paren,
#[doc(hidden)]

/// Inner content
pub content: ParseBuffer<'a>,
}

// Not public API.
#[doc(hidden)]
/// The rust code enclosed in braces
pub struct Braces<'a> {
#[doc(hidden)]
/// Brace token '{' and '}'
pub token: token::Brace,
#[doc(hidden)]

/// Inner content
pub content: ParseBuffer<'a>,
}

// Not public API.
#[doc(hidden)]
/// The rust code enclosed in brackets
pub struct Brackets<'a> {
#[doc(hidden)]
/// Bracket token ']' and '['
pub token: token::Bracket,
#[doc(hidden)]

/// Inner content
pub content: ParseBuffer<'a>,
}

// Not public API.
#[cfg(any(feature = "full", feature = "derive"))]
#[doc(hidden)]
pub struct Group<'a> {
Expand All @@ -41,26 +40,27 @@ pub struct Group<'a> {
pub content: ParseBuffer<'a>,
}

// Not public API.
#[doc(hidden)]
/// Parse a set of parentheses and expose their content to subsequent parsers.
/// Use it instead of parenthesized! macro when you want to handle Err yourself
pub fn parse_parens<'a>(input: &ParseBuffer<'a>) -> Result<Parens<'a>> {
parse_delimited(input, Delimiter::Parenthesis).map(|(span, content)| Parens {
token: token::Paren(span),
content,
})
}

// Not public API.
#[doc(hidden)]
/// Parse a set of curly braces and expose their content to subsequent parsers.
/// Use it instead of braced! macro when you want to handle Err yourself
pub fn parse_braces<'a>(input: &ParseBuffer<'a>) -> Result<Braces<'a>> {
parse_delimited(input, Delimiter::Brace).map(|(span, content)| Braces {
token: token::Brace(span),
content,
})
}

// Not public API.
#[doc(hidden)]
/// Parse a set of square brackets and expose their content to subsequent
/// parsers.
/// Use it instead of bracketed! macro when you want to handle Err yourself
pub fn parse_brackets<'a>(input: &ParseBuffer<'a>) -> Result<Brackets<'a>> {
parse_delimited(input, Delimiter::Bracket).map(|(span, content)| Brackets {
token: token::Bracket(span),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ mod macros;
#[cfg(feature = "parsing")]
#[macro_use]
mod group;
#[cfg(feature = "parsing")]
pub use crate::group::{parse_braces, parse_brackets, parse_parens, Braces, Brackets, Parens};

#[macro_use]
pub mod token;
Expand Down