aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-12-05 00:14:38 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-12-05 00:14:38 -0600
commit7c8afa19975517b18553f2eb3007c0e279360299 (patch)
tree5394425f598ce828c056011469c0703bd4f42225
parentdfe06fd9d474c368cb6c724902dd20369d68f1b6 (diff)
downloadnimterop-7c8afa19975517b18553f2eb3007c0e279360299.tar.gz
nimterop-7c8afa19975517b18553f2eb3007c0e279360299.zip
Fix default cpp mode, print row col length in AST output
-rw-r--r--toast.nim15
1 files changed, 8 insertions, 7 deletions
diff --git a/toast.nim b/toast.nim
index 7511d8d..5885bc2 100644
--- a/toast.nim
+++ b/toast.nim
@@ -1,4 +1,4 @@
-import os, strutils
+import os, strformat, strutils
import treesitter/[runtime, c, cpp]
@@ -14,7 +14,9 @@ proc printLisp(root: TSNode) =
if not node.tsNodeIsNull():
if gStateRT.pretty:
stdout.write spaces(depth)
- stdout.write "(" & $node.tsNodeType() & " " & $node.tsNodeStartByte() & " " & $node.tsNodeEndByte()
+ let
+ (line, col) = node.getLineCol()
+ stdout.write &"({$node.tsNodeType()} {line} {col} {node.tsNodeEndByte() - node.tsNodeStartByte()}"
else:
return
@@ -66,11 +68,10 @@ proc process(path: string) =
gStateRT.sourceFile = path
if gStateRT.mode.len == 0:
- gStateRT.mode = modeDefault
- elif ext in [".h", ".c"]:
- gStateRT.mode = "c"
- elif ext in [".hxx", ".hpp", ".hh", ".H", ".h++", ".cpp", ".cxx", ".cc", ".C", ".c++"]:
- gStateRT.mode = "cpp"
+ if ext in [".h", ".c"]:
+ gStateRT.mode = "c"
+ elif ext in [".hxx", ".hpp", ".hh", ".H", ".h++", ".cpp", ".cxx", ".cc", ".C", ".c++"]:
+ gStateRT.mode = "cpp"
if gStateRT.preprocess:
gStateRT.code = getPreprocessor(path)