diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-05-08 20:54:03 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-05-08 20:54:03 -0500 |
| commit | d9ab18c7757193f14fac69f3b462981b79defc93 (patch) | |
| tree | bbc616b5509e2dc14d40330bcc8d2c16d55877d8 | |
| parent | b0a8f9bec5fb00ecf070a445f1b3b6a419fee103 (diff) | |
| download | nimterop-pragma.tar.gz nimterop-pragma.zip | |
Exclude comments from output with flagpragma
| -rw-r--r-- | nimterop.nimble | 9 | ||||
| -rw-r--r-- | nimterop/globals.nim | 4 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 2 | ||||
| -rw-r--r-- | nimterop/toast.nim | 39 |
4 files changed, 27 insertions, 27 deletions
diff --git a/nimterop.nimble b/nimterop.nimble index c53e4dc..a9a99ee 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -27,12 +27,9 @@ proc execTest(test: string) = proc tsoloud() = execTest "tests/tsoloud.nim" -proc buildToast() = - execCmd(&"nim c -d:release nimterop/toast.nim") - -task rebuildToast, "rebuild toast": +task buildToast, "build toast": # If need to manually rebuild (automatically built on 1st need) - buildToast() + execCmd(&"nim c -d:release nimterop/toast.nim") proc testAll() = execTest "tests/tnimterop_c.nim" @@ -69,7 +66,7 @@ proc runNimDoc() = execCmd &"nim js -o:{htmldocsDir}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim" task test, "Test": - buildToast() + buildToastTask() testAll() runNimDoc() diff --git a/nimterop/globals.nim b/nimterop/globals.nim index 10b6ac3..1bef589 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -55,7 +55,7 @@ type State = ref object 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 @@ -64,7 +64,7 @@ type NimState {.used.} = ref object identifiers*: TableRef[string, string] - constStr*, debugStr*, enumStr*, procStr*, typeStr*, commentStr*: string + commentStr*, constStr*, debugStr*, enumStr*, procStr*, typeStr*: string gState*: State diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index f9bb2cb..3010966 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -24,7 +24,7 @@ proc genPragma(nimState: NimState, pragmas: varargs[string]): string = result = result.replace(nimState.impHeader & ", cdecl", nimState.impHeader & "C") proc getComments(nimState: NimState): string = - if nimState.commentStr.len != 0: + if not nimState.gState.nocomments and nimState.commentStr.len != 0: result = "\n" & nimState.commentStr nimState.commentStr = "" diff --git a/nimterop/toast.nim b/nimterop/toast.nim index bf34f41..eed39d8 100644 --- a/nimterop/toast.nim +++ b/nimterop/toast.nim @@ -98,33 +98,34 @@ proc process(gState: State, path: string, astTable: AstTable) = echo gState.code proc main( - mode = modeDefault, + preprocess = false, past = false, pnim = false, - pretty = true, - preprocess = false, - pgrammar = false, recurse = false, - debug = false, + nocomments = false, defines: seq[string] = @[], includeDirs: seq[string] = @[], symOverride: seq[string] = @[], pluginSourcePath: string = "", - source: seq[string], + debug = false, + mode = modeDefault, + pgrammar = false, + source: seq[string] ) = var gState = State( - mode: mode, + preprocess: preprocess, past: past, pnim: pnim, - pretty: pretty, - preprocess: preprocess, recurse: recurse, - debug: debug, + nocomments: nocomments, defines: defines, includeDirs: includeDirs, symOverride: symOverride, - pluginSourcePath: pluginSourcePath + pluginSourcePath: pluginSourcePath, + debug: debug, + mode: mode, + pretty: true ) gState.symOverride = gState.symOverride.getSplitComma() @@ -145,26 +146,28 @@ proc main( when isMainModule: import cligen dispatch(main, help = { + "preprocess": "run preprocessor on header", "past": "print AST output", - "mode": "language; see CompileMode", # TODO: auto-generate valid choices "pnim": "print Nim output", + "recurse": "process #include files", + "nocomments": "exclude top-level comments from output", "defines": "definitions to pass to preprocessor", "includeDirs": "include directory to pass to preprocessor", "symOverride": "skip generating specified symbols", "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", - "source" : "C/C++ source/header", + "mode": "language parser: c or cpp", + "pgrammar": "print grammar", + "source" : "C/C++ source/header" }, short = { + "preprocess": 'p', "past": 'a', "pnim": 'n', + "recurse": 'r', + "nocomments": 'c', "defines": 'D', "includeDirs": 'I', "symOverride": 'O', - "preprocess": 'p', - "recurse": 'r', "debug": 'd', "pgrammar": 'g' }) |
