aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2020-05-18 16:58:07 -0600
committergenotrance <dev@genotrance.com>2020-05-18 23:46:47 -0500
commit5895db1d18e1d3c9f1e502f0a68f671d4e53e02b (patch)
tree4690fb4d953121f25caacd3ed9a4a9a1cb449a0b
parentffd6b9b5eb6be220b05178438aa622cda047d9d5 (diff)
downloadnimterop-5895db1d18e1d3c9f1e502f0a68f671d4e53e02b.tar.gz
nimterop-5895db1d18e1d3c9f1e502f0a68f671d4e53e02b.zip
Remove regex from comment processing
-rw-r--r--nimterop/tshelp.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/nimterop/tshelp.nim b/nimterop/tshelp.nim
index 762cf7c..9565a1f 100644
--- a/nimterop/tshelp.nim
+++ b/nimterop/tshelp.nim
@@ -1,7 +1,5 @@
import sets, strformat, strutils
-import regex
-
import "."/[getters, globals]
import "."/treesitter/[api, c, cpp]
@@ -273,8 +271,14 @@ proc getCommentsStr*(gState: State, commentNodes: seq[TSNode]): string =
for commentNode in commentNodes:
result &= "\n " & gState.getNodeVal(commentNode).strip()
- result = result.replace(re" *(//|/\*\*|\*\*/|/\*|\*/|\*)", "")
- result = result.multiReplace([("\n", "\n "), ("`", "")]).strip()
+ result = result.multiReplace(
+ {
+ "/**": "", "**/": "", "/*": "",
+ "*/": "", "/*": "", "//": "",
+ "\n": "\n ", "`": ""
+ }
+ # need to replace this last otherwise it supercedes other replacements
+ ).replace(" *", "").strip()
proc getCommentNodes*(gState: State, node: TSNode, maxSearch=1): seq[TSNode] =
## Get a set of comment nodes in order of priority. Will search up to ``maxSearch``