-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Conversation
… 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
CI failure @amaanq |
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 😁 |
(type_identifier)) | ||
(parameter_declaration | ||
(type_identifier)) | ||
(parameter_declaration |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 areidentifier
, bothint
s aretype_identifier
)(x, y int)
means the same thing in both cases (x and y areidentifier
, int is atype_identifier
)(edit: this is wrong, I needed some sleep, they are the same)(x, y)
is invalid for parameters, but in the case result x and y aretype_identifier
I can try to send a PR later this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting for your PR
There was a problem hiding this comment.
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 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
Supersedes #117
Checklist:
Closes #62
Closes #94
Closes #95
Closes #104
Closes #107