summary refs log tree commit diff stats
path: root/lib/packages
diff options
context:
space:
mode:
authorAndrey Makarov <ph.makarov@gmail.com>2021-06-24 11:28:28 +0300
committerGitHub <noreply@github.com>2021-06-24 10:28:28 +0200
commit0c8d3ae9852721147ddf878e204c14e949ed676a (patch)
tree744fc8f40b44f723ca67bea9a2d70ff4dc78a55a /lib/packages
parent55c1953f636ff2d2e2b9e9599194fa6c3fb49050 (diff)
downloadNim-0c8d3ae9852721147ddf878e204c14e949ed676a.tar.gz
rst: allow comment to continue on second line (#18338)
Diffstat (limited to 'lib/packages')
-rw-r--r--lib/packages/docutils/rst.nim28
1 files changed, 10 insertions, 18 deletions
diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim
index 7833e6e9a..8ffbbd4d3 100644
--- a/lib/packages/docutils/rst.nim
+++ b/lib/packages/docutils/rst.nim
@@ -1615,24 +1615,16 @@ proc getDirective(p: var RstParser): string =
             "too many colons for a directive (should be ::)",
             p.tok[afterIdx].line, p.tok[afterIdx].col)
 
-proc parseComment(p: var RstParser): PRstNode =
-  case currentTok(p).kind
-  of tkIndent, tkEof:
-    if currentTok(p).kind != tkEof and nextTok(p).kind == tkIndent:
-      inc p.idx              # empty comment
-    else:
-      var indent = currentTok(p).ival
-      while true:
-        case currentTok(p).kind
-        of tkEof:
-          break
-        of tkIndent:
-          if currentTok(p).ival < indent: break
-        else:
-          discard
-        inc p.idx
+proc parseComment(p: var RstParser, col: int): PRstNode =
+  if currentTok(p).kind != tkEof and nextTok(p).kind == tkIndent:
+    inc p.idx              # empty comment
   else:
-    while currentTok(p).kind notin {tkIndent, tkEof}: inc p.idx
+    while currentTok(p).kind != tkEof:
+      if currentTok(p).kind == tkIndent and currentTok(p).ival > col or
+         currentTok(p).kind != tkIndent and currentTok(p).col > col:
+        inc p.idx
+      else:
+        break
   result = nil
 
 proc parseLine(p: var RstParser, father: PRstNode) =
@@ -2841,7 +2833,7 @@ proc parseDotDot(p: var RstParser): PRstNode =
       (n = parseFootnote(p); n != nil):
     result = n
   else:
-    result = parseComment(p)
+    result = parseComment(p, col)
 
 proc rstParsePass1*(fragment, filename: string,
                     line, column: int,