mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-21 06:45:27 +00:00
Pragma syntax is now consistent (#9993)
* Give deprecation warning when type pragmas do not follow the type name * pragma before generic parameter list in type definition is now deprecated * Update changelog * Fix bug where deprecated warning was being shown even though no generic param list was present * Fix bug * Use errGenerated * Best attempt at writing the grammar
This commit is contained in:
committed by
Andreas Rumpf
parent
8948894713
commit
05b8085a87
@@ -141,6 +141,12 @@ proc enumToString*(enums: openArray[enum]): string =
|
||||
it's more recognizable and allows tools like github to recognize it as Nim,
|
||||
see [#9647](https://github.com/nim-lang/Nim/issues/9647).
|
||||
The previous extension will continue to work.
|
||||
- Pragma syntax is now consistent. Previous syntax where type pragmas did not
|
||||
follow the type name is now deprecated. Also pragma before generic parameter
|
||||
list is deprecated to be consistent with how pragmas are used with a proc. See
|
||||
[#8514](https://github.com/nim-lang/Nim/issues/8514) and
|
||||
[#1872](https://github.com/nim-lang/Nim/issues/1872) for further details.
|
||||
|
||||
|
||||
### Tool changes
|
||||
- `jsondoc` now include a `moduleDescription` field with the module
|
||||
|
||||
@@ -1905,6 +1905,8 @@ proc parseObject(p: var TParser): PNode =
|
||||
result = newNodeP(nkObjectTy, p)
|
||||
getTok(p)
|
||||
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
||||
# Deprecated since v0.20.0
|
||||
parMessage(p, warnDeprecated, "type pragmas follow the type name; this form of writing pragmas")
|
||||
addSon(result, parsePragma(p))
|
||||
else:
|
||||
addSon(result, p.emptyNode)
|
||||
@@ -1977,13 +1979,42 @@ proc parseTypeClass(p: var TParser): PNode =
|
||||
proc parseTypeDef(p: var TParser): PNode =
|
||||
#|
|
||||
#| typeDef = identWithPragmaDot genericParamList? '=' optInd typeDefAux
|
||||
#| indAndComment? / identVisDot genericParamList? pragma '=' optInd typeDefAux
|
||||
#| indAndComment?
|
||||
result = newNodeP(nkTypeDef, p)
|
||||
addSon(result, identWithPragma(p, allowDot=true))
|
||||
var identifier = identVis(p, allowDot=true)
|
||||
var identPragma = identifier
|
||||
var pragma: PNode
|
||||
var genericParam: PNode
|
||||
var noPragmaYet = true
|
||||
|
||||
if p.tok.tokType == tkCurlyDotLe:
|
||||
pragma = optPragmas(p)
|
||||
identPragma = newNodeP(nkPragmaExpr, p)
|
||||
addSon(identPragma, identifier)
|
||||
addSon(identPragma, pragma)
|
||||
noPragmaYet = false
|
||||
|
||||
if p.tok.tokType == tkBracketLe and p.validInd:
|
||||
addSon(result, parseGenericParamList(p))
|
||||
if not noPragmaYet:
|
||||
# Deprecated since v0.20.0
|
||||
parMessage(p, warnDeprecated, "pragma before generic parameter list")
|
||||
genericParam = parseGenericParamList(p)
|
||||
else:
|
||||
addSon(result, p.emptyNode)
|
||||
genericParam = p.emptyNode
|
||||
|
||||
if noPragmaYet:
|
||||
pragma = optPragmas(p)
|
||||
if pragma.kind != nkEmpty:
|
||||
identPragma = newNodeP(nkPragmaExpr, p)
|
||||
addSon(identPragma, identifier)
|
||||
addSon(identPragma, pragma)
|
||||
elif p.tok.tokType == tkCurlyDotLe:
|
||||
parMessage(p, errGenerated, "pragma already present")
|
||||
|
||||
addSon(result, identPragma)
|
||||
addSon(result, genericParam)
|
||||
|
||||
if p.tok.tokType == tkEquals:
|
||||
result.info = parLineInfo(p)
|
||||
getTok(p)
|
||||
|
||||
Reference in New Issue
Block a user