Skip to content

Commit

Permalink
fix: Refactored subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Jul 28, 2024
1 parent 5537a12 commit 8c91bed
Showing 1 changed file with 41 additions and 114 deletions.
155 changes: 41 additions & 114 deletions lykiadb-playground/src/regularizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ impl TreeBuilder {
}
return None;
}

Check warning on line 42 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L28-L42

Added lines #L28 - L42 were not covered by tests

pub fn get_subtree(&self, name: &str, span: &Span, id: usize, mut children: Vec<Tree>) -> Tree {
let token_children = self.get_children(id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: name.to_owned(),
children: Some(children),
span: *span,
}
}

Check warning on line 54 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L44-L54

Added lines #L44 - L54 were not covered by tests
}

impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
Expand Down Expand Up @@ -80,42 +92,24 @@ impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
}
}
Expr::Variable { name, span, id } => {
let mut children = vec![Tree {
self.get_subtree("Variable", span, *id, vec![Tree {
name: "identifier".to_string(),
children: None,
span: name.span,
}];
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: "Variable".to_owned(),
children: Some(children),
span: *span,
}
}])

Check warning on line 99 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L94-L99

Added lines #L94 - L99 were not covered by tests
}
Expr::Assignment {
dst,
expr,
span,
id,

Check warning on line 105 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L102-L105

Added lines #L102 - L105 were not covered by tests
} => {
let mut children = vec![Tree {
let children = vec![Tree {
name: "identifier".to_string(),
children: None,
span: dst.span,
}];
children.push(self.visit_expr(expr)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: "Assignment".to_string(),
children: Some(children),
span: *span,
}
}, self.visit_expr(expr)?];
self.get_subtree("Assignment", span, *id, children)

Check warning on line 112 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L107-L112

Added lines #L107 - L112 were not covered by tests
}
Expr::Logical {
left,
Expand All @@ -124,61 +118,36 @@ impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
span,
id,

Check warning on line 119 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L115-L119

Added lines #L115 - L119 were not covered by tests
} => {
let mut children = vec![];
children.push(self.visit_expr(left)?);
children.push(self.visit_expr(right)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: format!("{:?}", operation),
children: Some(children),
span: *span,
}
let children = vec![
self.visit_expr(left)?,
self.visit_expr(right)?

Check warning on line 123 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L121-L123

Added lines #L121 - L123 were not covered by tests
];
self.get_subtree(&format!("Logical/{:?}", operation), span, *id, children)

Check warning on line 125 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L125

Added line #L125 was not covered by tests
}
Expr::Call {
callee,
args,
span,
id,

Check warning on line 131 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L128-L131

Added lines #L128 - L131 were not covered by tests
} => {
let mut children = vec![];
children.push(self.visit_expr(callee)?);
let mut children = vec![self.visit_expr(callee)?];
for arg in args {
children.push(self.visit_expr(arg)?);

Check warning on line 135 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L133-L135

Added lines #L133 - L135 were not covered by tests
}
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: "Call".to_string(),
children: Some(children),
span: *span,
}
self.get_subtree("Call", span, *id, children)

Check warning on line 137 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L137

Added line #L137 was not covered by tests
}
Expr::Get {
object,
name,
span,
id,

Check warning on line 143 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L140-L143

Added lines #L140 - L143 were not covered by tests
} => {
let mut children = vec![Tree {
let children = vec![Tree {
name: "identifier".to_string(),
children: None,
span: name.span,
}];
children.push(self.visit_expr(object)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: name.name.clone(),
children: Some(children),
span: *span,
}
}, self.visit_expr(object)?];
self.get_subtree("Get", span, *id, children)

Check warning on line 150 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L145-L150

Added lines #L145 - L150 were not covered by tests
}
Expr::Set {
object,
Expand All @@ -187,35 +156,16 @@ impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
span,
id,

Check warning on line 157 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L153-L157

Added lines #L153 - L157 were not covered by tests
} => {
let mut children = vec![Tree {
let children = vec![Tree {
name: "identifier".to_string(),
children: None,
span: name.span,
}];
children.push(self.visit_expr(object)?);
children.push(self.visit_expr(value)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: name.name.clone(),
children: Some(children),
span: *span,
}
}, self.visit_expr(object)?, self.visit_expr(value)?];
self.get_subtree("Set", span, *id, children)

Check warning on line 164 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L159-L164

Added lines #L159 - L164 were not covered by tests
}
Expr::Grouping { expr, span, id } => {
let mut children = vec![];
children.push(self.visit_expr(expr)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: "Grouping".to_string(),
children: Some(children),
span: *span,
}
let children = vec![self.visit_expr(expr)?];
self.get_subtree("Grouping", span, *id, children)

Check warning on line 168 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L166-L168

Added lines #L166 - L168 were not covered by tests
}
Expr::Function {
name,
Expand All @@ -241,15 +191,8 @@ impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
span: param.span,
});
}

Check warning on line 193 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L187-L193

Added lines #L187 - L193 were not covered by tests
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: "Function".to_string(),
children: Some(children),
span: *span,
}

self.get_subtree("Function", span, *id, children)

Check warning on line 195 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L195

Added line #L195 was not covered by tests
}
Expr::Binary {
left,
Expand All @@ -258,36 +201,20 @@ impl<'a> VisitorMut<Tree, ()> for TreeBuilder {
span,
id,

Check warning on line 202 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L198-L202

Added lines #L198 - L202 were not covered by tests
} => {
let mut children = vec![];
children.push(self.visit_expr(left)?);
children.push(self.visit_expr(right)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: format!("{:?}", operation),
children: Some(children),
span: *span,
}
let children = vec![
self.visit_expr(left)?,
self.visit_expr(right)?

Check warning on line 206 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L204-L206

Added lines #L204 - L206 were not covered by tests
];
self.get_subtree(&format!("Binary/{:?}", operation), span, *id, children)

Check warning on line 208 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L208

Added line #L208 was not covered by tests
}
Expr::Unary {
operation,
expr,
span,
id,

Check warning on line 214 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L211-L214

Added lines #L211 - L214 were not covered by tests
} => {
let mut children = vec![];
children.push(self.visit_expr(expr)?);
let token_children = self.get_children(*id);
if let Some(c) = token_children {
children.extend(c);
}
Tree {
name: format!("{:?}", operation),
children: Some(children),
span: *span,
}
let children = vec![self.visit_expr(expr)?];
self.get_subtree(&format!("Unary/{:?}", operation), span, *id, children)

Check warning on line 217 in lykiadb-playground/src/regularizer.rs

View check run for this annotation

Codecov / codecov/patch

lykiadb-playground/src/regularizer.rs#L216-L217

Added lines #L216 - L217 were not covered by tests
}
Expr::Insert { command, span, id } => Tree {
name: format!("{:?}", command),
Expand Down

0 comments on commit 8c91bed

Please sign in to comment.