Exclude comments from output with flag

This commit is contained in:
Ganesh Viswanathan 2019-05-08 20:54:03 -05:00
commit d9ab18c775
4 changed files with 27 additions and 27 deletions

View file

@ -27,12 +27,9 @@ proc execTest(test: string) =
proc tsoloud() = proc tsoloud() =
execTest "tests/tsoloud.nim" execTest "tests/tsoloud.nim"
proc buildToast() = task buildToast, "build toast":
execCmd(&"nim c -d:release nimterop/toast.nim")
task rebuildToast, "rebuild toast":
# If need to manually rebuild (automatically built on 1st need) # If need to manually rebuild (automatically built on 1st need)
buildToast() execCmd(&"nim c -d:release nimterop/toast.nim")
proc testAll() = proc testAll() =
execTest "tests/tnimterop_c.nim" execTest "tests/tnimterop_c.nim"
@ -69,7 +66,7 @@ proc runNimDoc() =
execCmd &"nim js -o:{htmldocsDir}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim" execCmd &"nim js -o:{htmldocsDir}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim"
task test, "Test": task test, "Test":
buildToast() buildToastTask()
testAll() testAll()
runNimDoc() runNimDoc()

View file

@ -55,7 +55,7 @@ type
State = ref object State = ref object
compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string] compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string]
nocache*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool nocache*, nocomments*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool
code*, mode*, pluginSourcePath*: string code*, mode*, pluginSourcePath*: string
@ -64,7 +64,7 @@ type
NimState {.used.} = ref object NimState {.used.} = ref object
identifiers*: TableRef[string, string] identifiers*: TableRef[string, string]
constStr*, debugStr*, enumStr*, procStr*, typeStr*, commentStr*: string commentStr*, constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
gState*: State gState*: State

View file

@ -24,7 +24,7 @@ proc genPragma(nimState: NimState, pragmas: varargs[string]): string =
result = result.replace(nimState.impHeader & ", cdecl", nimState.impHeader & "C") result = result.replace(nimState.impHeader & ", cdecl", nimState.impHeader & "C")
proc getComments(nimState: NimState): string = proc getComments(nimState: NimState): string =
if nimState.commentStr.len != 0: if not nimState.gState.nocomments and nimState.commentStr.len != 0:
result = "\n" & nimState.commentStr result = "\n" & nimState.commentStr
nimState.commentStr = "" nimState.commentStr = ""

View file

@ -98,33 +98,34 @@ proc process(gState: State, path: string, astTable: AstTable) =
echo gState.code echo gState.code
proc main( proc main(
mode = modeDefault, preprocess = false,
past = false, past = false,
pnim = false, pnim = false,
pretty = true,
preprocess = false,
pgrammar = false,
recurse = false, recurse = false,
debug = false, nocomments = false,
defines: seq[string] = @[], defines: seq[string] = @[],
includeDirs: seq[string] = @[], includeDirs: seq[string] = @[],
symOverride: seq[string] = @[], symOverride: seq[string] = @[],
pluginSourcePath: string = "", pluginSourcePath: string = "",
source: seq[string], debug = false,
mode = modeDefault,
pgrammar = false,
source: seq[string]
) = ) =
var gState = State( var gState = State(
mode: mode, preprocess: preprocess,
past: past, past: past,
pnim: pnim, pnim: pnim,
pretty: pretty,
preprocess: preprocess,
recurse: recurse, recurse: recurse,
debug: debug, nocomments: nocomments,
defines: defines, defines: defines,
includeDirs: includeDirs, includeDirs: includeDirs,
symOverride: symOverride, symOverride: symOverride,
pluginSourcePath: pluginSourcePath pluginSourcePath: pluginSourcePath,
debug: debug,
mode: mode,
pretty: true
) )
gState.symOverride = gState.symOverride.getSplitComma() gState.symOverride = gState.symOverride.getSplitComma()
@ -145,26 +146,28 @@ proc main(
when isMainModule: when isMainModule:
import cligen import cligen
dispatch(main, help = { dispatch(main, help = {
"preprocess": "run preprocessor on header",
"past": "print AST output", "past": "print AST output",
"mode": "language; see CompileMode", # TODO: auto-generate valid choices
"pnim": "print Nim output", "pnim": "print Nim output",
"recurse": "process #include files",
"nocomments": "exclude top-level comments from output",
"defines": "definitions to pass to preprocessor", "defines": "definitions to pass to preprocessor",
"includeDirs": "include directory to pass to preprocessor", "includeDirs": "include directory to pass to preprocessor",
"symOverride": "skip generating specified symbols", "symOverride": "skip generating specified symbols",
"pluginSourcePath": "Nim file to build and load as a plugin", "pluginSourcePath": "Nim file to build and load as a plugin",
"preprocess": "run preprocessor on header",
"pgrammar": "print grammar",
"recurse": "process #include files",
"debug": "enable debug output", "debug": "enable debug output",
"source" : "C/C++ source/header", "mode": "language parser: c or cpp",
"pgrammar": "print grammar",
"source" : "C/C++ source/header"
}, short = { }, short = {
"preprocess": 'p',
"past": 'a', "past": 'a',
"pnim": 'n', "pnim": 'n',
"recurse": 'r',
"nocomments": 'c',
"defines": 'D', "defines": 'D',
"includeDirs": 'I', "includeDirs": 'I',
"symOverride": 'O', "symOverride": 'O',
"preprocess": 'p',
"recurse": 'r',
"debug": 'd', "debug": 'd',
"pgrammar": 'g' "pgrammar": 'g'
}) })