Skip to content

Commit

Permalink
Refactor fold and walk APIs.
Browse files Browse the repository at this point in the history
This change moves fold APIs into the `walk` module, integrates folding
with `BranchSequencer` (previously `Enqueue`), and implements the
`starting` and `ending` iterators via `BranchSequencer` instead of
`filter_tree_map`.

With these changes, `has_root` has also been reimplemented and now
returns `When` instead of `bool`.
  • Loading branch information
olson-sean-k committed Jan 27, 2024
1 parent 4a0b29b commit a10f507
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 509 deletions.
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use thiserror::Error;
use crate::encode::CompileError;
use crate::rule::{Checked, RuleError};
use crate::token::{
ConcatenationTree, ExpressionMetadata, ParseError, Text, Token, TokenTree, Tokenized,
ConcatenationTree, ExpressionMetadata, ParseError, Text, Token, TokenTree, Tokenized, When,
};
#[cfg(feature = "walk")]
use crate::walk::WalkError;
Expand Down Expand Up @@ -750,12 +750,10 @@ impl<'t> Glob<'t> {
/// As with Unix paths, a glob expression has a root if it begins with a separator `/`.
/// Patterns other than separators may also root an expression, such as `/**` or `</root:1,>`.
pub fn has_root(&self) -> bool {
self.tree
.as_ref()
.as_token()
.concatenation()
.first()
.map_or(false, Token::has_root)
match self.tree.as_ref().as_token().has_root() {
When::Always => true,
_ => false,
}
}

/// Returns `true` if the glob has literals that have non-nominal semantics on the target
Expand Down
1 change: 1 addition & 0 deletions src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//!
//! Most rules concern alternatives, which have complex interactions with neighboring tokens.
// TODO: Use the term "branch" instead of "group".
// TODO: The `check` function fails fast and either report no errors or exactly one error. To
// better support diagnostics, `check` should probably perform an exhaustive analysis and
// report zero or more errors.
Expand Down
Loading

0 comments on commit a10f507

Please sign in to comment.