From a0ecf4d21667a10f7ae9c4871dd0026871a7df72 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 18 May 2020 16:58:07 -0600 Subject: [PATCH] Remove regex from comment processing --- nimterop/tshelp.nim | 12 ++++++++---- 1 file 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``