Skip to content

Commit

Permalink
style: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Apr 28, 2024
1 parent bcd6072 commit a5b2823
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
96 changes: 53 additions & 43 deletions crates/redos/src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ mod token;
use token::Token;

use std::{
cell::RefCell, num::NonZeroUsize, rc::{Rc, Weak}
cell::RefCell,
num::NonZeroUsize,
rc::{Rc, Weak},
};

use fancy_regex::{Assertion, Expr as RegexExpr, LookAround};
Expand Down Expand Up @@ -82,7 +84,7 @@ impl ExprNode {
{
// Here, we don't care about current; we are going to replace it
let mut node = ExprNode::new_prev(Expr::Concat(vec![]), previous, parent);

let child = current(Rc::downgrade(&Rc::new(node.clone())));

if child.is_none() {
Expand Down Expand Up @@ -119,7 +121,10 @@ impl ExprNode {
}
}

fn parented_dummy(parent: Option<WeakLink<ExprNode>>, previous: Option<WeakLink<ExprNode>>) -> ExprNode {
fn parented_dummy(
parent: Option<WeakLink<ExprNode>>,
previous: Option<WeakLink<ExprNode>>,
) -> ExprNode {
ExprNode {
current: Expr::Token(Token {
yes: vec![],
Expand Down Expand Up @@ -334,13 +339,7 @@ fn to_nested_expr(
let no_siblings_list = list
.iter()
.filter_map(|e| {
to_nested_expr(
e,
config,
group_increment,
Some(parent.clone()),
None,
)
to_nested_expr(e, config, group_increment, Some(parent.clone()), None)
})
.map(Rc::new)
.collect::<Vec<_>>();
Expand Down Expand Up @@ -385,7 +384,8 @@ fn to_nested_expr(
group_increment,
Some(x.clone()),
Some(x.clone()),
).map(Rc::new)
)
.map(Rc::new)
})
.collect::<Vec<_>>(),
))
Expand Down Expand Up @@ -495,40 +495,50 @@ fn to_nested_expr(
condition,
true_branch,
false_branch,
} => ExprNode::new_prev_consume_optional(|x| {
let true_branch = to_nested_expr(
true_branch,
config,
group_increment,
Some(x.clone()),
Some(x.clone()),
);
let false_branch = to_nested_expr(
false_branch,
config,
group_increment,
Some(x.clone()),
Some(x.clone()),
);
if let (Some(true_branch), Some(false_branch)) = (true_branch, false_branch) {
let condition: Option<ExprConditional> = match condition.as_ref() {
&RegexExpr::BackrefExistsCondition(number) => {
Some(ExprConditional::BackrefExistsCondition(number))
}
expr => to_nested_expr(expr, config, group_increment, Some(x.clone()), Some(x.clone()))
} => ExprNode::new_prev_consume_optional(
|x| {
let true_branch = to_nested_expr(
true_branch,
config,
group_increment,
Some(x.clone()),
Some(x.clone()),
);
let false_branch = to_nested_expr(
false_branch,
config,
group_increment,
Some(x.clone()),
Some(x.clone()),
);
if let (Some(true_branch), Some(false_branch)) = (true_branch, false_branch) {
let condition: Option<ExprConditional> = match condition.as_ref() {
&RegexExpr::BackrefExistsCondition(number) => {
Some(ExprConditional::BackrefExistsCondition(number))
}
expr => to_nested_expr(
expr,
config,
group_increment,
Some(x.clone()),
Some(x.clone()),
)
.map(|x| ExprConditional::Condition(Rc::new(x))),
};
};

let condition = condition.map(|condition| Expr::Conditional {
condition,
true_branch: Rc::new(true_branch),
false_branch: Rc::new(false_branch),
});
let condition = condition.map(|condition| Expr::Conditional {
condition,
true_branch: Rc::new(true_branch),
false_branch: Rc::new(false_branch),
});

condition
} else {
return None;
}
}, previous, parent)
condition
} else {
return None;
}
},
previous,
parent,
),
}
}
2 changes: 1 addition & 1 deletion crates/redos/src/ir/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub enum Value {
Singular(String),
Range(String, String),
Any
Any,
}

#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down

0 comments on commit a5b2823

Please sign in to comment.