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 more types and struct/parameter fix #118

Merged
merged 6 commits into from
May 30, 2023
Merged

Add more types and struct/parameter fix #118

merged 6 commits into from
May 30, 2023

Conversation

amaanq
Copy link
Member

@amaanq amaanq commented May 22, 2023

Supersedes #117

Checklist:

  • All tests pass in CI.
  • There are sufficient tests for the new fix/feature.
  • Grammar rules have not been renamed unless absolutely necessary.
  • The conflicts section hasn't grown too much.
  • The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).

Closes #62
Closes #94
Closes #95
Closes #104
Closes #107

amaanq added 4 commits May 22, 2023 19:44
… priority

The lower priority allows for multiple return types to be parsed as two
types rather than a second map return type being split into an
identifier `map` followed by an array type
…_simple_type

The _simple_type covers both constraint_term and interface_type_name, no point having both when we can just alias _simple_type to constraint_elem
@aryx
Copy link
Contributor

aryx commented May 23, 2023

CI failure @amaanq

@amaanq
Copy link
Member Author

amaanq commented May 25, 2023

Yeah...I forgot one file failed in the latest moby commit that the bigger PR had fixed as well - I added it to known-failures but I'll remove it in the followup PR! Sorry for the delay - on vacation right now 😁

@amaanq amaanq requested a review from aryx May 26, 2023 23:44
@aryx aryx merged commit 7cccc30 into tree-sitter:master May 30, 2023
Comment on lines +268 to +271
(type_identifier))
(parameter_declaration
(type_identifier))
(parameter_declaration
Copy link

Choose a reason for hiding this comment

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

This seems incorrect. In the declaration:

func f2(a File, b, c, d Thing) int {}

b and c are identifiers, not types.

Copy link

@fsouza fsouza Jun 1, 2023

Choose a reason for hiding this comment

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

Unfortunately, it looks like we can't reuse parameter_list for receiver, parameters and result.

Basically, the receiver cannot take a list for parameters, it's always a single parameter, but (x) means that x is a type_identifier, whereas (x y) means that x is identifier and y is type_identifier.

Now, for parameters vs result:

  • (x int, y int) means the same thing in both cases (x and y are identifier, both ints are type_identifier)
  • (x, y int) means the same thing in both cases (x and y are identifier, int is a type_identifier)
  • (x, y) is invalid for parameters, but in the case result x and y are type_identifier (edit: this is wrong, I needed some sleep, they are the same)

I can try to send a PR later this week.

Copy link

Choose a reason for hiding this comment

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

waiting for your PR

Copy link

Choose a reason for hiding this comment

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

Hmm I'm actually struggling with this one. I wanted to make something like:

func f1(x1, x2 int) {}
func f2(int, int) {}

Become:

(function_declaration
  (identifier)
  (parameter_list
    (parameter_declaration
      (identifier))
    (parameter_declaration
      (identifier)
      (type_identifier)))
  (block))

(function_declaration
  (identifier)
  (parameter_list
    (type_identifier)
    (type_identifier))
  (block))

But that's surprisingly tricky 😁

I tried:

    parameter_list: $ => seq(
      '(',
      optional(
        seq(
          choice(
            commaSep1(choice($.parameter_declaration, $.variadic_parameter_declaration)),
            seq(commaSep($._type)),
          ),
          optional(','),
        ),
      ),
      ')'
    ),

    parameter_declaration: $ => prec.left(-1, seq(
      field('name', $.identifier),
      optional(field('type', $._type)),
    )),

It would be somewhat easy to group parameters that "reuse" the type, but I feel like that isn't the correct approach.

I'll come back to this later this week, but if anyone has additional ideas, I'm all ears 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

@amaanq thanks for fixing it, I was definitely over complicating this lol

@amaanq amaanq mentioned this pull request Jun 5, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants