-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Named arguments in commands + many grammar fixes #20994
Conversation
Types are separated from expressions and better reflected in the grammar.
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
* 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
@@ -1199,8 +1200,12 @@ proc parseTypeDescKAux(p: var Parser, kind: TNodeKind, | |||
getTok(p) | |||
if p.tok.indent != -1 and p.tok.indent <= p.currInd: return | |||
optInd(p, result) | |||
let isTypedef = mode == pmTypeDef and p.tok.tokType in {tkObject, tkTuple} |
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.
It seems that
type
Named = tuple or int
doesn't work anymore. Is it expected?
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.
Yes, tuple
in type sections can have a syntax similar to objects, so it becomes tuple[]
which is misleading
Hence this bigger example doesn't compile in 1.6:
type Named = tuple or int
proc foo(x: Named) = echo x
foo((1, 2))
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.
I see, thanks for your explanation.
* 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
closes nim-lang/RFCs#442, closes #15050, closes #8846 and maybe some other issues, cleans up after #19181
This is a fully rebased version of #19383 I am opening again to bump it up because apparently the time is ticking on 2.0 and it doesn't make sense for it to not have this.
foo a = b
now meansfoo(a = b)
instead offoo(a) = b
, for consistency withfoo a, b = c
. To do this, theprimary
expression in the grammar, which had many issues and did not reflect reality, had to be slightly overhauled.primary
anymore. Instead they have been broken up intotypeDefValue
(right hand sides of type sections) andtypeDesc
(everywhere else a type is expected).typeDesc
itself is broken up into 2:rawTypeDesc
(expressions that start with type keywords) andtypeDescExpr
(general expressions that may evaluate to types, as well as binarynot
). We userawTypeDesc
as the ordered choice inprimary
.identOrLiteral
s for simplicity. (This seems to break nothing as it doesn't really make sense to apply to anything else)primarySuffix
anymore. This never made sense and had many issues. For example, in realityprimary
only parses 1 command argument, but the grammar denotes an arbitrary number of arguments.=
) is now inexprStmt
(which it already was, but not in the grammar). We indicate with a parser mode that we want to get away with parsing only asimplePrimary
(which is also reflected in the grammar), and if we do we parseexprEqExpr ^+ comma
for command syntax. Otherwise we just use the expression that we got.for a, (b, c) in d
syntax with'for' ((varTuple / identWithPragma) ^+ comma)
instead of'for' (identWithPragma ^+ comma)
.