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

Support CfxLua #338

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Support CfxLua #338

wants to merge 5 commits into from

Conversation

mdxwzl
Copy link

@mdxwzl mdxwzl commented Feb 9, 2025

  • Implemented CFX Lua as a feature flag - cfxlua
    • Compound Operators: +=, -=, *=, /=, <<=, >>=, &=, |=, and ^=
    • Safe Navigation e.g. t?.x?.y == nil
    • In Unpacking e.g. local a, b, c = t is equivalent to local a, b, c = t.a, t.b, t.c
    • Set Constructors e.g. t = { .x, .y } is equivalent to t = { x = true, y = true }
    • C-Style Comments (single & multiline) e.g. /* comment */
    • Compile Time Jenkins' Hashes e.g. `Hello, World!` -> 1395890823

@mdxwzl
Copy link
Author

mdxwzl commented Feb 9, 2025

Some of the tests dont pass in the workflow, I'll look into it tmrw

@mdxwzl mdxwzl marked this pull request as ready for review February 9, 2025 19:43
@mdxwzl mdxwzl force-pushed the main branch 2 times, most recently from b1ac9c0 to 942e98d Compare February 10, 2025 07:28
@mdxwzl
Copy link
Author

mdxwzl commented Feb 10, 2025

Would be glad if someone can look over it. I tested the workflows locally with Docker, and it keeps changing up the bytes, line & character values in the AST. Somehow, they are not the same in the workflow environment as on my Windows machine.

@mdxwzl
Copy link
Author

mdxwzl commented Feb 20, 2025

Test should run now

Copy link
Collaborator

@JohnnyMorganz JohnnyMorganz left a comment

Choose a reason for hiding this comment

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

Thanks for this! I had an initial look - I haven't looked deep into the parser / tokenizer changes yet, I will do this in a follow up

}
/*
CompoundOp and CompoundAssignment have been moved to `compound.rs´, since CfxLua makes use of them as well.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we re-export the types here? To reduce the breaking change on downstream users

SlashEqual(TokenReference),
CaretEqual(TokenReference),

// luau sepcific
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these be gated via cfg(feature = "luau") flags if they are only available in luau?

Some with the below for CfxLua

Comment on lines +26 to +29
LeftShift(TokenReference),
RightShift(TokenReference),
BitwiseAndAssignment(TokenReference),
BitwiseOrAssignment(TokenReference),
Copy link
Collaborator

Choose a reason for hiding this comment

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

To align with the other options. We try to make the names represent the characters rather than the logic, since in future >>= could mean something other than right shift operator for a different Lua dialect

Suggested change
LeftShift(TokenReference),
RightShift(TokenReference),
BitwiseAndAssignment(TokenReference),
BitwiseOrAssignment(TokenReference),
DoubleLessThanEqual(TokenReference),
DoubleGreaterThanEqual(TokenReference),
AmpersandEqual(TokenReference),
PipeEqual(TokenReference),

@@ -39,7 +46,7 @@ mod versions;

#[cfg(any(feature = "lua52", feature = "luajit"))]
pub mod lua52;
#[cfg(feature = "lua54")]
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since cfxlua already extends lua54, we don't need to change this config since lua54 should always be enabled

Suggested change
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
#[cfg(feature = "lua54")]

@@ -413,11 +430,11 @@ pub enum Stmt {

/// A goto statement, such as `goto label`
/// Only available when the "lua52" or "luajit" feature flag is enabled.
#[cfg(any(feature = "lua52", feature = "luajit"))]
#[cfg(any(feature = "lua52", feature = "luajit", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above and in the other cases, I think this can be left alone

Suggested change
#[cfg(any(feature = "lua52", feature = "luajit", feature = "cfxlua"))]
#[cfg(any(feature = "lua52", feature = "luajit"))]

visit_goto => Goto,
visit_label => Label,
}

#[cfg(feature = "lua54")] {
visit_attribute => Attribute,
}

#[cfg(all(feature = "cfxlua", not(feature = "luau")))] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this condition.

We can remove the visit_compound_assignment from the Luau section above and then use any

Suggested change
#[cfg(all(feature = "cfxlua", not(feature = "luau")))] {
#[cfg(any(feature = "cfxlua", feature = "luau"))] {

}, token: {
visit_identifier,
visit_multi_line_comment,
visit_number,
visit_single_line_comment,
visit_string_literal,
visit_c_style_comment,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be gated by a cfxlua check

@@ -6,7 +6,7 @@ use crate::{

#[cfg(any(feature = "lua52", feature = "luajit"))]
use crate::ast::lua52::*;
#[cfg(feature = "lua54")]
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#[cfg(any(feature = "lua54", feature = "cfxlua"))]
#[cfg(feature = "lua54")]

/// A set constructor field, such as .a inside { .a } which is equivalent to { a = true }
#[display("{dot}{name}")]
#[cfg(feature = "cfxlua")]
SetConstructorField {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are already in Field, we don't need Field at the end of the name

Suggested change
SetConstructorField {
SetConstructor {

@@ -8,6 +8,10 @@ use super::{
span::ContainedSpan,
Expression, FunctionBody, Parameter,
};

#[cfg(any(feature = "cfxlua", feature = "luau"))]
use super::Var;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this was introduced by your IDE.

You should reference it through ast::Var instead, which is already exported

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.

2 participants