Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created December 28, 2019 23:26
Show Gist options
  • Save halfdan/06e49a1676e7e486c794c34906356c76 to your computer and use it in GitHub Desktop.
Save halfdan/06e49a1676e7e486c794c34906356c76 to your computer and use it in GitHub Desktop.
import os, streams, parsecsv, options, json
type
Filter = object
column: string
`include`: bool
values: seq
min: Option[string]
max: Option[string]
Configuration = ref object
output: string
filters: seq[Filter]
proc main() =
if paramCount() < 2:
quit("synopsis: " & getAppFilename() & " input config")
let
inputFilename = paramStr(1)
configFilename = paramStr(2)
var
inputFile = newFileStream(inputFilename, fmRead)
configFile = newFileStream(configFilename, fmRead)
if inputFile == nil:
quit("cannot open the file " & inputFilename)
defer: inputFile.close()
defer: configFile.close()
let configJson = parseJson(configFile, configFilename)
let config = to(configJson, seq[Configuration])
echo len(config)
main()
stack trace: (most recent call last)
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1565, 38) to
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1359, 46) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1410, 33) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1348, 27) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1212, 29) processType
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1169, 34) processFields
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1127, 40) processObjField
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1359, 46) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1412, 27) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1212, 29) processType
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1169, 34) processFields
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1127, 40) processObjField
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1410, 33) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1359, 46) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1412, 27) createConstructor
/usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1269, 11) processType
/usr/local/Cellar/nim/1.0.4/nim/lib/system/assertions.nim(27, 20) failedAssertImpl
/usr/local/Cellar/nim/1.0.4/nim/lib/system/assertions.nim(20, 11) raiseAssert
/usr/local/Cellar/nim/1.0.4/nim/lib/system/fatal.nim(39, 5) sysFatal
/Users/halfdan/Projects/dev/filter-csv.nim/filter_csv.nim(34, 18) template/generic instantiation of `to` from here
/usr/local/Cellar/nim/1.0.4/nim/lib/system/fatal.nim(39, 5) Error: unhandled exception: /usr/local/Cellar/nim/1.0.4/nim/lib/pure/json.nim(1269, 18) `false` Unable to process nnkSym T [AssertionError]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment