parsecfg.html 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/parsecfg</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/parsecfg</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <ul class="simple"><li><a class="reference" id="configuration-file-example_toc" href="#configuration-file-example">Configuration file example</a></li>
  50. <li><a class="reference" id="creating-a-configuration-file_toc" href="#creating-a-configuration-file">Creating a configuration file</a></li>
  51. <li><a class="reference" id="reading-a-configuration-file_toc" href="#reading-a-configuration-file">Reading a configuration file</a></li>
  52. <li><a class="reference" id="modifying-a-configuration-file_toc" href="#modifying-a-configuration-file">Modifying a configuration file</a></li>
  53. <li><a class="reference" id="deleting-a-section-key-in-a-configuration-file_toc" href="#deleting-a-section-key-in-a-configuration-file">Deleting a section key in a configuration file</a></li>
  54. <li><a class="reference" id="supported-ini-file-structure_toc" href="#supported-ini-file-structure">Supported INI File structure</a></li>
  55. </ul><li>
  56. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  57. </li>
  58. <li>
  59. <details open>
  60. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  61. <ul class="simple simple-toc-section">
  62. <li><a class="reference" href="#CfgEvent" title="CfgEvent = object of RootObj
  63. case kind*: CfgEventKind ## the kind of the event
  64. of cfgEof:
  65. nil
  66. of cfgSectionStart:
  67. section*: string ## `section` contains the name of the
  68. ## parsed section start (syntax: `[section]`)
  69. of cfgKeyValuePair, cfgOption:
  70. key*, value*: string ## contains the (key, value) pair if an option
  71. ## of the form `--key: value` or an ordinary
  72. ## `key= value` pair has been parsed.
  73. ## `value==&quot;&quot;` if it was not specified in the
  74. ## configuration file.
  75. of cfgError: ## the parser encountered an error: `msg`
  76. msg*: string ## contains the error message. No exceptions
  77. ## are thrown if a parse error occurs.">CfgEvent</a></li>
  78. <li><a class="reference" href="#CfgEventKind" title="CfgEventKind = enum
  79. cfgEof, ## end of file reached
  80. cfgSectionStart, ## a `[section]` has been parsed
  81. cfgKeyValuePair, ## a `key=value` pair has been detected
  82. cfgOption, ## a `--key=value` command line option
  83. cfgError ## an error occurred during parsing">CfgEventKind</a></li>
  84. <li><a class="reference" href="#CfgParser" title="CfgParser = object of BaseLexer">CfgParser</a></li>
  85. <li><a class="reference" href="#Config" title="Config = OrderedTableRef[string, OrderedTableRef[string, string]]">Config</a></li>
  86. </ul>
  87. </details>
  88. </li>
  89. <li>
  90. <details open>
  91. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  92. <ul class="simple simple-toc-section">
  93. <ul class="simple nested-toc-section">$
  94. <li><a class="reference" href="#%24%2CConfig" title="`$`(dict: Config): string">`$`(dict: Config): string</a></li>
  95. </ul>
  96. <ul class="simple nested-toc-section">close
  97. <li><a class="reference" href="#close%2CCfgParser" title="close(c: var CfgParser)">close(c: var CfgParser)</a></li>
  98. </ul>
  99. <ul class="simple nested-toc-section">delSection
  100. <li><a class="reference" href="#delSection%2CConfig%2Cstring" title="delSection(dict: var Config; section: string)">delSection(dict: var Config; section: string)</a></li>
  101. </ul>
  102. <ul class="simple nested-toc-section">delSectionKey
  103. <li><a class="reference" href="#delSectionKey%2CConfig%2Cstring%2Cstring" title="delSectionKey(dict: var Config; section, key: string)">delSectionKey(dict: var Config; section, key: string)</a></li>
  104. </ul>
  105. <ul class="simple nested-toc-section">errorStr
  106. <li><a class="reference" href="#errorStr%2CCfgParser%2Cstring" title="errorStr(c: CfgParser; msg: string): string">errorStr(c: CfgParser; msg: string): string</a></li>
  107. </ul>
  108. <ul class="simple nested-toc-section">getColumn
  109. <li><a class="reference" href="#getColumn%2CCfgParser" title="getColumn(c: CfgParser): int">getColumn(c: CfgParser): int</a></li>
  110. </ul>
  111. <ul class="simple nested-toc-section">getFilename
  112. <li><a class="reference" href="#getFilename%2CCfgParser" title="getFilename(c: CfgParser): string">getFilename(c: CfgParser): string</a></li>
  113. </ul>
  114. <ul class="simple nested-toc-section">getLine
  115. <li><a class="reference" href="#getLine%2CCfgParser" title="getLine(c: CfgParser): int">getLine(c: CfgParser): int</a></li>
  116. </ul>
  117. <ul class="simple nested-toc-section">getSectionValue
  118. <li><a class="reference" href="#getSectionValue%2CConfig%2Cstring%2Cstring%2Cstring" title="getSectionValue(dict: Config; section, key: string; defaultVal = &quot;&quot;): string">getSectionValue(dict: Config; section, key: string; defaultVal = &quot;&quot;): string</a></li>
  119. </ul>
  120. <ul class="simple nested-toc-section">ignoreMsg
  121. <li><a class="reference" href="#ignoreMsg%2CCfgParser%2CCfgEvent" title="ignoreMsg(c: CfgParser; e: CfgEvent): string">ignoreMsg(c: CfgParser; e: CfgEvent): string</a></li>
  122. </ul>
  123. <ul class="simple nested-toc-section">loadConfig
  124. <li><a class="reference" href="#loadConfig%2Cstring" title="loadConfig(filename: string): Config">loadConfig(filename: string): Config</a></li>
  125. <li><a class="reference" href="#loadConfig%2CStream%2Cstring" title="loadConfig(stream: Stream; filename: string = &quot;[stream]&quot;): Config">loadConfig(stream: Stream; filename: string = &quot;[stream]&quot;): Config</a></li>
  126. </ul>
  127. <ul class="simple nested-toc-section">newConfig
  128. <li><a class="reference" href="#newConfig" title="newConfig(): Config">newConfig(): Config</a></li>
  129. </ul>
  130. <ul class="simple nested-toc-section">next
  131. <li><a class="reference" href="#next%2CCfgParser" title="next(c: var CfgParser): CfgEvent">next(c: var CfgParser): CfgEvent</a></li>
  132. </ul>
  133. <ul class="simple nested-toc-section">open
  134. <li><a class="reference" href="#open%2CCfgParser%2CStream%2Cstring%2Cint" title="open(c: var CfgParser; input: Stream; filename: string; lineOffset = 0)">open(c: var CfgParser; input: Stream; filename: string; lineOffset = 0)</a></li>
  135. </ul>
  136. <ul class="simple nested-toc-section">setSectionKey
  137. <li><a class="reference" href="#setSectionKey%2CConfig%2Cstring%2Cstring%2Cstring" title="setSectionKey(dict: var Config; section, key, value: string)">setSectionKey(dict: var Config; section, key, value: string)</a></li>
  138. </ul>
  139. <ul class="simple nested-toc-section">warningStr
  140. <li><a class="reference" href="#warningStr%2CCfgParser%2Cstring" title="warningStr(c: CfgParser; msg: string): string">warningStr(c: CfgParser; msg: string): string</a></li>
  141. </ul>
  142. <ul class="simple nested-toc-section">writeConfig
  143. <li><a class="reference" href="#writeConfig%2CConfig%2Cstring" title="writeConfig(dict: Config; filename: string)">writeConfig(dict: Config; filename: string)</a></li>
  144. <li><a class="reference" href="#writeConfig%2CConfig%2CStream" title="writeConfig(dict: Config; stream: Stream)">writeConfig(dict: Config; stream: Stream)</a></li>
  145. </ul>
  146. </ul>
  147. </details>
  148. </li>
  149. <li>
  150. <details open>
  151. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  152. <ul class="simple simple-toc-section">
  153. <ul class="simple nested-toc-section">sections
  154. <li><a class="reference" href="#sections.i%2CConfig" title="sections(dict: Config): lent string">sections(dict: Config): lent string</a></li>
  155. </ul>
  156. </ul>
  157. </details>
  158. </li>
  159. </ul>
  160. </div>
  161. <div class="nine columns" id="content">
  162. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  163. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  164. <div id="tocRoot"></div>
  165. <p class="module-desc"><p>The <tt class="docutils literal"><span class="pre"><span class="Identifier">parsecfg</span></span></tt> module implements a high performance configuration file parser. The configuration file's syntax is similar to the Windows <tt class="docutils literal"><span class="pre"><span class="Operator">.</span><span class="Identifier">ini</span></span></tt> format, but much more powerful, as it is not a line based parser. String literals, raw string literals and triple quoted string literals are supported as in the Nim programming language.</p>
  166. <p>Example of how a configuration file may look like:</p>
  167. <pre># This is a comment.
  168. ; this too.
  169. [Common]
  170. cc=gcc # '=' and ':' are the same
  171. --foo=&quot;bar&quot; # '--cc' and 'cc' are the same, 'bar' and '&quot;bar&quot;' are the same (except for '#')
  172. macrosym: &quot;#&quot; # Note that '#' is interpreted as a comment without the quotation
  173. --verbose
  174. [Windows]
  175. isConsoleApplication=False ; another comment
  176. [Posix]
  177. isConsoleApplication=True
  178. key1: &quot;in this string backslash escapes are interpreted\n&quot;
  179. key2: r&quot;in this string not&quot;
  180. key3: &quot;&quot;&quot;triple quotes strings
  181. are also supported. They may span
  182. multiple lines.&quot;&quot;&quot;
  183. --&quot;long option with spaces&quot;: r&quot;c:\myfiles\test.txt&quot;
  184. </pre>
  185. <p>Here is an example of how to use the configuration file parser:</p>
  186. <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
  187. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  188. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Punctuation">[</span><span class="Identifier">strutils</span><span class="Punctuation">,</span> <span class="Identifier">streams</span><span class="Punctuation">]</span>
  189. <span class="Keyword">let</span> <span class="Identifier">configFile</span> <span class="Operator">=</span> <span class="StringLit">&quot;example.ini&quot;</span>
  190. <span class="Keyword">var</span> <span class="Identifier">f</span> <span class="Operator">=</span> <span class="Identifier">newFileStream</span><span class="Punctuation">(</span><span class="Identifier">configFile</span><span class="Punctuation">,</span> <span class="Identifier">fmRead</span><span class="Punctuation">)</span>
  191. <span class="Identifier">assert</span> <span class="Identifier">f</span> <span class="Operator">!=</span> <span class="Keyword">nil</span><span class="Punctuation">,</span> <span class="StringLit">&quot;cannot open &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">configFile</span>
  192. <span class="Keyword">var</span> <span class="Identifier">p</span><span class="Punctuation">:</span> <span class="Identifier">CfgParser</span>
  193. <span class="Identifier">open</span><span class="Punctuation">(</span><span class="Identifier">p</span><span class="Punctuation">,</span> <span class="Identifier">f</span><span class="Punctuation">,</span> <span class="Identifier">configFile</span><span class="Punctuation">)</span>
  194. <span class="Keyword">while</span> <span class="Identifier">true</span><span class="Punctuation">:</span>
  195. <span class="Keyword">var</span> <span class="Identifier">e</span> <span class="Operator">=</span> <span class="Identifier">next</span><span class="Punctuation">(</span><span class="Identifier">p</span><span class="Punctuation">)</span>
  196. <span class="Keyword">case</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">kind</span>
  197. <span class="Keyword">of</span> <span class="Identifier">cfgEof</span><span class="Punctuation">:</span> <span class="Keyword">break</span>
  198. <span class="Keyword">of</span> <span class="Identifier">cfgSectionStart</span><span class="Punctuation">:</span> <span class="Comment">## a `[section]` has been parsed</span>
  199. <span class="Identifier">echo</span> <span class="StringLit">&quot;new section: &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">section</span>
  200. <span class="Keyword">of</span> <span class="Identifier">cfgKeyValuePair</span><span class="Punctuation">:</span>
  201. <span class="Identifier">echo</span> <span class="StringLit">&quot;key-value-pair: &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">key</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;: &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">value</span>
  202. <span class="Keyword">of</span> <span class="Identifier">cfgOption</span><span class="Punctuation">:</span>
  203. <span class="Identifier">echo</span> <span class="StringLit">&quot;command: &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">key</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;: &quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">value</span>
  204. <span class="Keyword">of</span> <span class="Identifier">cfgError</span><span class="Punctuation">:</span>
  205. <span class="Identifier">echo</span> <span class="Identifier">e</span><span class="Operator">.</span><span class="Identifier">msg</span>
  206. <span class="Identifier">close</span><span class="Punctuation">(</span><span class="Identifier">p</span><span class="Punctuation">)</span></pre>
  207. <h2><a class="toc-backref" id="configuration-file-example" href="#configuration-file-example">Configuration file example</a></h2><pre class="listing">charset = &quot;utf-8&quot;
  208. [Package]
  209. name = &quot;hello&quot;
  210. --threads:on
  211. [Author]
  212. name = &quot;nim-lang&quot;
  213. website = &quot;nim-lang.org&quot;</pre>
  214. <h2><a class="toc-backref" id="creating-a-configuration-file" href="#creating-a-configuration-file">Creating a configuration file</a></h2>
  215. <p><strong class="examples_text">Example:</strong></p>
  216. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  217. <span class="Keyword">var</span> <span class="Identifier">dict</span> <span class="Operator">=</span> <span class="Identifier">newConfig</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  218. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;charset&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;utf-8&quot;</span><span class="Punctuation">)</span>
  219. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Package&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;name&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;hello&quot;</span><span class="Punctuation">)</span>
  220. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Package&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;--threads&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;on&quot;</span><span class="Punctuation">)</span>
  221. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;name&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;nim-lang&quot;</span><span class="Punctuation">)</span>
  222. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;website&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;nim-lang.org&quot;</span><span class="Punctuation">)</span>
  223. <span class="Identifier">assert</span> <span class="Operator">$</span><span class="Identifier">dict</span> <span class="Operator">==</span> <span class="LongStringLit">&quot;&quot;&quot;
  224. charset=utf-8
  225. [Package]
  226. name=hello
  227. --threads:on
  228. [Author]
  229. name=nim-lang
  230. website=nim-lang.org
  231. &quot;&quot;&quot;</span></pre>
  232. <h2><a class="toc-backref" id="reading-a-configuration-file" href="#reading-a-configuration-file">Reading a configuration file</a></h2>
  233. <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
  234. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  235. <span class="Keyword">let</span> <span class="Identifier">dict</span> <span class="Operator">=</span> <span class="Identifier">loadConfig</span><span class="Punctuation">(</span><span class="StringLit">&quot;config.ini&quot;</span><span class="Punctuation">)</span>
  236. <span class="Keyword">let</span> <span class="Identifier">charset</span> <span class="Operator">=</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="StringLit">&quot;&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;charset&quot;</span><span class="Punctuation">)</span>
  237. <span class="Keyword">let</span> <span class="Identifier">threads</span> <span class="Operator">=</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="StringLit">&quot;Package&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;--threads&quot;</span><span class="Punctuation">)</span>
  238. <span class="Keyword">let</span> <span class="Identifier">pname</span> <span class="Operator">=</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="StringLit">&quot;Package&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;name&quot;</span><span class="Punctuation">)</span>
  239. <span class="Keyword">let</span> <span class="Identifier">name</span> <span class="Operator">=</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;name&quot;</span><span class="Punctuation">)</span>
  240. <span class="Keyword">let</span> <span class="Identifier">website</span> <span class="Operator">=</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;website&quot;</span><span class="Punctuation">)</span>
  241. <span class="Identifier">echo</span> <span class="Identifier">pname</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">name</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">website</span></pre>
  242. <h2><a class="toc-backref" id="modifying-a-configuration-file" href="#modifying-a-configuration-file">Modifying a configuration file</a></h2>
  243. <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
  244. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  245. <span class="Keyword">var</span> <span class="Identifier">dict</span> <span class="Operator">=</span> <span class="Identifier">loadConfig</span><span class="Punctuation">(</span><span class="StringLit">&quot;config.ini&quot;</span><span class="Punctuation">)</span>
  246. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">setSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;name&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;nim-lang&quot;</span><span class="Punctuation">)</span>
  247. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">writeConfig</span><span class="Punctuation">(</span><span class="StringLit">&quot;config.ini&quot;</span><span class="Punctuation">)</span></pre>
  248. <h2><a class="toc-backref" id="deleting-a-section-key-in-a-configuration-file" href="#deleting-a-section-key-in-a-configuration-file">Deleting a section key in a configuration file</a></h2>
  249. <p><strong class="examples_text">Example: cmd: -r:off</strong></p>
  250. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  251. <span class="Keyword">var</span> <span class="Identifier">dict</span> <span class="Operator">=</span> <span class="Identifier">loadConfig</span><span class="Punctuation">(</span><span class="StringLit">&quot;config.ini&quot;</span><span class="Punctuation">)</span>
  252. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">delSectionKey</span><span class="Punctuation">(</span><span class="StringLit">&quot;Author&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;website&quot;</span><span class="Punctuation">)</span>
  253. <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">writeConfig</span><span class="Punctuation">(</span><span class="StringLit">&quot;config.ini&quot;</span><span class="Punctuation">)</span></pre>
  254. <h2><a class="toc-backref" id="supported-ini-file-structure" href="#supported-ini-file-structure">Supported INI File structure</a></h2>
  255. <p><strong class="examples_text">Example:</strong></p>
  256. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">parsecfg</span>
  257. <span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">streams</span>
  258. <span class="Keyword">var</span> <span class="Identifier">dict</span> <span class="Operator">=</span> <span class="Identifier">loadConfig</span><span class="Punctuation">(</span><span class="Identifier">newStringStream</span><span class="Punctuation">(</span><span class="LongStringLit">&quot;&quot;&quot;[Simple Values]
  259. key=value
  260. spaces in keys=allowed
  261. spaces in values=allowed as well
  262. spaces around the delimiter = obviously
  263. you can also use : to delimit keys from values
  264. [All Values Are Strings]
  265. values like this: 19990429
  266. or this: 3.14159265359
  267. are they treated as numbers : no
  268. integers floats and booleans are held as: strings
  269. can use the API to get converted values directly: true
  270. [No Values]
  271. key_without_value
  272. # empty string value is not allowed =
  273. [ Seletion A ]
  274. space around section name will be ignored
  275. [You can use comments]
  276. # like this
  277. ; or this
  278. # By default only in an empty line.
  279. # Inline comments can be harmful because they prevent users
  280. # from using the delimiting characters as parts of values.
  281. # That being said, this can be customized.
  282. [Sections Can Be Indented]
  283. can_values_be_as_well = True
  284. does_that_mean_anything_special = False
  285. purpose = formatting for readability
  286. # Did I mention we can indent comments, too?
  287. &quot;&quot;&quot;</span><span class="Punctuation">)</span>
  288. <span class="Punctuation">)</span>
  289. <span class="Keyword">let</span> <span class="Identifier">section1</span> <span class="Operator">=</span> <span class="StringLit">&quot;Simple Values&quot;</span>
  290. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section1</span><span class="Punctuation">,</span> <span class="StringLit">&quot;key&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;value&quot;</span>
  291. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section1</span><span class="Punctuation">,</span> <span class="StringLit">&quot;spaces in keys&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;allowed&quot;</span>
  292. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section1</span><span class="Punctuation">,</span> <span class="StringLit">&quot;spaces in values&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;allowed as well&quot;</span>
  293. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section1</span><span class="Punctuation">,</span> <span class="StringLit">&quot;spaces around the delimiter&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;obviously&quot;</span>
  294. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section1</span><span class="Punctuation">,</span> <span class="StringLit">&quot;you can also use&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;to delimit keys from values&quot;</span>
  295. <span class="Keyword">let</span> <span class="Identifier">section2</span> <span class="Operator">=</span> <span class="StringLit">&quot;All Values Are Strings&quot;</span>
  296. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section2</span><span class="Punctuation">,</span> <span class="StringLit">&quot;values like this&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;19990429&quot;</span>
  297. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section2</span><span class="Punctuation">,</span> <span class="StringLit">&quot;or this&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;3.14159265359&quot;</span>
  298. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section2</span><span class="Punctuation">,</span> <span class="StringLit">&quot;are they treated as numbers&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;no&quot;</span>
  299. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section2</span><span class="Punctuation">,</span> <span class="StringLit">&quot;integers floats and booleans are held as&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;strings&quot;</span>
  300. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section2</span><span class="Punctuation">,</span> <span class="StringLit">&quot;can use the API to get converted values directly&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;true&quot;</span>
  301. <span class="Keyword">let</span> <span class="Identifier">section3</span> <span class="Operator">=</span> <span class="StringLit">&quot;Seletion A&quot;</span>
  302. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section3</span><span class="Punctuation">,</span>
  303. <span class="StringLit">&quot;space around section name will be ignored&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;not an empty value&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;&quot;</span>
  304. <span class="Keyword">let</span> <span class="Identifier">section4</span> <span class="Operator">=</span> <span class="StringLit">&quot;Sections Can Be Indented&quot;</span>
  305. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section4</span><span class="Punctuation">,</span> <span class="StringLit">&quot;can_values_be_as_well&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;True&quot;</span>
  306. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section4</span><span class="Punctuation">,</span> <span class="StringLit">&quot;does_that_mean_anything_special&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;False&quot;</span>
  307. <span class="Identifier">assert</span> <span class="Identifier">dict</span><span class="Operator">.</span><span class="Identifier">getSectionValue</span><span class="Punctuation">(</span><span class="Identifier">section4</span><span class="Punctuation">,</span> <span class="StringLit">&quot;purpose&quot;</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;formatting for readability&quot;</span></pre></p>
  308. <div class="section" id="6">
  309. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  310. <dl class="item">
  311. <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="lexbase.html">lexbase</a>, <a class="reference external" href="streams.html">streams</a>, <a class="reference external" href="tables.html">tables</a>, <a class="reference external" href="decode_helpers.html">decode_helpers</a>, <a class="reference external" href="since.html">since</a>, <a class="reference external" href="syncio.html">syncio</a>
  312. </dl>
  313. </div>
  314. <div class="section" id="7">
  315. <h1><a class="toc-backref" href="#7">Types</a></h1>
  316. <dl class="item">
  317. <div id="CfgEvent">
  318. <dt><pre><a href="parsecfg.html#CfgEvent"><span class="Identifier">CfgEvent</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="system.html#RootObj"><span class="Identifier">RootObj</span></a>
  319. <span class="Keyword">case</span> <span class="Identifier">kind</span><span class="Operator">*</span><span class="Other">:</span> <a href="parsecfg.html#CfgEventKind"><span class="Identifier">CfgEventKind</span></a> <span class="Comment">## the kind of the event</span>
  320. <span class="Keyword">of</span> <span class="Identifier">cfgEof</span><span class="Other">:</span>
  321. <span class="Keyword">nil</span>
  322. <span class="Keyword">of</span> <span class="Identifier">cfgSectionStart</span><span class="Other">:</span>
  323. <span class="Identifier">section</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## `section` contains the name of the</span>
  324. <span class="Comment">## parsed section start (syntax: `[section]`)</span>
  325. <span class="Keyword">of</span> <span class="Identifier">cfgKeyValuePair</span><span class="Other">,</span> <span class="Identifier">cfgOption</span><span class="Other">:</span>
  326. <span class="Identifier">key</span><span class="Operator">*</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## contains the (key, value) pair if an option</span>
  327. <span class="Comment">## of the form `--key: value` or an ordinary</span>
  328. <span class="Comment">## `key= value` pair has been parsed.</span>
  329. <span class="Comment">## `value==&quot;&quot;` if it was not specified in the</span>
  330. <span class="Comment">## configuration file.</span>
  331. <span class="Keyword">of</span> <span class="Identifier">cfgError</span><span class="Other">:</span> <span class="Comment">## the parser encountered an error: `msg`</span>
  332. <span class="Identifier">msg</span><span class="Operator">*</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Comment">## contains the error message. No exceptions</span>
  333. <span class="Comment">## are thrown if a parse error occurs.</span></pre></dt>
  334. <dd>
  335. describes a parsing event
  336. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L191" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  337. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L191" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  338. </dd>
  339. </div>
  340. <div id="CfgEventKind">
  341. <dt><pre><a href="parsecfg.html#CfgEventKind"><span class="Identifier">CfgEventKind</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  342. <span class="Identifier">cfgEof</span><span class="Other">,</span> <span class="Comment">## end of file reached</span>
  343. <span class="Identifier">cfgSectionStart</span><span class="Other">,</span> <span class="Comment">## a `[section]` has been parsed</span>
  344. <span class="Identifier">cfgKeyValuePair</span><span class="Other">,</span> <span class="Comment">## a `key=value` pair has been detected</span>
  345. <span class="Identifier">cfgOption</span><span class="Other">,</span> <span class="Comment">## a `--key=value` command line option</span>
  346. <span class="Identifier">cfgError</span> <span class="Comment">## an error occurred during parsing</span></pre></dt>
  347. <dd>
  348. enumeration of all events that may occur when parsing
  349. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L184" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  350. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L184" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  351. </dd>
  352. </div>
  353. <div id="CfgParser">
  354. <dt><pre><a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="lexbase.html#BaseLexer"><span class="Identifier">BaseLexer</span></a></pre></dt>
  355. <dd>
  356. the parser object.
  357. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L214" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  358. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L214" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  359. </dd>
  360. </div>
  361. <div id="Config">
  362. <dt><pre><a href="parsecfg.html#Config"><span class="Identifier">Config</span></a> <span class="Other">=</span> <a href="tables.html#OrderedTableRef"><span class="Identifier">OrderedTableRef</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="tables.html#OrderedTableRef"><span class="Identifier">OrderedTableRef</span></a><span class="Other">[</span><a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">,</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span></pre></dt>
  363. <dd>
  364. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L501" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  365. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L501" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  366. </dd>
  367. </div>
  368. </dl>
  369. </div>
  370. <div class="section" id="12">
  371. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  372. <dl class="item">
  373. <div id="$-procs-all">
  374. <div id="$,Config">
  375. <dt><pre><span class="Keyword">proc</span> <a href="#%24%2CConfig"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  376. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  377. <dd>
  378. Writes the contents of the table to string.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  379. Comment statement will be ignored.</div>
  380. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L606" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  381. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L606" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  382. </dd>
  383. </div>
  384. </div>
  385. <div id="close-procs-all">
  386. <div id="close,CfgParser">
  387. <dt><pre><span class="Keyword">proc</span> <a href="#close%2CCfgParser"><span class="Identifier">close</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span>
  388. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  389. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  390. <dd>
  391. Closes the parser <tt class="docutils literal"><span class="pre"><span class="Identifier">c</span></span></tt> and its associated input stream.
  392. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L237" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  393. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L237" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  394. </dd>
  395. </div>
  396. </div>
  397. <div id="delSection-procs-all">
  398. <div id="delSection,Config,string">
  399. <dt><pre><span class="Keyword">proc</span> <a href="#delSection%2CConfig%2Cstring"><span class="Identifier">delSection</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">section</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  400. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  401. <dd>
  402. Deletes the specified section and all of its sub keys.
  403. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L643" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  404. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L643" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  405. </dd>
  406. </div>
  407. </div>
  408. <div id="delSectionKey-procs-all">
  409. <div id="delSectionKey,Config,string,string">
  410. <dt><pre><span class="Keyword">proc</span> <a href="#delSectionKey%2CConfig%2Cstring%2Cstring"><span class="Identifier">delSectionKey</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">section</span><span class="Other">,</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  411. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  412. <dd>
  413. Deletes the key of the specified section.
  414. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L647" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  415. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L647" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  416. </dd>
  417. </div>
  418. </div>
  419. <div id="errorStr-procs-all">
  420. <div id="errorStr,CfgParser,string">
  421. <dt><pre><span class="Keyword">proc</span> <a href="#errorStr%2CCfgParser%2Cstring"><span class="Identifier">errorStr</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span>
  422. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  423. <dd>
  424. Returns a properly formatted error message containing current line and column information.
  425. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L428" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  426. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L428" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  427. </dd>
  428. </div>
  429. </div>
  430. <div id="getColumn-procs-all">
  431. <div id="getColumn,CfgParser">
  432. <dt><pre><span class="Keyword">proc</span> <a href="#getColumn%2CCfgParser"><span class="Identifier">getColumn</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  433. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  434. <dd>
  435. Gets the current column the parser has arrived at.
  436. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L241" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  437. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L241" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  438. </dd>
  439. </div>
  440. </div>
  441. <div id="getFilename-procs-all">
  442. <div id="getFilename,CfgParser">
  443. <dt><pre><span class="Keyword">proc</span> <a href="#getFilename%2CCfgParser"><span class="Identifier">getFilename</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  444. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  445. <dd>
  446. Gets the filename of the file that the parser processes.
  447. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L249" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  448. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L249" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  449. </dd>
  450. </div>
  451. </div>
  452. <div id="getLine-procs-all">
  453. <div id="getLine,CfgParser">
  454. <dt><pre><span class="Keyword">proc</span> <a href="#getLine%2CCfgParser"><span class="Identifier">getLine</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  455. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  456. <dd>
  457. Gets the current line the parser has arrived at.
  458. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L245" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  459. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L245" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  460. </dd>
  461. </div>
  462. </div>
  463. <div id="getSectionValue-procs-all">
  464. <div id="getSectionValue,Config,string,string,string">
  465. <dt><pre><span class="Keyword">proc</span> <a href="#getSectionValue%2CConfig%2Cstring%2Cstring%2Cstring"><span class="Identifier">getSectionValue</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">section</span><span class="Other">,</span> <span class="Identifier">key</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">defaultVal</span> <span class="Other">=</span> <span class="StringLit">&quot;&quot;</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  466. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  467. <dd>
  468. Gets the key value of the specified Section. Returns the specified default value if the specified key does not exist.
  469. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L624" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  470. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L624" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  471. </dd>
  472. </div>
  473. </div>
  474. <div id="ignoreMsg-procs-all">
  475. <div id="ignoreMsg,CfgParser,CfgEvent">
  476. <dt><pre><span class="Keyword">proc</span> <a href="#ignoreMsg%2CCfgParser%2CCfgEvent"><span class="Identifier">ignoreMsg</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">;</span> <span class="Identifier">e</span><span class="Other">:</span> <a href="parsecfg.html#CfgEvent"><span class="Identifier">CfgEvent</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span>
  477. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  478. <dd>
  479. Returns a properly formatted warning message containing that an entry is ignored.
  480. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L440" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  481. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L440" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  482. </dd>
  483. </div>
  484. </div>
  485. <div id="loadConfig-procs-all">
  486. <div id="loadConfig,string">
  487. <dt><pre><span class="Keyword">proc</span> <a href="#loadConfig%2Cstring"><span class="Identifier">loadConfig</span></a><span class="Other">(</span><span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a> {.
  488. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  489. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">,</span> <span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  490. <dd>
  491. Loads the specified configuration file into a new Config instance.
  492. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L541" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  493. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L541" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  494. </dd>
  495. </div>
  496. <div id="loadConfig,Stream,string">
  497. <dt><pre><span class="Keyword">proc</span> <a href="#loadConfig%2CStream%2Cstring"><span class="Identifier">loadConfig</span></a><span class="Other">(</span><span class="Identifier">stream</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> <span class="Other">=</span> <span class="StringLit">&quot;[stream]&quot;</span><span class="Other">)</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a> {.
  498. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span>
  499. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  500. <dd>
  501. Loads the specified configuration from stream into a new Config instance. <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt> parameter is only used for nicer error messages.
  502. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L508" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  503. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L508" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  504. </dd>
  505. </div>
  506. </div>
  507. <div id="newConfig-procs-all">
  508. <div id="newConfig">
  509. <dt><pre><span class="Keyword">proc</span> <a href="#newConfig"><span class="Identifier">newConfig</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  510. <dd>
  511. Creates a new configuration table. Useful when wanting to create a configuration file.
  512. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L503" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  513. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L503" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  514. </dd>
  515. </div>
  516. </div>
  517. <div id="next-procs-all">
  518. <div id="next,CfgParser">
  519. <dt><pre><span class="Keyword">proc</span> <a href="#next%2CCfgParser"><span class="Identifier">next</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">)</span><span class="Other">:</span> <a href="parsecfg.html#CfgEvent"><span class="Identifier">CfgEvent</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span>
  520. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  521. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  522. <dd>
  523. Retrieves the first/next event. This controls the parser.
  524. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L471" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  525. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L471" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  526. </dd>
  527. </div>
  528. </div>
  529. <div id="open-procs-all">
  530. <div id="open,CfgParser,Stream,string,int">
  531. <dt><pre><span class="Keyword">proc</span> <a href="#open%2CCfgParser%2CStream%2Cstring%2Cint"><span class="Identifier">open</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">;</span> <span class="Identifier">input</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">lineOffset</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span> {.
  532. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span> <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  533. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ReadIOEffect</span><span class="Other">,</span> <span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  534. <dd>
  535. Initializes the parser with an input stream. <tt class="docutils literal"><span class="pre"><span class="Identifier">Filename</span></span></tt> is only used for nice error messages. <tt class="docutils literal"><span class="pre"><span class="Identifier">lineOffset</span></span></tt> can be used to influence the line number information in the generated error messages.
  536. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L225" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  537. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L225" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  538. </dd>
  539. </div>
  540. </div>
  541. <div id="setSectionKey-procs-all">
  542. <div id="setSectionKey,Config,string,string,string">
  543. <dt><pre><span class="Keyword">proc</span> <a href="#setSectionKey%2CConfig%2Cstring%2Cstring%2Cstring"><span class="Identifier">setSectionKey</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">section</span><span class="Other">,</span> <span class="Identifier">key</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.
  544. <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  545. <dd>
  546. Sets the Key value of the specified Section.
  547. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L635" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  548. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L635" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  549. </dd>
  550. </div>
  551. </div>
  552. <div id="warningStr-procs-all">
  553. <div id="warningStr,CfgParser,string">
  554. <dt><pre><span class="Keyword">proc</span> <a href="#warningStr%2CCfgParser%2Cstring"><span class="Identifier">warningStr</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="parsecfg.html#CfgParser"><span class="Identifier">CfgParser</span></a><span class="Other">;</span> <span class="Identifier">msg</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npc$1&quot;</span><span class="Other">,</span>
  555. <span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  556. <dd>
  557. Returns a properly formatted warning message containing current line and column information.
  558. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L434" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  559. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L434" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  560. </dd>
  561. </div>
  562. </div>
  563. <div id="writeConfig-procs-all">
  564. <div id="writeConfig,Config,string">
  565. <dt><pre><span class="Keyword">proc</span> <a href="#writeConfig%2CConfig%2Cstring"><span class="Identifier">writeConfig</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">filename</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  566. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  567. <dd>
  568. Writes the contents of the table to the specified configuration file.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  569. Comment statement will be ignored.</div>
  570. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L615" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  571. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L615" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  572. </dd>
  573. </div>
  574. <div id="writeConfig,Config,Stream">
  575. <dt><pre><span class="Keyword">proc</span> <a href="#writeConfig%2CConfig%2CStream"><span class="Identifier">writeConfig</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">;</span> <span class="Identifier">stream</span><span class="Other">:</span> <a href="streams.html#Stream"><span class="Identifier">Stream</span></a><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">IOError</span><span class="Other">,</span> <span class="Identifier">OSError</span><span class="Other">]</span><span class="Other">,</span>
  576. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">WriteIOEffect</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  577. <dd>
  578. Writes the contents of the table to the specified stream.<div class="admonition admonition-info"><span class="admonition-info-text"><b>Note:</b></span>
  579. Comment statement will be ignored.</div>
  580. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L566" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  581. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L566" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  582. </dd>
  583. </div>
  584. </div>
  585. </dl>
  586. </div>
  587. <div class="section" id="15">
  588. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  589. <dl class="item">
  590. <div id="sections-iterators-all">
  591. <div id="sections.i,Config">
  592. <dt><pre><span class="Keyword">iterator</span> <a href="#sections.i%2CConfig"><span class="Identifier">sections</span></a><span class="Other">(</span><span class="Identifier">dict</span><span class="Other">:</span> <a href="parsecfg.html#Config"><span class="Identifier">Config</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#lent"><span class="Identifier">lent</span></a> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  593. <dd>
  594. Iterates through the sections in the <tt class="docutils literal"><span class="pre"><span class="Identifier">dict</span></span></tt>.
  595. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/parsecfg.nim#L656" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  596. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/parsecfg.nim#L656" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  597. </dd>
  598. </div>
  599. </div>
  600. </dl>
  601. </div>
  602. </div>
  603. </div>
  604. <div class="twelve-columns footer">
  605. <span class="nim-sprite"></span>
  606. <br>
  607. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-06 22:28:06 UTC</small>
  608. </div>
  609. </div>
  610. </div>
  611. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  612. </body>
  613. </html>