parsecfgex.nim 578 B

1234567891011121314151617181920212223242526
  1. import
  2. os, parsecfg, strutils, streams
  3. var f = newFileStream(paramStr(1), fmRead)
  4. if f != nil:
  5. var p: CfgParser
  6. open(p, f, paramStr(1))
  7. while true:
  8. var e = next(p)
  9. case e.kind
  10. of cfgEof:
  11. echo("EOF!")
  12. break
  13. of cfgSectionStart: ## a ``[section]`` has been parsed
  14. echo("new section: " & e.section)
  15. of cfgKeyValuePair:
  16. echo("key-value-pair: " & e.key & ": " & e.value)
  17. of cfgOption:
  18. echo("command: " & e.key & ": " & e.value)
  19. of cfgError:
  20. echo(e.msg)
  21. close(p)
  22. else:
  23. echo("cannot open: " & paramStr(1))