Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove_generalized_iteration rule #217

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ tracing = ["dep:tracing"]

[dependencies]
anstyle = "1.0.6"
blake3 = "1.5.4"
clap = { version = "4.5.3", features = ["derive"] }
durationfmt = "0.1.1"
elsa = "1.10.0"
env_logger = "0.11.3"
full_moon = { version = "1.0.0", features = ["roblox"] }
hex = "0.4.3"
json5 = "0.4.1"
log = "0.4.21"
pathdiff = "0.2.1"
regex = "1.10.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.114"
serde_yaml = "0.9.32"
strfmt = "0.2.4"
toml = "0.8.11"
tracing = { version = "0.1", optional = true }
wax = "0.5.0"
Expand Down
5 changes: 5 additions & 0 deletions src/nodes/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ impl Block {
self.statements.iter_mut()
}

#[inline]
pub fn mutate_statements(&mut self) -> &mut Vec<Statement> {
&mut self.statements
}

#[inline]
pub fn first_statement(&self) -> Option<&Statement> {
self.statements.first()
Expand Down
5 changes: 5 additions & 0 deletions src/nodes/statements/generic_for.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ impl GenericForStatement {
self.expressions.iter_mut()
}

#[inline]
pub fn mutate_expressions(&mut self) -> &mut Vec<Expression> {
&mut self.expressions
}

#[inline]
pub fn mutate_block(&mut self) -> &mut Block {
&mut self.block
Expand Down
6 changes: 6 additions & 0 deletions src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod remove_comments;
mod remove_compound_assign;
mod remove_debug_profiling;
mod remove_if_expression;
mod remove_generalized_iteration;
mod remove_interpolated_string;
mod remove_nil_declarations;
mod remove_spaces;
Expand All @@ -28,6 +29,7 @@ mod rename_variables;
mod replace_referenced_tokens;
pub(crate) mod require;
mod rule_property;
pub mod runtime_identifier;
mod shift_token_line;
mod unused_if_branch;
mod unused_while;
Expand All @@ -49,6 +51,7 @@ pub use remove_comments::*;
pub use remove_compound_assign::*;
pub use remove_debug_profiling::*;
pub use remove_if_expression::*;
pub use remove_generalized_iteration::*;
pub use remove_interpolated_string::*;
pub use remove_nil_declarations::*;
pub use remove_spaces::*;
Expand Down Expand Up @@ -216,6 +219,7 @@ pub fn get_default_rules() -> Vec<Box<dyn Rule>> {
Box::<RemoveNilDeclaration>::default(),
Box::<RenameVariables>::default(),
Box::<RemoveFunctionCallParens>::default(),
Box::<RemoveGeneralizedIteration>::default(),
]
}

Expand Down Expand Up @@ -245,6 +249,7 @@ pub fn get_all_rule_names() -> Vec<&'static str> {
REMOVE_UNUSED_WHILE_RULE_NAME,
RENAME_VARIABLES_RULE_NAME,
REMOVE_IF_EXPRESSION_RULE_NAME,
REMOVE_GENERALIZED_ITERATION_RULE_NAME,
]
}

Expand Down Expand Up @@ -279,6 +284,7 @@ impl FromStr for Box<dyn Rule> {
REMOVE_UNUSED_WHILE_RULE_NAME => Box::<RemoveUnusedWhile>::default(),
RENAME_VARIABLES_RULE_NAME => Box::<RenameVariables>::default(),
REMOVE_IF_EXPRESSION_RULE_NAME => Box::<RemoveIfExpression>::default(),
REMOVE_GENERALIZED_ITERATION_RULE_NAME => Box::<RemoveGeneralizedIteration>::default(),
_ => return Err(format!("invalid rule name: {}", string)),
};

Expand Down
Loading
Loading