-
Notifications
You must be signed in to change notification settings - Fork 23
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
Change command + =
syntax
#442
Comments
That would break the rule "unary binds stronger than binary". It's an easy enough rule to remember, I'm not sure the exception is worth it. And later all parsing/syntax highlighting packages need to be updated. |
But that rule already doesn't apply for
I doubt they parse this correctly already. Even if they didn't, I don't think they would break that much. But yes, this is a breaking change overall. |
I like the idea. |
Types are separated from expressions and better reflected in the grammar.
It may be worth observing here that named arguments already work for non-first params: proc foo(x: int, a=2, b=3) = discard
foo 1, b=2, a=3 |
Was mentioned but has been included more thoroughly in the proposal. In my opinion that is in favor of the proposed syntax. |
I agree "all arguments working" is a good consistency principle. It took me a while to discover that it worked for non-first args, actually. Sorry if I didn't notice the mention already. It may be the strongest pro-argument here, but I think it would be good for other Nimmers to weigh in. You may also be interested in what I call "named do" which I think of as closely related - making named parameter passing work in "code block notation" as well as "code expression notation" (which already works). You just need a way to connect the parameter name and |
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
Types are separated from expressions and better reflected in the grammar.
* Breaking parser changes, implement nim-lang/RFCs#442 Types are separated from expressions and better reflected in the grammar. * add test * more accurate grammar * fix keyword typedescs * accept expressions in proc argument lists * CI "fixes" * fixes * allow full ref expressions again, adapt old tests * cleanup, fix some tests * improve grammar, try and revert semtypes change * restrict sigil binding to identOrLiteral * fix, should have caught this immediately * add changelog entry, fix double not nil bug * correct grammar * change section * fix * real fix hopefully * fix test * support LL(1) for tuples * make grammar.txt too
* Breaking parser changes, implement nim-lang/RFCs#442 Types are separated from expressions and better reflected in the grammar. * add test * more accurate grammar * fix keyword typedescs * accept expressions in proc argument lists * CI "fixes" * fixes * allow full ref expressions again, adapt old tests * cleanup, fix some tests * improve grammar, try and revert semtypes change * restrict sigil binding to identOrLiteral * fix, should have caught this immediately * add changelog entry, fix double not nil bug * correct grammar * change section * fix * real fix hopefully * fix test * support LL(1) for tuples * make grammar.txt too
* Breaking parser changes, implement nim-lang/RFCs#442 Types are separated from expressions and better reflected in the grammar. * add test * more accurate grammar * fix keyword typedescs * accept expressions in proc argument lists * CI "fixes" * fixes * allow full ref expressions again, adapt old tests * cleanup, fix some tests * improve grammar, try and revert semtypes change * restrict sigil binding to identOrLiteral * fix, should have caught this immediately * add changelog entry, fix double not nil bug * correct grammar * change section * fix * real fix hopefully * fix test * support LL(1) for tuples * make grammar.txt too
* Breaking parser changes, implement nim-lang/RFCs#442 Types are separated from expressions and better reflected in the grammar. * add test * more accurate grammar * fix keyword typedescs * accept expressions in proc argument lists * CI "fixes" * fixes * allow full ref expressions again, adapt old tests * cleanup, fix some tests * improve grammar, try and revert semtypes change * restrict sigil binding to identOrLiteral * fix, should have caught this immediately * add changelog entry, fix double not nil bug * correct grammar * change section * fix * real fix hopefully * fix test * support LL(1) for tuples * make grammar.txt too
Currently this:
parses as this:
The proposal is to make this mean (only in statement form):
foo a = b, c = d
syntax should be an easy outcome of this for a reason explained below.Reasoning:
a b + c
, or evena b += c
. Since=
forms an expression in named argument syntax, it makes sense to consider it equivalent to an infix operation.foo a, b = c
already parses asfoo(a, b = c)
(not in the grammar). Hencefoo a = b, c = d
should be easy to support.foo(a) = b
ora.foo = b
are already possible and not much less ergonomic.I've never seen the current syntax in code likely because of the above problems.foo(a = b, c = d)
, so there is a clear use for this syntax in command form. Macros and DSLs would also benefit from this, for exampleunpack (a, (b, c)) = (1, (2, 3))
would become possible.This change would definitely break code and macros which use the current syntax. However
I genuinely have never seen any code which does, the workaround is simple and all the capabilities of the old syntax seem to be kept. And it can be easily tied to a big, backwards-incompatible release like 2.0.From what I can think of, this would require some redundancy in the grammar, but there may still be simple ways to include it. It shouldn't cause a giant ambiguity anyway.
Edit: Looking more into the parser, I am changing this proposal to only work in statement form.
Edit: I have found that my own macro library has tests using the old syntax. Thankfully it does nothing more than create an inconsistency with the other macros. It can also easily still support the old invocations. I did not think about how this could affect existing macros rather than just normal code, but AST has been noticeably changed before and in my view no information is lost here.
Edit 2: Old issue about this I didn't see: nim-lang/Nim#15050
The text was updated successfully, but these errors were encountered: