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

trailing comma support implemented #1272

Merged
merged 6 commits into from
Oct 2, 2024
Merged

trailing comma support implemented #1272

merged 6 commits into from
Oct 2, 2024

Conversation

ThakeeNathees
Copy link
Collaborator

"""
This test file is to ensure the valid syntax of jac lang.
Add new jac syntax here to test if it compile without any issue.
"""

# Import statement without trailing comma.
import:py from time {
  sleep,
  timezone,
  tzname
}


# Import statement with trailing comma.
import:py from os {
  path,
  getenv,
  getpid,
}


enum WithoutTrailComma {
    FOO = "FOO",
    BAR = "BAR"
}


enum WithTrailComma {
    FOO = "FOO",
    BAR = "BAR",
}


can without_trail_comma(a:int, b:int) {}

can with_trail_comma(
      a:int,
      b:int,
      c:int,
    ) {}


with entry {

    dict_without_trail_comma = { "key" : "value" };
    dict_with_trail_comma = {
        "key" : "val",
    };

    list_without_trail_comma = [ "foo", "bar" ];
    list_with_trail_comma = [
        "foo",
        "bar",
    ];

    set_without_trail_comma = { "foo", "bar" };
    set_with_trail_comma = {
      "foo",
      "bar",
    };

    print("Code compiled and ran successfully!");
}

Copy link
Collaborator

@kugesan1105 kugesan1105 left a comment

Choose a reason for hiding this comment

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

The changes look good overall @ThakeeNathees 🎯. However, it would be great if we could extend support for trailing commas to tuples as well: @marsninja

(1, 2, 3,);

@kugesan1105
Copy link
Collaborator

kugesan1105 commented Sep 24, 2024

Hi @AshishMahendra , the recent grammar change introducing trailing commas is causing the formatter to break, particularly in the FuncCall handling. The IndexError: list index out of range seems to occur when processing the trailing commas. Could you please look into fixing this in the same PR?

     foo_instance1 = foo11(val=90);
    # foo_instance1_2 = foo11(val=90,);  # TODO: FORMATTER: trailing comma is not supported

    foo_instance3 = foo11(2, 34, val3=90);
    # foo_instance3_2 = foo11(2,34,val3=90,);  # TODO: FORMATTER: trailing comma is not supported

    foo_instance4 = foo11(2, 34,val3=90, val4=90);
    # foo_instance4_2 = foo11(2, 34,val3=90, val4=90,);   # TODO: FORMATTER: trailing comma is not supported

Link to the Test file
Test file breaking at lines 63, 66, 69.

@marsninja marsninja merged commit 93cae23 into main Oct 2, 2024
3 checks passed
@marsninja marsninja deleted the thakee-trailing-comma branch October 2, 2024 22:39
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.

4 participants