Const tuple unpacking (#9964)
* tuple unpacking is now supported for consts * Move nkConstTuple to the end of TNodeKind * Add nnkConstTuple in macros.nim * Fix Formatting
This commit is contained in:
parent
3f917c8d91
commit
8e90ed0618
4 changed files with 77 additions and 31 deletions
|
|
@ -1764,21 +1764,43 @@ proc parseSection(p: var TParser, kind: TNodeKind,
|
|||
else:
|
||||
parMessage(p, errIdentifierExpected, p.tok)
|
||||
|
||||
proc parseConstant(p: var TParser): PNode =
|
||||
#| constant = identWithPragma (colon typeDesc)? '=' optInd expr indAndComment
|
||||
result = newNodeP(nkConstDef, p)
|
||||
addSon(result, identWithPragma(p))
|
||||
if p.tok.tokType == tkColon:
|
||||
proc parseConstTuple(p: var TParser): PNode =
|
||||
result = newNodeP(nkConstTuple, p)
|
||||
getTok(p) # skip '('
|
||||
optInd(p, result)
|
||||
while p.tok.tokType in {tkSymbol, tkAccent}:
|
||||
addSon(result, identWithPragma(p))
|
||||
if p.tok.tokType == tkColon:
|
||||
getTok(p)
|
||||
optInd(p, result)
|
||||
addSon(result, parseTypeDesc(p))
|
||||
if p.tok.tokType != tkComma: break
|
||||
getTok(p)
|
||||
optInd(p, result)
|
||||
addSon(result, parseTypeDesc(p))
|
||||
else:
|
||||
addSon(result, p.emptyNode)
|
||||
|
||||
addSon(result, p.emptyNode)
|
||||
eat(p, tkParRi)
|
||||
eat(p, tkEquals)
|
||||
optInd(p, result)
|
||||
addSon(result, parseExpr(p))
|
||||
indAndComment(p, result)
|
||||
|
||||
proc parseConstant(p: var TParser): PNode =
|
||||
#| constant = identWithPragma (colon typeDesc)? '=' optInd expr indAndComment
|
||||
if p.tok.tokType == tkParLe: result = parseConstTuple(p)
|
||||
else:
|
||||
result = newNodeP(nkConstDef, p)
|
||||
addSon(result, identWithPragma(p))
|
||||
if p.tok.tokType == tkColon:
|
||||
getTok(p)
|
||||
optInd(p, result)
|
||||
addSon(result, parseTypeDesc(p))
|
||||
else:
|
||||
addSon(result, p.emptyNode)
|
||||
eat(p, tkEquals)
|
||||
optInd(p, result)
|
||||
addSon(result, parseExpr(p))
|
||||
indAndComment(p, result)
|
||||
|
||||
proc parseEnum(p: var TParser): PNode =
|
||||
#| enum = 'enum' optInd (symbol optInd ('=' optInd expr COMMENT?)? comma?)+
|
||||
result = newNodeP(nkEnumTy, p)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue