unify tuple expressions (#13793)
* unify tuple expressions * fix test * fix test * apply feedback * Handle empty tuples * Fix rendering named unary tuple * Protect static NimNode against stripping * Slightly less hacky * Revert "Slightly less hacky" This reverts commit 170c5aec0addc029f637afbc948700ca006b7942. * Slightly less hacky * Cleanup * Fix test * Fix another test * Add condsym * Rebase fallout * changelog: Move from compiler changes to language changes * Add stricter tests * Add empty tuple example to doc/astspec * Fix test Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
35655cd189
commit
159c06e045
13 changed files with 136 additions and 32 deletions
|
|
@ -329,19 +329,56 @@ AST:
|
|||
Parentheses
|
||||
-----------
|
||||
|
||||
Parentheses for affecting operator precedence or tuple construction
|
||||
are built with the ``nnkPar`` node.
|
||||
Parentheses for affecting operator precedence use the ``nnkPar`` node.
|
||||
|
||||
Concrete syntax:
|
||||
|
||||
.. code-block:: nim
|
||||
(1, 2, (3))
|
||||
(a + b) * c
|
||||
|
||||
AST:
|
||||
|
||||
.. code-block:: nim
|
||||
nnkPar(nnkIntLit(1), nnkIntLit(2), nnkPar(nnkIntLit(3)))
|
||||
nnkInfix(nnkIdent("*"),
|
||||
nnkPar(
|
||||
nnkInfix(nnkIdent("+"), nnkIdent("a"), nnkIdent("b"))),
|
||||
nnkIdent("c"))
|
||||
|
||||
Tuple Constructors
|
||||
------------------
|
||||
|
||||
Nodes for tuple construction are built with the ``nnkTupleConstr`` node.
|
||||
|
||||
Concrete syntax:
|
||||
|
||||
.. code-block:: nim
|
||||
(1, 2, 3)
|
||||
(a: 1, b: 2, c: 3)
|
||||
()
|
||||
|
||||
AST:
|
||||
|
||||
.. code-block:: nim
|
||||
nnkTupleConstr(nnkIntLit(1), nnkIntLit(2), nnkIntLit(3))
|
||||
nnkTupleConstr(
|
||||
nnkExprColonExpr(nnkIdent("a"), nnkIntLit(1)),
|
||||
nnkExprColonExpr(nnkIdent("b"), nnkIntLit(2)),
|
||||
nnkExprColonExpr(nnkIdent("c"), nnkIntLit(3)))
|
||||
|
||||
Since the one tuple would be syntactically identical to parentheses
|
||||
with an expression in them, the parser expects a trailing comma for
|
||||
them. For tuple constructors with field names, this is not necessary.
|
||||
|
||||
.. code-block:: nim
|
||||
(1,)
|
||||
(a: 1)
|
||||
|
||||
AST:
|
||||
|
||||
.. code-block:: nim
|
||||
nnkTupleConstr(nnkIntLit(1))
|
||||
nnkTupleConstr(
|
||||
nnkExprColonExpr(nnkIdent("a"), nnkIntLit(1)))
|
||||
|
||||
Curly braces
|
||||
------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue