Fix default cpp mode, print row col length in AST output

This commit is contained in:
Ganesh Viswanathan 2018-12-05 00:14:38 -06:00
commit 7c8afa1997

View file

@ -1,4 +1,4 @@
import os, strutils import os, strformat, strutils
import treesitter/[runtime, c, cpp] import treesitter/[runtime, c, cpp]
@ -14,7 +14,9 @@ proc printLisp(root: TSNode) =
if not node.tsNodeIsNull(): if not node.tsNodeIsNull():
if gStateRT.pretty: if gStateRT.pretty:
stdout.write spaces(depth) 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: else:
return return
@ -66,11 +68,10 @@ proc process(path: string) =
gStateRT.sourceFile = path gStateRT.sourceFile = path
if gStateRT.mode.len == 0: if gStateRT.mode.len == 0:
gStateRT.mode = modeDefault if ext in [".h", ".c"]:
elif ext in [".h", ".c"]: gStateRT.mode = "c"
gStateRT.mode = "c" elif ext in [".hxx", ".hpp", ".hh", ".H", ".h++", ".cpp", ".cxx", ".cc", ".C", ".c++"]:
elif ext in [".hxx", ".hpp", ".hh", ".H", ".h++", ".cpp", ".cxx", ".cc", ".C", ".c++"]: gStateRT.mode = "cpp"
gStateRT.mode = "cpp"
if gStateRT.preprocess: if gStateRT.preprocess:
gStateRT.code = getPreprocessor(path) gStateRT.code = getPreprocessor(path)