Skip to content

Commit

Permalink
run the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Jul 20, 2024
1 parent 7a744ff commit 1b9e8e3
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 69 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ mod tests {
pattern_with_rewrite()
"#
.to_string();
let mut libs = BTreeMap::new();
let libs = BTreeMap::new();
let problem = src_to_problem_libs(
pattern_src.to_string(),
&libs,
Expand Down
6 changes: 5 additions & 1 deletion crates/core/src/ast_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
problem::MarzanoQueryContext,
};
use anyhow::{anyhow, Result};
use grit_pattern_matcher::pattern::PatternDefinition;
use grit_pattern_matcher::{
binding::Binding,
pattern::{
Expand All @@ -29,7 +30,10 @@ impl ASTNode {
impl AstNodePattern<MarzanoQueryContext> for ASTNode {
const INCLUDES_TRIVIA: bool = false;

fn children(&self) -> Vec<PatternOrPredicate<MarzanoQueryContext>> {
fn children<'a>(
&'a self,
_definitions: &'a [PatternDefinition<MarzanoQueryContext>],
) -> Vec<PatternOrPredicate<'a, MarzanoQueryContext>> {
self.args
.iter()
.map(|a| PatternOrPredicate::Pattern(&a.2))
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/pattern_compiler/not_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl NodeCompiler for NotCompiler {
.ok_or_else(|| anyhow!("missing pattern of patternNot"))?;
let range = pattern.range();
let pattern = PatternCompiler::from_node(&pattern, context)?;
if pattern.iter().any(|p| {
if pattern.iter(&[]).any(|p| {
matches!(
p,
PatternOrPredicate::Pattern(Pattern::Rewrite(_))
Expand Down Expand Up @@ -59,7 +59,7 @@ impl NodeCompiler for PrNotCompiler {
.ok_or_else(|| anyhow!("predicateNot missing predicate"))?;
let range = not.range();
let not = PredicateCompiler::from_node(&not, context)?;
if not.iter().any(|p| {
if not.iter(&[]).any(|p| {
matches!(
p,
PatternOrPredicate::Pattern(Pattern::Rewrite(_))
Expand Down
10 changes: 5 additions & 5 deletions crates/grit-pattern-matcher/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::{

/// Determine if a provided pattern has a rewrite anywhere inside of it
pub fn has_rewrite<Q: QueryContext>(current_pattern: &Pattern<Q>) -> bool {

Check failure on line 7 in crates/grit-pattern-matcher/src/analysis.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `current_pattern`

error: unused variable: `current_pattern` --> crates/grit-pattern-matcher/src/analysis.rs:7:37 | 7 | pub fn has_rewrite<Q: QueryContext>(current_pattern: &Pattern<Q>) -> bool { | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_current_pattern` | = note: `-D unused-variables` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_variables)]`
for pattern in current_pattern.iter() {
if matches!(pattern, PatternOrPredicate::Pattern(Pattern::Rewrite(_))) {
return true;
}
}
// for pattern in current_pattern.iter(definitions) {
// if matches!(pattern, PatternOrPredicate::Pattern(Pattern::Rewrite(_))) {
// return true;
// }
// }
false
}
6 changes: 5 additions & 1 deletion crates/grit-pattern-matcher/src/pattern/ast_node_pattern.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{
iter_pattern::PatternOrPredicate,
patterns::{Matcher, PatternName},
PatternDefinition,
};
use crate::context::QueryContext;

Expand All @@ -12,7 +13,10 @@ pub trait AstNodePattern<Q: QueryContext>:
/// Trivia is useful for being able to re-print an AST, but not all parsers support collecting it.
const INCLUDES_TRIVIA: bool;

fn children(&self) -> Vec<PatternOrPredicate<Q>>;
fn children<'a>(
&'a self,
definitions: &'a [PatternDefinition<Q>],
) -> Vec<PatternOrPredicate<'a, Q>>;

fn matches_kind_of(&self, node: &Q::Node<'_>) -> bool;
}
Expand Down
Loading

0 comments on commit 1b9e8e3

Please sign in to comment.