Skip to content

Commit

Permalink
Wrap comments at column 100.
Browse files Browse the repository at this point in the history
This change reformats comments such that they wrap at column 100 (like
code) rather than column 80.
  • Loading branch information
olson-sean-k committed Sep 30, 2023
1 parent 291513d commit f45600c
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 575 deletions.
46 changes: 20 additions & 26 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,18 @@ impl From<OwnedText> for MaybeOwnedText<'static> {

/// Text that has been matched by a [`Pattern`] and its captures.
///
/// To match a [`Glob`] or other [`Pattern`] against a [`CandidatePath`] and get
/// the matched text, use the [`Pattern::matched`] function.
/// To match a [`Glob`] or other [`Pattern`] against a [`CandidatePath`] and get the matched text,
/// use the [`Pattern::matched`] function.
///
/// All [`Pattern`]s provide an implicit capture of the complete text of a
/// match. This implicit capture has index zero, and is exposed via the
/// [`complete`] function as well as the [`get`] function using index zero.
/// Capturing tokens are indexed starting at one, and can be used to isolate
/// more specific sub-text.
/// All [`Pattern`]s provide an implicit capture of the complete text of a match. This implicit
/// capture has index zero, and is exposed via the [`complete`] function as well as the [`get`]
/// function using index zero. Capturing tokens are indexed starting at one, and can be used to
/// isolate more specific sub-text.
///
/// # Examples
///
/// Capturing tokens and matched text can be used to isolate sub-text in a
/// match. For example, the file name of a match can be extracted using an
/// alternative to group patterns.
/// Capturing tokens and matched text can be used to isolate sub-text in a match. For example, the
/// file name of a match can be extracted using an alternative to group patterns.
///
/// ```rust
/// use wax::{CandidatePath, Glob, Pattern};
Expand Down Expand Up @@ -125,10 +123,9 @@ impl<'t> MatchedText<'t> {

/// Clones any borrowed data to an owning instance.
///
/// This function is similar to [`into_owned`], but does not consume its
/// receiver. Due to a technical limitation, `MatchedText` cannot implement
/// [`Clone`], so this function is provided as a stop gap that allows a
/// distinct instance to be created that owns its data.
/// This function is similar to [`into_owned`], but does not consume its receiver. Due to a
/// technical limitation, `MatchedText` cannot implement [`Clone`], so this function is
/// provided as a stop gap that allows a distinct instance to be created that owns its data.
///
/// [`Clone`]: std::clone::Clone
/// [`into_owned`]: crate::MatchedText::into_owned
Expand All @@ -142,9 +139,8 @@ impl<'t> MatchedText<'t> {

/// Gets the complete text of a match.
///
/// All [`Pattern`]s have an implicit capture of the complete text at index
/// zero. This function is therefore equivalent to unwrapping the output of
/// the [`get`] function with index zero.
/// All [`Pattern`]s have an implicit capture of the complete text at index zero. This function
/// is therefore equivalent to unwrapping the output of the [`get`] function with index zero.
///
/// [`get`]: crate::MatchedText::get
/// [`Pattern`]: crate::Pattern
Expand All @@ -154,16 +150,14 @@ impl<'t> MatchedText<'t> {

/// Gets the matched text of a capture at the given index.
///
/// All [`Pattern`]s have an implicit capture of the complete text at index
/// zero. Capturing tokens are indexed from one, so any capturing
/// sub-expression will be indexed after the implicit complete text. For
/// example, the sub-expression `*` in the glob expression `*.txt` is at
/// index one and will exclude the suffix `.txt` in its matched text.
/// All [`Pattern`]s have an implicit capture of the complete text at index zero. Capturing
/// tokens are indexed from one, so any capturing sub-expression will be indexed after the
/// implicit complete text. For example, the sub-expression `*` in the glob expression `*.txt`
/// is at index one and will exclude the suffix `.txt` in its matched text.
///
/// Alternative and repetition patterns group their sub-globs into a single
/// capture, so it is not possible to isolate matched text from their
/// sub-globs. This can be used to explicitly group matched text, such as
/// isolating an entire matched file name using an expression like
/// Alternative and repetition patterns group their sub-globs into a single capture, so it is
/// not possible to isolate matched text from their sub-globs. This can be used to explicitly
/// group matched text, such as isolating an entire matched file name using an expression like
/// `{*.{go,rs}}`.
///
/// [`Pattern`]: crate::Pattern
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/miette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub fn diagnose<'i, 't>(
mod tests {
use crate::Glob;

// It is non-trivial to downcast `&dyn Diagnostic`, so diagnostics are
// identified in tests by their code.
// It is non-trivial to downcast `&dyn Diagnostic`, so diagnostics are identified in tests by
// their code.
const CODE_SEMANTIC_LITERAL: &str = "wax::glob::semantic_literal";
const CODE_TERMINATING_SEPARATOR: &str = "wax::glob::terminating_separator";

Expand Down
16 changes: 7 additions & 9 deletions src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub use crate::diagnostics::miette::diagnose;

/// Location and length of a token within a glob expression.
///
/// Spans are encoded as a tuple of `usize`s, where the first element is the
/// location or position and the second element is the length. Both position and
/// length are measured in bytes and **not** code points, graphemes, etc.
/// Spans are encoded as a tuple of `usize`s, where the first element is the location or position
/// and the second element is the length. Both position and length are measured in bytes and
/// **not** code points, graphemes, etc.
///
/// # Examples
///
Expand Down Expand Up @@ -44,18 +44,16 @@ impl SpanExt for Span {

/// Error associated with a [`Span`] within a glob expression.
///
/// Located errors describe specific instances of an error within a glob
/// expression. Types that implement this trait provide a location within a glob
/// expression via the [`LocatedError::span`] function as well as a description
/// via the [`Display`] trait. See [`BuildError::locations`].
/// Located errors describe specific instances of an error within a glob expression. Types that
/// implement this trait provide a location within a glob expression via the [`LocatedError::span`]
/// function as well as a description via the [`Display`] trait. See [`BuildError::locations`].
///
/// [`BuildError::locations`]: crate::BuildError::locations
/// [`Display`]: std::fmt::Display
/// [`LocatedError::span`]: crate::LocatedError::span
/// [`Span`]: crate::Span
pub trait LocatedError: Display {
/// Gets the span within the glob expression with which the error is
/// associated.
/// Gets the span within the glob expression with which the error is associated.
fn span(&self) -> Span;
}

Expand Down
38 changes: 17 additions & 21 deletions src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ const SEPARATOR_CLASS_EXPRESSION: &str = "/\\\\";
#[cfg(unix)]
const SEPARATOR_CLASS_EXPRESSION: &str = "/";

// This only encodes the platform's main separator, so any additional separators
// will be missed. It may be better to have explicit platform support and invoke
// `compile_error!` on unsupported platforms, as this could cause very aberrant
// behavior. Then again, it seems that platforms using more than one separator
// are rare. GS/OS, OS/2, and Windows are likely the best known examples and of
// those only Windows is a supported Rust target at the time of writing (and is
// already supported by Wax).
// This only encodes the platform's main separator, so any additional separators will be missed. It
// may be better to have explicit platform support and invoke `compile_error!` on unsupported
// platforms, as this could cause very aberrant behavior. Then again, it seems that platforms using
// more than one separator are rare. GS/OS, OS/2, and Windows are likely the best known examples
// and of those only Windows is a supported Rust target at the time of writing (and is already
// supported by Wax).
#[cfg(not(any(windows, unix)))]
const SEPARATOR_CLASS_EXPRESSION: &str = main_separator_class_expression();

#[cfg(not(any(windows, unix)))]
const fn main_separator_class_expression() -> &'static str {
use std::path::MAIN_SEPARATOR;

// TODO: This is based upon `regex_syntax::is_meta_character`, but that
// function is not `const`. Perhaps that can be changed upstream.
// TODO: This is based upon `regex_syntax::is_meta_character`, but that function is not
// `const`. Perhaps that can be changed upstream.
const fn escape(x: char) -> &'static str {
match x {
'\\' | '.' | '+' | '*' | '?' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$'
Expand All @@ -56,9 +55,8 @@ macro_rules! nsepexpr {

/// Describes errors that occur when compiling a glob expression.
///
/// **This error only occurs when the size of the compiled program is too
/// large.** All other compilation errors are considered internal bugs and will
/// panic.
/// **This error only occurs when the size of the compiled program is too large.** All other
/// compilation errors are considered internal bugs and will panic.
#[derive(Clone, Debug, Error)]
#[error("failed to compile glob: {kind}")]
pub struct CompileError {
Expand Down Expand Up @@ -176,8 +174,8 @@ fn encode<'t, A, T>(
pattern.push(')');
}

// TODO: Use `Grouping` everywhere a group is encoded. For invariant groups
// that ignore `grouping`, construct a local `Grouping` instead.
// TODO: Use `Grouping` everywhere a group is encoded. For invariant groups that ignore
// `grouping`, construct a local `Grouping` instead.
for (position, token) in tokens.into_iter().with_position() {
match (position, token.borrow().kind()) {
(_, Literal(literal)) => {
Expand Down Expand Up @@ -261,13 +259,11 @@ fn encode<'t, A, T>(
pattern.push_str(nsepexpr!("&&{0}"));
}
pattern.push(']');
// Compile the character class sub-expression. This may fail
// if the subtraction of the separator pattern yields an
// empty character class (meaning that the glob expression
// matches only separator characters on the target
// platform). If compilation fails, then use the null
// character class, which matches nothing on supported
// platforms.
// Compile the character class sub-expression. This may fail if the subtraction
// of the separator pattern yields an empty character class (meaning that the
// glob expression matches only separator characters on the target platform).
// If compilation fails, then use the null character class, which matches
// nothing on supported platforms.
if Regex::new(&pattern).is_ok() {
pattern.into()
}
Expand Down
Loading

0 comments on commit f45600c

Please sign in to comment.