aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-02-13 10:17:51 +0100
committerPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-03-30 13:52:29 +0200
commit08ccfe9c65d8a8d934a403b40d0a4549e3c642d1 (patch)
treef4c3ba18810775e77c71e7d4e5a673089a8f260d
parentf7152d606c82e2c0b9c57d6c2e8f30ab90214553 (diff)
downloadgcc-08ccfe9c65d8a8d934a403b40d0a4549e3c642d1.zip
gcc-08ccfe9c65d8a8d934a403b40d0a4549e3c642d1.tar.gz
gcc-08ccfe9c65d8a8d934a403b40d0a4549e3c642d1.tar.bz2
libproc_macro: Move Spacing type to punct module
The spacing type is inherently linked to the Punct type and can therefore be moved to the punct module. This commit also add some documentation to the spacing type. ChangeLog: * librust/proc_macro/rust/lib.rs: Remove Spacing type. * librust/proc_macro/rust/punct.rs: Add Spacing type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--librust/proc_macro/rust/lib.rs8
-rw-r--r--librust/proc_macro/rust/punct.rs17
2 files changed, 16 insertions, 9 deletions
diff --git a/librust/proc_macro/rust/lib.rs b/librust/proc_macro/rust/lib.rs
index 1bb8e247..f79342e 100644
--- a/librust/proc_macro/rust/lib.rs
+++ b/librust/proc_macro/rust/lib.rs
@@ -1,6 +1,6 @@
pub use ident::Ident;
pub use literal::Literal;
-pub use punct::Punct;
+pub use punct::{Punct, Spacing};
pub use span::Span;
use std::error;
use std::fmt;
@@ -29,9 +29,3 @@ impl fmt::Display for LexError {
}
impl error::Error for LexError {}
-
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-pub enum Spacing {
- Alone,
- Joint,
-}
diff --git a/librust/proc_macro/rust/punct.rs b/librust/proc_macro/rust/punct.rs
index 1389122..24d6acb 100644
--- a/librust/proc_macro/rust/punct.rs
+++ b/librust/proc_macro/rust/punct.rs
@@ -1,14 +1,27 @@
use std::fmt;
-use Spacing;
use Span;
+/// Describes the context of a [`Punct`] relatively to the next token.
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub enum Spacing {
+ /// A [`Punct`] is not immediately followed by another `Punct`.
+ Alone,
+ /// A [`Punct`] is immediately followed by another `Punct` and can be
+ /// combined into a multi-character operator.
+ Joint,
+}
+
+/// Single punctuation character such as `+`, `-` or `#`.
+///
+/// Multi-character operators like `+=` are represented as two instances of
+/// `Punct` with different forms of `Spacing` returned.
#[derive(Clone)]
pub struct Punct {
// Internal implementation details.
}
impl Punct {
- /// Creates a new [Punct] from a given character and spacing.
+ /// Creates a new `Punct` from a given character and spacing.
///
/// # Arguments
///