Skip to content

Conversation

jiwonz
Copy link
Contributor

@jiwonz jiwonz commented Jan 29, 2025

Closes #256

Changes

  • Add a rule convert_luau_numbers that converts luau's number literal syntax.
  • Add a simple tests for a rule convert_luau_numbers.

Copy link
Contributor

@jeparlefrancais jeparlefrancais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for submitting the PR

Before merging this, I'd like to see these:

  • change the rule name to convert_luau_numbers
  • convert only binary numbers to decimal numbers because those are the compatibility issue
  • for each kind of number, if they have a token, remove the token if it contains any underscores (_)

src/rules/mod.rs Outdated
@@ -235,6 +237,7 @@ pub fn get_default_rules() -> Vec<Box<dyn Rule>> {
Box::<RemoveNilDeclaration>::default(),
Box::<RenameVariables>::default(),
Box::<RemoveFunctionCallParens>::default(),
Box::<RemoveNumberLiterals>::default(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would not put this rule in the default rules, at least for now

struct Processor {}

impl NodeProcessor for Processor {
fn process_expression(&mut self, exp: &mut Expression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function for number expressions you can use directly:

Suggested change
fn process_expression(&mut self, exp: &mut Expression) {
fn process_number_expression(&mut self, number: &mut NumberExpression) {

@ewd3v
Copy link

ewd3v commented Feb 3, 2025

I can't see a reason why you would want this, but it might be cool to atleast have an option for it to convert all number literals (so even hex literals like 0xFFFFFFF, like it's doing right now), instead of it only converting binary literals and removing underscores.

… changed to convert_luau_numbers and only converts binary to decimal and removes underscores from token)
@jiwonz jiwonz changed the title Add remove_number_literals rule Add convert_luau_numbers rule Mar 13, 2025
@jLn0n
Copy link

jLn0n commented Jun 4, 2025

I can't see a reason why you would want this, but it might be cool to atleast have an option for it to convert all number literals (so even hex literals like 0xFFFFFFF, like it's doing right now), instead of it only converting binary literals and removing underscores.

oh, it is for lua 5.1 compatibility thingy

@jeparlefrancais jeparlefrancais mentioned this pull request Jun 19, 2025
1 task
@jeparlefrancais
Copy link
Contributor

Closed since this has been merged in #274

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 way of converting number literals to decimals
4 participants