-
Notifications
You must be signed in to change notification settings - Fork 660
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
[Bug] [ABNF] Ordering and commas for member declarations #842
Comments
I would say member variables should precede member functions and the last one should always terminate with a comma. Though I'm not opposed to the ending symbol being a semi-colon since we define our member variables and functions in the same scope. I like the idea of these restrictions being placed into the grammar and language itself because it enforces a bit of styling at a lower level. @acoglio @collinc97 thoughts? |
I have no strong opinions, but my vote would be to require member variables to be terminated by semicolon instead of comma and to allow intermixing of member variables and functions. Style guides could suggest to put all member variables first and then all member functions in general; but perhaps there are cases in which it may make more sense to group things differently (although that may call for splitting a large circuit into smaller ones). |
I'm a fan of member variables with an optional trailing comma. No commas after member functions. circuit Foo {
x: u32,
y: u32
}
circuit Foo {
x: u32,
y: u32,
} I think both should be allowed. |
I think the strangeness in that is that we allow variable and function definitions in the same block @collinc97. Our style is more c++ similar where define both in a block. But c++ requires the semi-colon here. |
Also similar to Java -- mixed field and methods, with fields terminated by semicolon. A Rust struct has only fields, no methods. |
In the best interest of time and not rushing this discussion, for DP2 should I just make it so that the abnf grammar just says no commas after member functions @acoglio @collinc97? Could leave this PR open and discuss more then. |
We could do that, but as I think of grammar rules for that, they seem a bit awkward (unless I'm missing something):
@gluax Maybe you have thought of a more elegant formulation of the rules? Note that this allows a circuit with no members, which the current rules disallow, but I believe the parser allows. Ideally that should be a separate issue, but we may take care of this while we are at it. |
Maybe we could turn things around a bit:
I think this is less awkward, but still a bit. |
This is what I would vote for:
|
The last one makes a lot of sense @acoglio. Although if we want variables to come before functions I think we would need to do something like this in the future.
|
Reopening this discussion, is it impossible in the ABNF grammar to have rules that allow this case? I'm asking because it seems like the purpose of adding semicolons to the end of circuit members is just to have complete ABNF rules. |
It's possible to have ABNF rules that allow that, such as the ones at #842 (comment). |
By the way, I just noticed (by accident) that it is also allowed to have no commas (or semicolons). The following works with the latest Leo:
|
The no commas make sense since we don't currently check if something is the last member variable before member functions, so they are effectively just optional at the moment. So if I remember correctly, the discussion after the end of the last meeting was to use semi-colons and commas. Then after we have a proper warning system, we can go ahead and give people a warning about the comma deprecation. We can fix the commas and add the semi-colons here, and then update the documentation. |
@gluax Your summary sounds good to me. |
🐛 Bug Report
The current rules for circuit member declarations require commas to separate each member, both variables and functions:
But this page https://developer.aleo.org/aleo/concepts/programs shows that member functions are not followed by commas. This seems reasonable, so we should update the grammar rules, but here are a few questions:
The text was updated successfully, but these errors were encountered: