summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src/discouraged.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/syn/src/discouraged.rs')
-rw-r--r--vendor/syn/src/discouraged.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/vendor/syn/src/discouraged.rs b/vendor/syn/src/discouraged.rs
index a46129b6a..fb98d6332 100644
--- a/vendor/syn/src/discouraged.rs
+++ b/vendor/syn/src/discouraged.rs
@@ -1,6 +1,7 @@
//! Extensions to the parsing API with niche applicability.
use super::*;
+use proc_macro2::extra::DelimSpan;
/// Extensions to the `ParseStream` API to support speculative parsing.
pub trait Speculative {
@@ -192,3 +193,27 @@ impl<'a> Speculative for ParseBuffer<'a> {
.set(unsafe { mem::transmute::<Cursor, Cursor<'static>>(fork.cursor()) });
}
}
+
+/// Extensions to the `ParseStream` API to support manipulating invisible
+/// delimiters the same as if they were visible.
+pub trait AnyDelimiter {
+ /// Returns the delimiter, the span of the delimiter token, and the nested
+ /// contents for further parsing.
+ fn parse_any_delimiter(&self) -> Result<(Delimiter, DelimSpan, ParseBuffer)>;
+}
+
+impl<'a> AnyDelimiter for ParseBuffer<'a> {
+ fn parse_any_delimiter(&self) -> Result<(Delimiter, DelimSpan, ParseBuffer)> {
+ self.step(|cursor| {
+ if let Some((content, delimiter, span, rest)) = cursor.any_group() {
+ let scope = crate::buffer::close_span_of_group(*cursor);
+ let nested = crate::parse::advance_step_cursor(cursor, content);
+ let unexpected = crate::parse::get_unexpected(self);
+ let content = crate::parse::new_parse_buffer(scope, nested, unexpected);
+ Ok(((delimiter, span, content), rest))
+ } else {
+ Err(cursor.error("expected any delimiter"))
+ }
+ })
+ }
+}