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_continue rule #211

Closed
wants to merge 22 commits into from
Closed

Conversation

jiwonz
Copy link
Contributor

@jiwonz jiwonz commented Sep 5, 2024

Closes #202

Cases

Case: There are continue and break together in a loop but there are more continue than break

Input

for i = 1, 10 do
	if i % 3 == 0 then
		continue
	end
	if i % 6 == 0 then
		continue
	end
	if i % 9 == 0 then
		continue
	end
	if i % 10 == 0 then
		break
	end
end

Output

for i = 1, 10 do
local __DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf=false repeat	if i % 3 == 0 then
break	
end
	if i % 6 == 0 then
break	
end
	if i % 9 == 0 then
break	
end
	if i % 10 == 0 then
__DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf=true break	
end
until true if __DARKLUA_REMOVE_CONTINUE_break5784919bbab63ddf then break end end

Case: There are continue and break together in a loop but there are more break than continue

Input

for i = 1, 10 do
	if i % 3 == 0 then
		break
	end
	if i % 6 == 0 then
		break
	end
	if i % 9 == 0 then
		break
	end
	if i % 10 == 0 then
		continue
	end
end

Output

for i = 1, 10 do
local __DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf=false repeat	if i % 3 == 0 then
break	
end
	if i % 6 == 0 then
break	
end
	if i % 9 == 0 then
break	
end
	if i % 10 == 0 then
__DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf=true break	
end
until true if not __DARKLUA_REMOVE_CONTINUE_continue5784919bbab63ddf then break end end

Case: There is only continue in a loop

Input

for i = 1, 10 do
	if i % 5 == 0 then
		continue
	end
	print(i)
end

Output

for i = 1, 10 do
repeat	if i % 5 == 0 then
break	
end
	print(i)
until true end

Note

  • blake3 used for exit variable name (break_variable_name, continue_variable_name)

TO-DOs

  • Add tests for cases where continue and break are mixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A rule for removing (converting) continue statements
1 participant