Skip to content

Commit

Permalink
rst: fix bug 20 from nim-lang#17340
Browse files Browse the repository at this point in the history
and a leftover bug: priority of option list inside definition list
  • Loading branch information
a-mr committed Jun 25, 2021
1 parent f6bea08 commit d56a74f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/packages/docutils/rst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ proc parseOptionList(p: var RstParser): PRstNode =
popInd(p)
else:
parseLine(p, b)
if currentTok(p).kind == tkIndent: inc p.idx
while currentTok(p).kind == tkIndent: inc p.idx
c.add(a)
c.add(b)
c.order = order; inc order
Expand All @@ -2262,6 +2262,8 @@ proc parseDefinitionList(p: var RstParser): PRstNode =
var col = currentTok(p).col
result = newRstNodeA(p, rnDefList)
while true:
if isOptionList(p):
break # option list has priority over def.list
j = p.idx
var a = newRstNode(rnDefName)
parseLine(p, a)
Expand Down
47 changes: 47 additions & 0 deletions tests/stdlib/trst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,53 @@ suite "RST parsing":
rnLeaf 'set'
""")

test "items of 1 option list can be separated by blank lines":
check(dedent"""
-a desc1
-b desc2
""".toAst ==
dedent"""
rnOptionList
rnOptionListItem order=1
rnOptionGroup
rnLeaf '-'
rnLeaf 'a'
rnDescription
rnLeaf 'desc1'
rnOptionListItem order=2
rnOptionGroup
rnLeaf '-'
rnLeaf 'b'
rnDescription
rnLeaf 'desc2'
""")

test "option list has priority over definition list":
check(dedent"""
defName
defBody
-b desc2
""".toAst ==
dedent"""
rnInner
rnDefList
rnDefItem
rnDefName
rnLeaf 'defName'
rnDefBody
rnInner
rnLeaf 'defBody'
rnOptionList
rnOptionListItem order=1
rnOptionGroup
rnLeaf '-'
rnLeaf 'b'
rnDescription
rnLeaf 'desc2'
""")

test "RST comment":
check(dedent"""
.. comment1
Expand Down

0 comments on commit d56a74f

Please sign in to comment.