Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Grammar inconsistent with language for tuple/array/pragma

Open arnetheduck opened this issue 2 months ago • 2 comments

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

arnetheduck avatar Oct 21 '25 12:10 arnetheduck

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

ringabout avatar Oct 21 '25 14:10 ringabout

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)

ringabout avatar Oct 22 '25 12:10 ringabout