diff options
author | Araq <rumpf_a@web.de> | 2011-02-20 20:12:22 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-02-20 20:12:22 +0100 |
commit | 2cdfe35e737291e65060e2f954d718316a969048 (patch) | |
tree | a39553bd397311c4601dde11be37c50ad99d81ab /lib/pure/parsecfg.nim | |
parent | cbee9c4e1a1252e6c809d25a0ef371ddee3fc802 (diff) | |
download | Nim-2cdfe35e737291e65060e2f954d718316a969048.tar.gz |
tests themselves contain the expected result
Diffstat (limited to 'lib/pure/parsecfg.nim')
-rwxr-xr-x | lib/pure/parsecfg.nim | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/pure/parsecfg.nim b/lib/pure/parsecfg.nim index ae151ff94..67644e156 100755 --- a/lib/pure/parsecfg.nim +++ b/lib/pure/parsecfg.nim @@ -74,15 +74,18 @@ const proc rawGetTok(c: var TCfgParser, tok: var TToken) -proc open*(c: var TCfgParser, input: PStream, filename: string) {. +proc open*(c: var TCfgParser, input: PStream, filename: string, + lineOffset = 0) {. rtl, extern: "npc$1".} = ## initializes the parser with an input stream. `Filename` is only used - ## for nice error messages. + ## for nice error messages. `lineOffset` can be used to influence the line + ## number information in the generated error messages. lexbase.open(c, input) c.filename = filename c.state = startState c.tok.kind = tkInvalid c.tok.literal = "" + inc(c.linenumber, lineOffset) rawGetTok(c, c.tok) proc close*(c: var TCfgParser) {.rtl, extern: "npc$1".} = @@ -291,6 +294,23 @@ proc errorStr*(c: TCfgParser, msg: string): string {.rtl, extern: "npc$1".} = ## column information. result = `%`("$1($2, $3) Error: $4", [c.filename, $getLine(c), $getColumn(c), msg]) + +proc warningStr*(c: TCfgParser, msg: string): string {.rtl, extern: "npc$1".} = + ## returns a properly formated warning message containing current line and + ## column information. + result = `%`("$1($2, $3) Warning: $4", + [c.filename, $getLine(c), $getColumn(c), msg]) + +proc ignoreMsg*(c: TCfgParser, e: TCfgEvent): string {.rtl, extern: "npc$1".} = + ## returns a properly formated warning message containing that + ## an entry is ignored. + case e.kind + of cfgSectionStart: result = c.warningStr("section ignored: " & e.section) + of cfgKeyValuePair: result = c.warningStr("key ignored: " & e.key) + of cfgOption: + result = c.warningStr("command ignored: " & e.key & ": " & e.value) + of cfgError: result = e.msg + of cfgEof: result = "" proc getKeyValPair(c: var TCfgParser, kind: TCfgEventKind): TCfgEvent = if c.tok.kind == tkSymbol: |