Skip to content

Commit

Permalink
gather repetition groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Oct 26, 2024
1 parent bce4b17 commit 3c7a254
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 1 deletion.
27 changes: 26 additions & 1 deletion expandable-impl/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Architectural invariant: this module contains types that are useful for error
// reporting and nothing else.

use proc_macro2::{Span, TokenTree};
use proc_macro2::TokenTree;

use crate::{RepetitionQuantifierKind, Terminal, grammar::TokenDescription};

Expand Down Expand Up @@ -76,6 +76,31 @@ pub enum Error<Span = proc_macro2::Span> {
where_: Span,
},

/// A metavariable is defined at a lower depth than it is used at. At any given repetition
/// depth, it is only possible to use metavariables defined at the same or higher depth.
#[non_exhaustive]
MetavariableDefinedAtLowerDepth {
/// The name of the metavariable that was used.
name: String,
/// Where it was defined.
definition_span: Span,
/// Where it was used.
usage_span: Span,
/// The depth at which the metavariable was defined.
definition_depth: usize,
/// The depth at which the metavariable was used.
usage_depth: usize,
},

/// A repetition group (nor other repetitions nested into it) doesn't refer to any metavariable
/// defined at the same depth in the match arm. This means it's not possible to determine how
/// much that repetition should be repeated.
#[non_exhaustive]
RepetitionWithoutMetavariables {
/// Where the repetition is defined.
span: Span,
},

/// A variable is being repeated with a sequence of operator that does not
/// match the one used when the variable was declared.
///
Expand Down
10 changes: 10 additions & 0 deletions expandable-impl/src/expand/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod repetition_groups;

use crate::token_tree::TokenTree;
use crate::expand::repetition_groups::RepetitionGroups;

#[expect(dead_code)]
pub(crate) fn expand(matcher: Vec<TokenTree>, transcriber: Vec<TokenTree>) -> Vec<Vec<TokenTree>> {
let _ = RepetitionGroups::new(&matcher, &transcriber);
todo!();
}
Loading

0 comments on commit 3c7a254

Please sign in to comment.