Files
Nim/examples/parsecfgex.nim
Adam Strzelecki 5d80548cce examples: Trim .nim files trailing whitespace
via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
2015-09-04 23:05:22 +02:00

26 lines
578 B
Nim

import
os, parsecfg, strutils, streams
var f = newFileStream(paramStr(1), fmRead)
if f != nil:
var p: CfgParser
open(p, f, paramStr(1))
while true:
var e = next(p)
case e.kind
of cfgEof:
echo("EOF!")
break
of cfgSectionStart: ## a ``[section]`` has been parsed
echo("new section: " & e.section)
of cfgKeyValuePair:
echo("key-value-pair: " & e.key & ": " & e.value)
of cfgOption:
echo("command: " & e.key & ": " & e.value)
of cfgError:
echo(e.msg)
close(p)
else:
echo("cannot open: " & paramStr(1))