fixes #1799 properly
This commit is contained in:
parent
c1c76a20e6
commit
cd7b5ae1eb
2 changed files with 86 additions and 8 deletions
|
|
@ -123,6 +123,9 @@ proc rawSkipComment(p: var TParser, node: PNode) =
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
|
||||||
proc skipComment(p: var TParser, node: PNode) =
|
proc skipComment(p: var TParser, node: PNode) =
|
||||||
|
if p.tok.indent < 0: rawSkipComment(p, node)
|
||||||
|
|
||||||
|
proc flexComment(p: var TParser, node: PNode) =
|
||||||
if p.tok.indent < 0 or realInd(p): rawSkipComment(p, node)
|
if p.tok.indent < 0 or realInd(p): rawSkipComment(p, node)
|
||||||
|
|
||||||
proc skipInd(p: var TParser) =
|
proc skipInd(p: var TParser) =
|
||||||
|
|
@ -892,7 +895,8 @@ proc parseTuple(p: var TParser, indentAllowed = false): PNode =
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkSymbol, tkAccent:
|
of tkSymbol, tkAccent:
|
||||||
var a = parseIdentColonEquals(p, {})
|
var a = parseIdentColonEquals(p, {})
|
||||||
skipComment(p, a)
|
if p.tok.indent < 0 or p.tok.indent >= p.currInd:
|
||||||
|
rawSkipComment(p, a)
|
||||||
addSon(result, a)
|
addSon(result, a)
|
||||||
of tkEof: break
|
of tkEof: break
|
||||||
else:
|
else:
|
||||||
|
|
@ -1608,7 +1612,7 @@ proc parseEnum(p: var TParser): PNode =
|
||||||
getTok(p)
|
getTok(p)
|
||||||
addSon(result, ast.emptyNode)
|
addSon(result, ast.emptyNode)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
rawSkipComment(p, result)
|
flexComment(p, result)
|
||||||
while true:
|
while true:
|
||||||
var a = parseSymbol(p)
|
var a = parseSymbol(p)
|
||||||
if a.kind == nkEmpty: return
|
if a.kind == nkEmpty: return
|
||||||
|
|
@ -1622,12 +1626,14 @@ proc parseEnum(p: var TParser): PNode =
|
||||||
a = newNodeP(nkEnumFieldDef, p)
|
a = newNodeP(nkEnumFieldDef, p)
|
||||||
addSon(a, b)
|
addSon(a, b)
|
||||||
addSon(a, parseExpr(p))
|
addSon(a, parseExpr(p))
|
||||||
skipComment(p, a)
|
if p.tok.indent < 0 or p.tok.indent >= p.currInd:
|
||||||
|
rawSkipComment(p, a)
|
||||||
if p.tok.tokType == tkComma and p.tok.indent < 0:
|
if p.tok.tokType == tkComma and p.tok.indent < 0:
|
||||||
getTok(p)
|
getTok(p)
|
||||||
rawSkipComment(p, a)
|
rawSkipComment(p, a)
|
||||||
else:
|
else:
|
||||||
skipComment(p, a)
|
if p.tok.indent < 0 or p.tok.indent >= p.currInd:
|
||||||
|
rawSkipComment(p, a)
|
||||||
addSon(result, a)
|
addSon(result, a)
|
||||||
if p.tok.indent >= 0 and p.tok.indent <= p.currInd or
|
if p.tok.indent >= 0 and p.tok.indent <= p.currInd or
|
||||||
p.tok.tokType == tkEof:
|
p.tok.tokType == tkEof:
|
||||||
|
|
@ -1648,7 +1654,7 @@ proc parseObjectWhen(p: var TParser): PNode =
|
||||||
addSon(branch, parseExpr(p))
|
addSon(branch, parseExpr(p))
|
||||||
colcom(p, branch)
|
colcom(p, branch)
|
||||||
addSon(branch, parseObjectPart(p))
|
addSon(branch, parseObjectPart(p))
|
||||||
skipComment(p, branch)
|
flexComment(p, branch)
|
||||||
addSon(result, branch)
|
addSon(result, branch)
|
||||||
if p.tok.tokType != tkElif: break
|
if p.tok.tokType != tkElif: break
|
||||||
if p.tok.tokType == tkElse and sameInd(p):
|
if p.tok.tokType == tkElse and sameInd(p):
|
||||||
|
|
@ -1656,7 +1662,7 @@ proc parseObjectWhen(p: var TParser): PNode =
|
||||||
eat(p, tkElse)
|
eat(p, tkElse)
|
||||||
colcom(p, branch)
|
colcom(p, branch)
|
||||||
addSon(branch, parseObjectPart(p))
|
addSon(branch, parseObjectPart(p))
|
||||||
skipComment(p, branch)
|
flexComment(p, branch)
|
||||||
addSon(result, branch)
|
addSon(result, branch)
|
||||||
|
|
||||||
proc parseObjectCase(p: var TParser): PNode =
|
proc parseObjectCase(p: var TParser): PNode =
|
||||||
|
|
@ -1676,7 +1682,7 @@ proc parseObjectCase(p: var TParser): PNode =
|
||||||
addSon(a, ast.emptyNode)
|
addSon(a, ast.emptyNode)
|
||||||
addSon(result, a)
|
addSon(result, a)
|
||||||
if p.tok.tokType == tkColon: getTok(p)
|
if p.tok.tokType == tkColon: getTok(p)
|
||||||
skipComment(p, result)
|
flexComment(p, result)
|
||||||
var wasIndented = false
|
var wasIndented = false
|
||||||
let oldInd = p.currInd
|
let oldInd = p.currInd
|
||||||
if realInd(p):
|
if realInd(p):
|
||||||
|
|
@ -1725,7 +1731,8 @@ proc parseObjectPart(p: var TParser): PNode =
|
||||||
result = parseObjectCase(p)
|
result = parseObjectCase(p)
|
||||||
of tkSymbol, tkAccent:
|
of tkSymbol, tkAccent:
|
||||||
result = parseIdentColonEquals(p, {withPragma})
|
result = parseIdentColonEquals(p, {withPragma})
|
||||||
skipComment(p, result)
|
if p.tok.indent < 0 or p.tok.indent >= p.currInd:
|
||||||
|
rawSkipComment(p, result)
|
||||||
of tkNil, tkDiscard:
|
of tkNil, tkDiscard:
|
||||||
result = newNodeP(nkNilLit, p)
|
result = newNodeP(nkNilLit, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
|
|
||||||
71
tests/parser/tdoc_comments.nim
Normal file
71
tests/parser/tdoc_comments.nim
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
|
||||||
|
# bug #1799
|
||||||
|
|
||||||
|
proc MyProc1*() = ## Comment behind procedure
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc MyProc2*() =
|
||||||
|
## Comment below procedure
|
||||||
|
discard
|
||||||
|
|
||||||
|
|
||||||
|
template MyTemplate1*() = discard ## Comment behind template
|
||||||
|
|
||||||
|
template MyTemplate2*() = discard
|
||||||
|
## Comment below template
|
||||||
|
|
||||||
|
|
||||||
|
const
|
||||||
|
MyConst1* = 1 ## Comment behind constant
|
||||||
|
MyConst2* = 2
|
||||||
|
## Comment below constant
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
MyVar1* = 1 ## Comment behind variable
|
||||||
|
MyVar2* = 2
|
||||||
|
## Comment below variable
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
MyObject1* = object
|
||||||
|
## Comment below declaration
|
||||||
|
field1*: int ## Comment behind field
|
||||||
|
field2*: int ## Comment behind field
|
||||||
|
field3*: int
|
||||||
|
## Comment below field
|
||||||
|
field4*: int
|
||||||
|
## Comment below field
|
||||||
|
|
||||||
|
MyObject2* = object ## Comment behind declaration
|
||||||
|
field1*: int
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
MyTuple1* = tuple
|
||||||
|
## Comment below declaration
|
||||||
|
field1: int ## Comment behind field
|
||||||
|
field2: int ## Comment behind field
|
||||||
|
field3: int
|
||||||
|
## Comment below field
|
||||||
|
field4: int
|
||||||
|
## Comment below field
|
||||||
|
|
||||||
|
MyTuple2* = tuple ## Comment behind declaration
|
||||||
|
field1: int
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
MyEnum1* = enum
|
||||||
|
## Comment below declaration
|
||||||
|
value1, ## Comment behind value
|
||||||
|
value2,
|
||||||
|
## Comment below value with comma
|
||||||
|
value3
|
||||||
|
## Comment below value without comma
|
||||||
|
|
||||||
|
MyEnum2* = enum ## Comment behind declaration
|
||||||
|
value4
|
||||||
|
|
||||||
|
MyEnum3* = enum
|
||||||
|
value5 ## only document the enum value
|
||||||
Loading…
Add table
Add a link
Reference in a new issue