Skip to content

Commit 5845716

Browse files
committed
fixes parsing regressions; binary 'not' for 'not nil' must stay
1 parent 05683e3 commit 5845716

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

compiler/parser.nim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,14 +1254,29 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode =
12541254
if mode != pmSkipSuffix:
12551255
result = primarySuffix(p, result, baseInd, mode)
12561256

1257+
proc binaryNot(p: var TParser; a: PNode): PNode =
1258+
if p.tok.tokType == tkNot:
1259+
let notOpr = newIdentNodeP(p.tok.ident, p)
1260+
getTok(p)
1261+
optInd(p, notOpr)
1262+
let b = parseExpr(p)
1263+
result = newNodeP(nkCommand, p)
1264+
result.add notOpr
1265+
result.add a
1266+
result.add b
1267+
else:
1268+
result = a
1269+
12571270
proc parseTypeDesc(p: var TParser): PNode =
1258-
#| typeDesc = simpleExpr
1271+
#| typeDesc = simpleExpr ('not' expr)?
12591272
result = simpleExpr(p, pmTypeDesc)
1273+
result = binaryNot(p, result)
12601274

12611275
proc parseTypeDefAux(p: var TParser): PNode =
1262-
#| typeDefAux = simpleExpr
1276+
#| typeDefAux = simpleExpr ('not' expr)?
12631277
#| | 'concept' typeClass
12641278
result = simpleExpr(p, pmTypeDef)
1279+
result = binaryNot(p, result)
12651280

12661281
proc makeCall(n: PNode): PNode =
12671282
## Creates a call if the given node isn't already a call.

0 commit comments

Comments
 (0)