Nim
Nim copied to clipboard
Grammar inconsistent with language for tuple/array/pragma
Nim Version
2.2.4
Description
grammar:
tupleConstr = '(' optInd (exprColonEqExpr comma?)* optPar ')'
pragma = '{.' optInd (exprColonEqExpr comma?)* optPar ('.}' | '}')
code:
import macros
macro print(v: untyped) =
echo astGenRepr(v)
print:
(a: 1, b: 2, c: 3) # works
{.push pragma gcsafe raises: [].} # works
(a: 1 b: 2 c: 3) # breaks
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response
tupleConstr = '(' optInd (exprColonEqExpr comma?)* optPar ')'
I think this intended to mean in the position of the last element or when there is no value in the tuple, the comma can be omitted, e.g. (1, 2, 3) and (). And there seems to be no explicit check for the comma in the praser, e.g. (1 2 3) gives an error in the sem phase
I think this syntax is for commands, e.g.
proc foo(x: int): int =
result = x + 1
var x = [foo foo 12]
echo x
var y = (foo 1, foo 2)