pegs.html 204 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  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/pegs</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/pegs</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. <li><a class="reference" id="peg-syntax-and-semantics_toc" href="#peg-syntax-and-semantics">PEG syntax and semantics</a></li>
  50. <ul class="simple"><li><a class="reference" id="peg-syntax-and-semantics-builtminusin-macros_toc" href="#peg-syntax-and-semantics-builtminusin-macros">Built-in macros</a></li>
  51. <li><a class="reference" id="peg-syntax-and-semantics-supported-peg-grammar_toc" href="#peg-syntax-and-semantics-supported-peg-grammar">Supported PEG grammar</a></li>
  52. <li><a class="reference" id="peg-syntax-and-semantics-examples_toc" href="#peg-syntax-and-semantics-examples">Examples</a></li>
  53. <li><a class="reference" id="peg-syntax-and-semantics-peg-vs-regular-expression_toc" href="#peg-syntax-and-semantics-peg-vs-regular-expression">PEG vs regular expression</a></li>
  54. <li><a class="reference" id="peg-syntax-and-semantics-peg-construction_toc" href="#peg-syntax-and-semantics-peg-construction">PEG construction</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="#Captures" title="Captures = object">Captures</a></li>
  63. <li><a class="reference" href="#EInvalidPeg" title="EInvalidPeg = object of ValueError">EInvalidPeg</a></li>
  64. <li><a class="reference" href="#NonTerminal" title="NonTerminal = ref NonTerminalObj">NonTerminal</a></li>
  65. <li><a class="reference" href="#NonTerminalFlag" title="NonTerminalFlag = enum
  66. ntDeclared, ntUsed">NonTerminalFlag</a></li>
  67. <li><a class="reference" href="#Peg" title="Peg {.shallow.} = object
  68. case
  69. of pkEmpty .. pkWhitespace:
  70. nil
  71. of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle:
  72. of pkChar, pkGreedyRepChar:
  73. of pkCharChoice, pkGreedyRepSet:
  74. of pkNonTerminal:
  75. of pkBackRef .. pkBackRefIgnoreStyle:
  76. else:">Peg</a></li>
  77. <li><a class="reference" href="#PegKind" title="PegKind = enum
  78. pkEmpty, pkAny, ## any character (.)
  79. pkAnyRune, ## any Unicode character (_)
  80. pkNewLine, ## CR-LF, LF, CR
  81. pkLetter, ## Unicode letter
  82. pkLower, ## Unicode lower case letter
  83. pkUpper, ## Unicode upper case letter
  84. pkTitle, ## Unicode title character
  85. pkWhitespace, ## Unicode whitespace character
  86. pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle, pkChar, ## single character to match
  87. pkCharChoice, pkNonTerminal, pkSequence, ## a b c ... --&gt; Internal DSL: peg(a, b, c)
  88. pkOrderedChoice, ## a / b / ... --&gt; Internal DSL: a / b or /[a, b, c]
  89. pkGreedyRep, ## a* --&gt; Internal DSL: *a
  90. ## a+ --&gt; (a a*)
  91. pkGreedyRepChar, ## x* where x is a single character (superop)
  92. pkGreedyRepSet, ## [set]* (superop)
  93. pkGreedyAny, ## .* or _* (superop)
  94. pkOption, ## a? --&gt; Internal DSL: ?a
  95. pkAndPredicate, ## &amp;a --&gt; Internal DSL: &amp;a
  96. pkNotPredicate, ## !a --&gt; Internal DSL: !a
  97. pkCapture, ## {a} --&gt; Internal DSL: capture(a)
  98. pkBackRef, ## $i --&gt; Internal DSL: backref(i)
  99. pkBackRefIgnoreCase, pkBackRefIgnoreStyle, pkSearch, ## @a --&gt; Internal DSL: !*a
  100. pkCapturedSearch, ## {@} a --&gt; Internal DSL: !*\a
  101. pkRule, ## a &lt;- b
  102. pkList, ## a, b
  103. pkStartAnchor ## ^ --&gt; Internal DSL: startAnchor()">PegKind</a></li>
  104. </ul>
  105. </details>
  106. </li>
  107. <li>
  108. <details open>
  109. <summary><a class="reference reference-toplevel" href="#10" id="60">Consts</a></summary>
  110. <ul class="simple simple-toc-section">
  111. <li><a class="reference" href="#MaxSubpatterns" title="MaxSubpatterns = 20">MaxSubpatterns</a></li>
  112. </ul>
  113. </details>
  114. </li>
  115. <li>
  116. <details open>
  117. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  118. <ul class="simple simple-toc-section">
  119. <ul class="simple nested-toc-section">!
  120. <li><a class="reference" href="#%21%2CPeg" title="`!`(a: Peg): Peg">`!`(a: Peg): Peg</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">!*
  123. <li><a class="reference" href="#%21%2A%2CPeg" title="`!*`(a: Peg): Peg">`!*`(a: Peg): Peg</a></li>
  124. </ul>
  125. <ul class="simple nested-toc-section">!*\
  126. <li><a class="reference" href="#%21%2A%5C%2CPeg" title="`!*\`(a: Peg): Peg">`!*\`(a: Peg): Peg</a></li>
  127. </ul>
  128. <ul class="simple nested-toc-section">$
  129. <li><a class="reference" href="#%24%2CPeg" title="`$`(r: Peg): string">`$`(r: Peg): string</a></li>
  130. </ul>
  131. <ul class="simple nested-toc-section">&
  132. <li><a class="reference" href="#%26%2CPeg" title="`&amp;`(a: Peg): Peg">`&amp;`(a: Peg): Peg</a></li>
  133. </ul>
  134. <ul class="simple nested-toc-section">*
  135. <li><a class="reference" href="#%2A%2CPeg" title="`*`(a: Peg): Peg">`*`(a: Peg): Peg</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">+
  138. <li><a class="reference" href="#%2B%2CPeg" title="`+`(a: Peg): Peg">`+`(a: Peg): Peg</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">/
  141. <li><a class="reference" href="#%2F%2Cvarargs%5BPeg%5D" title="`/`(a: varargs[Peg]): Peg">`/`(a: varargs[Peg]): Peg</a></li>
  142. </ul>
  143. <ul class="simple nested-toc-section">?
  144. <li><a class="reference" href="#%3F%2CPeg" title="`?`(a: Peg): Peg">`?`(a: Peg): Peg</a></li>
  145. </ul>
  146. <ul class="simple nested-toc-section">any
  147. <li><a class="reference" href="#any" title="any(): Peg">any(): Peg</a></li>
  148. </ul>
  149. <ul class="simple nested-toc-section">anyRune
  150. <li><a class="reference" href="#anyRune" title="anyRune(): Peg">anyRune(): Peg</a></li>
  151. </ul>
  152. <ul class="simple nested-toc-section">backref
  153. <li><a class="reference" href="#backref%2Crange%5B%5D%2Cbool" title="backref(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg">backref(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg</a></li>
  154. </ul>
  155. <ul class="simple nested-toc-section">backrefIgnoreCase
  156. <li><a class="reference" href="#backrefIgnoreCase%2Crange%5B%5D%2Cbool" title="backrefIgnoreCase(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg">backrefIgnoreCase(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg</a></li>
  157. </ul>
  158. <ul class="simple nested-toc-section">backrefIgnoreStyle
  159. <li><a class="reference" href="#backrefIgnoreStyle%2Crange%5B%5D%2Cbool" title="backrefIgnoreStyle(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg">backrefIgnoreStyle(index: range[1 .. MaxSubpatterns]; reverse: bool = false): Peg</a></li>
  160. </ul>
  161. <ul class="simple nested-toc-section">bounds
  162. <li><a class="reference" href="#bounds%2CCaptures%2Crange%5B%5D" title="bounds(c: Captures; i: range[0 .. 20 - 1]): tuple[first, last: int]">bounds(c: Captures; i: range[0 .. 20 - 1]): tuple[first, last: int]</a></li>
  163. </ul>
  164. <ul class="simple nested-toc-section">capture
  165. <li><a class="reference" href="#capture%2CPeg" title="capture(a: Peg = Peg(kind: pkEmpty)): Peg">capture(a: Peg = Peg(kind: pkEmpty)): Peg</a></li>
  166. </ul>
  167. <ul class="simple nested-toc-section">ch
  168. <li><a class="reference" href="#ch%2CPeg" title="ch(p: Peg): char">ch(p: Peg): char</a></li>
  169. </ul>
  170. <ul class="simple nested-toc-section">charChoice
  171. <li><a class="reference" href="#charChoice%2CPeg" title="charChoice(p: Peg): ref set[char]">charChoice(p: Peg): ref set[char]</a></li>
  172. </ul>
  173. <ul class="simple nested-toc-section">charSet
  174. <li><a class="reference" href="#charSet%2Cset%5Bchar%5D" title="charSet(s: set[char]): Peg">charSet(s: set[char]): Peg</a></li>
  175. </ul>
  176. <ul class="simple nested-toc-section">col
  177. <li><a class="reference" href="#col%2CNonTerminal" title="col(nt: NonTerminal): int">col(nt: NonTerminal): int</a></li>
  178. </ul>
  179. <ul class="simple nested-toc-section">contains
  180. <li><a class="reference" href="#contains%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint" title="contains(s: string; pattern: Peg; matches: var openArray[string]; start = 0): bool">contains(s: string; pattern: Peg; matches: var openArray[string]; start = 0): bool</a></li>
  181. <li><a class="reference" href="#contains%2Cstring%2CPeg%2Cint" title="contains(s: string; pattern: Peg; start = 0): bool">contains(s: string; pattern: Peg; start = 0): bool</a></li>
  182. </ul>
  183. <ul class="simple nested-toc-section">endAnchor
  184. <li><a class="reference" href="#endAnchor" title="endAnchor(): Peg">endAnchor(): Peg</a></li>
  185. </ul>
  186. <ul class="simple nested-toc-section">endsWith
  187. <li><a class="reference" href="#endsWith%2Cstring%2CPeg%2Cint" title="endsWith(s: string; suffix: Peg; start = 0): bool">endsWith(s: string; suffix: Peg; start = 0): bool</a></li>
  188. </ul>
  189. <ul class="simple nested-toc-section">escapePeg
  190. <li><a class="reference" href="#escapePeg%2Cstring" title="escapePeg(s: string): string">escapePeg(s: string): string</a></li>
  191. </ul>
  192. <ul class="simple nested-toc-section">find
  193. <li><a class="reference" href="#find%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint" title="find(s: string; pattern: Peg; matches: var openArray[string]; start = 0): int">find(s: string; pattern: Peg; matches: var openArray[string]; start = 0): int</a></li>
  194. <li><a class="reference" href="#find%2Cstring%2CPeg%2Cint" title="find(s: string; pattern: Peg; start = 0): int">find(s: string; pattern: Peg; start = 0): int</a></li>
  195. </ul>
  196. <ul class="simple nested-toc-section">findAll
  197. <li><a class="reference" href="#findAll%2Cstring%2CPeg%2Cint" title="findAll(s: string; pattern: Peg; start = 0): seq[string]">findAll(s: string; pattern: Peg; start = 0): seq[string]</a></li>
  198. </ul>
  199. <ul class="simple nested-toc-section">findBounds
  200. <li><a class="reference" href="#findBounds%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint" title="findBounds(s: string; pattern: Peg; matches: var openArray[string]; start = 0): tuple[
  201. first, last: int]">findBounds(s: string; pattern: Peg; matches: var openArray[string]; start = 0): tuple[
  202. first, last: int]</a></li>
  203. </ul>
  204. <ul class="simple nested-toc-section">flags
  205. <li><a class="reference" href="#flags%2CNonTerminal" title="flags(nt: NonTerminal): set[NonTerminalFlag]">flags(nt: NonTerminal): set[NonTerminalFlag]</a></li>
  206. </ul>
  207. <ul class="simple nested-toc-section">index
  208. <li><a class="reference" href="#index%2CPeg" title="index(p: Peg): range[-20 .. 20 - 1]">index(p: Peg): range[-20 .. 20 - 1]</a></li>
  209. </ul>
  210. <ul class="simple nested-toc-section">kind
  211. <li><a class="reference" href="#kind%2CPeg" title="kind(p: Peg): PegKind">kind(p: Peg): PegKind</a></li>
  212. </ul>
  213. <ul class="simple nested-toc-section">line
  214. <li><a class="reference" href="#line%2CNonTerminal" title="line(nt: NonTerminal): int">line(nt: NonTerminal): int</a></li>
  215. </ul>
  216. <ul class="simple nested-toc-section">match
  217. <li><a class="reference" href="#match%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint" title="match(s: string; pattern: Peg; matches: var openArray[string]; start = 0): bool">match(s: string; pattern: Peg; matches: var openArray[string]; start = 0): bool</a></li>
  218. <li><a class="reference" href="#match%2Cstring%2CPeg%2Cint" title="match(s: string; pattern: Peg; start = 0): bool">match(s: string; pattern: Peg; start = 0): bool</a></li>
  219. </ul>
  220. <ul class="simple nested-toc-section">matchLen
  221. <li><a class="reference" href="#matchLen%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint" title="matchLen(s: string; pattern: Peg; matches: var openArray[string]; start = 0): int">matchLen(s: string; pattern: Peg; matches: var openArray[string]; start = 0): int</a></li>
  222. <li><a class="reference" href="#matchLen%2Cstring%2CPeg%2Cint" title="matchLen(s: string; pattern: Peg; start = 0): int">matchLen(s: string; pattern: Peg; start = 0): int</a></li>
  223. </ul>
  224. <ul class="simple nested-toc-section">name
  225. <li><a class="reference" href="#name%2CNonTerminal" title="name(nt: NonTerminal): string">name(nt: NonTerminal): string</a></li>
  226. </ul>
  227. <ul class="simple nested-toc-section">newLine
  228. <li><a class="reference" href="#newLine" title="newLine(): Peg">newLine(): Peg</a></li>
  229. </ul>
  230. <ul class="simple nested-toc-section">newNonTerminal
  231. <li><a class="reference" href="#newNonTerminal%2Cstring%2Cint%2Cint" title="newNonTerminal(name: string; line, column: int): NonTerminal">newNonTerminal(name: string; line, column: int): NonTerminal</a></li>
  232. </ul>
  233. <ul class="simple nested-toc-section">nonterminal
  234. <li><a class="reference" href="#nonterminal%2CNonTerminal" title="nonterminal(n: NonTerminal): Peg">nonterminal(n: NonTerminal): Peg</a></li>
  235. </ul>
  236. <ul class="simple nested-toc-section">nt
  237. <li><a class="reference" href="#nt%2CPeg" title="nt(p: Peg): NonTerminal">nt(p: Peg): NonTerminal</a></li>
  238. </ul>
  239. <ul class="simple nested-toc-section">parallelReplace
  240. <li><a class="reference" href="#parallelReplace%2Cstring%2Cvarargs%5Btuple%5BPeg%2Cstring%5D%5D" title="parallelReplace(s: string; subs: varargs[tuple[pattern: Peg, repl: string]]): string">parallelReplace(s: string; subs: varargs[tuple[pattern: Peg, repl: string]]): string</a></li>
  241. </ul>
  242. <ul class="simple nested-toc-section">parsePeg
  243. <li><a class="reference" href="#parsePeg%2Cstring%2Cstring%2Cint%2Cint" title="parsePeg(pattern: string; filename = &quot;pattern&quot;; line = 1; col = 0): Peg">parsePeg(pattern: string; filename = &quot;pattern&quot;; line = 1; col = 0): Peg</a></li>
  244. </ul>
  245. <ul class="simple nested-toc-section">peg
  246. <li><a class="reference" href="#peg%2Cstring" title="peg(pattern: string): Peg">peg(pattern: string): Peg</a></li>
  247. </ul>
  248. <ul class="simple nested-toc-section">rawMatch
  249. <li><a class="reference" href="#rawMatch%2Cstring%2CPeg%2Cint%2CCaptures" title="rawMatch(s: string; p: Peg; start: int; c: var Captures): int">rawMatch(s: string; p: Peg; start: int; c: var Captures): int</a></li>
  250. </ul>
  251. <ul class="simple nested-toc-section">replace
  252. <li><a class="reference" href="#replace%2Cstring%2CPeg%2Cproc%28int%2Cint%2CopenArray%5Bstring%5D%29" title="replace(s: string; sub: Peg;
  253. cb: proc (match: int; cnt: int; caps: openArray[string]): string): string">replace(s: string; sub: Peg;
  254. cb: proc (match: int; cnt: int; caps: openArray[string]): string): string</a></li>
  255. <li><a class="reference" href="#replace%2Cstring%2CPeg%2Cstring" title="replace(s: string; sub: Peg; by = &quot;&quot;): string">replace(s: string; sub: Peg; by = &quot;&quot;): string</a></li>
  256. </ul>
  257. <ul class="simple nested-toc-section">replacef
  258. <li><a class="reference" href="#replacef%2Cstring%2CPeg%2Cstring" title="replacef(s: string; sub: Peg; by: string): string">replacef(s: string; sub: Peg; by: string): string</a></li>
  259. </ul>
  260. <ul class="simple nested-toc-section">rule
  261. <li><a class="reference" href="#rule%2CNonTerminal" title="rule(nt: NonTerminal): Peg">rule(nt: NonTerminal): Peg</a></li>
  262. </ul>
  263. <ul class="simple nested-toc-section">sequence
  264. <li><a class="reference" href="#sequence%2Cvarargs%5BPeg%5D" title="sequence(a: varargs[Peg]): Peg">sequence(a: varargs[Peg]): Peg</a></li>
  265. </ul>
  266. <ul class="simple nested-toc-section">split
  267. <li><a class="reference" href="#split%2Cstring%2CPeg" title="split(s: string; sep: Peg): seq[string]">split(s: string; sep: Peg): seq[string]</a></li>
  268. </ul>
  269. <ul class="simple nested-toc-section">startAnchor
  270. <li><a class="reference" href="#startAnchor" title="startAnchor(): Peg">startAnchor(): Peg</a></li>
  271. </ul>
  272. <ul class="simple nested-toc-section">startsWith
  273. <li><a class="reference" href="#startsWith%2Cstring%2CPeg%2Cint" title="startsWith(s: string; prefix: Peg; start = 0): bool">startsWith(s: string; prefix: Peg; start = 0): bool</a></li>
  274. </ul>
  275. <ul class="simple nested-toc-section">term
  276. <li><a class="reference" href="#term%2CPeg" title="term(p: Peg): string">term(p: Peg): string</a></li>
  277. <li><a class="reference" href="#term%2Cchar" title="term(t: char): Peg">term(t: char): Peg</a></li>
  278. <li><a class="reference" href="#term%2Cstring" title="term(t: string): Peg">term(t: string): Peg</a></li>
  279. </ul>
  280. <ul class="simple nested-toc-section">termIgnoreCase
  281. <li><a class="reference" href="#termIgnoreCase%2Cstring" title="termIgnoreCase(t: string): Peg">termIgnoreCase(t: string): Peg</a></li>
  282. </ul>
  283. <ul class="simple nested-toc-section">termIgnoreStyle
  284. <li><a class="reference" href="#termIgnoreStyle%2Cstring" title="termIgnoreStyle(t: string): Peg">termIgnoreStyle(t: string): Peg</a></li>
  285. </ul>
  286. <ul class="simple nested-toc-section">transformFile
  287. <li><a class="reference" href="#transformFile%2Cstring%2Cstring%2Cvarargs%5Btuple%5BPeg%2Cstring%5D%5D" title="transformFile(infile, outfile: string;
  288. subs: varargs[tuple[pattern: Peg, repl: string]])">transformFile(infile, outfile: string;
  289. subs: varargs[tuple[pattern: Peg, repl: string]])</a></li>
  290. </ul>
  291. <ul class="simple nested-toc-section">unicodeLetter
  292. <li><a class="reference" href="#unicodeLetter" title="unicodeLetter(): Peg">unicodeLetter(): Peg</a></li>
  293. </ul>
  294. <ul class="simple nested-toc-section">unicodeLower
  295. <li><a class="reference" href="#unicodeLower" title="unicodeLower(): Peg">unicodeLower(): Peg</a></li>
  296. </ul>
  297. <ul class="simple nested-toc-section">unicodeTitle
  298. <li><a class="reference" href="#unicodeTitle" title="unicodeTitle(): Peg">unicodeTitle(): Peg</a></li>
  299. </ul>
  300. <ul class="simple nested-toc-section">unicodeUpper
  301. <li><a class="reference" href="#unicodeUpper" title="unicodeUpper(): Peg">unicodeUpper(): Peg</a></li>
  302. </ul>
  303. <ul class="simple nested-toc-section">unicodeWhitespace
  304. <li><a class="reference" href="#unicodeWhitespace" title="unicodeWhitespace(): Peg">unicodeWhitespace(): Peg</a></li>
  305. </ul>
  306. </ul>
  307. </details>
  308. </li>
  309. <li>
  310. <details open>
  311. <summary><a class="reference reference-toplevel" href="#15" id="65">Iterators</a></summary>
  312. <ul class="simple simple-toc-section">
  313. <ul class="simple nested-toc-section">findAll
  314. <li><a class="reference" href="#findAll.i%2Cstring%2CPeg%2Cint" title="findAll(s: string; pattern: Peg; start = 0): string">findAll(s: string; pattern: Peg; start = 0): string</a></li>
  315. </ul>
  316. <ul class="simple nested-toc-section">items
  317. <li><a class="reference" href="#items.i%2CPeg" title="items(p: Peg): Peg">items(p: Peg): Peg</a></li>
  318. </ul>
  319. <ul class="simple nested-toc-section">pairs
  320. <li><a class="reference" href="#pairs.i%2CPeg" title="pairs(p: Peg): (int, Peg)">pairs(p: Peg): (int, Peg)</a></li>
  321. </ul>
  322. <ul class="simple nested-toc-section">split
  323. <li><a class="reference" href="#split.i%2Cstring%2CPeg" title="split(s: string; sep: Peg): string">split(s: string; sep: Peg): string</a></li>
  324. </ul>
  325. </ul>
  326. </details>
  327. </li>
  328. <li>
  329. <details open>
  330. <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
  331. <ul class="simple simple-toc-section">
  332. <ul class="simple nested-toc-section">=~
  333. <li><a class="reference" href="#%3D~.t%2Cstring%2CPeg" title="`=~`(s: string; pattern: Peg): bool">`=~`(s: string; pattern: Peg): bool</a></li>
  334. </ul>
  335. <ul class="simple nested-toc-section">digits
  336. <li><a class="reference" href="#digits.t" title="digits(): Peg">digits(): Peg</a></li>
  337. </ul>
  338. <ul class="simple nested-toc-section">eventParser
  339. <li><a class="reference" href="#eventParser.t%2Cuntyped%2Cuntyped" title="eventParser(pegAst, handlers: untyped): (proc (s: string): int)">eventParser(pegAst, handlers: untyped): (proc (s: string): int)</a></li>
  340. </ul>
  341. <ul class="simple nested-toc-section">ident
  342. <li><a class="reference" href="#ident.t" title="ident(): Peg">ident(): Peg</a></li>
  343. </ul>
  344. <ul class="simple nested-toc-section">identChars
  345. <li><a class="reference" href="#identChars.t" title="identChars(): Peg">identChars(): Peg</a></li>
  346. </ul>
  347. <ul class="simple nested-toc-section">identStartChars
  348. <li><a class="reference" href="#identStartChars.t" title="identStartChars(): Peg">identStartChars(): Peg</a></li>
  349. </ul>
  350. <ul class="simple nested-toc-section">letters
  351. <li><a class="reference" href="#letters.t" title="letters(): Peg">letters(): Peg</a></li>
  352. </ul>
  353. <ul class="simple nested-toc-section">natural
  354. <li><a class="reference" href="#natural.t" title="natural(): Peg">natural(): Peg</a></li>
  355. </ul>
  356. <ul class="simple nested-toc-section">whitespace
  357. <li><a class="reference" href="#whitespace.t" title="whitespace(): Peg">whitespace(): Peg</a></li>
  358. </ul>
  359. </ul>
  360. </details>
  361. </li>
  362. </ul>
  363. </div>
  364. <div class="nine columns" id="content">
  365. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  366. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  367. <div id="tocRoot"></div>
  368. <p class="module-desc">Simple PEG (Parsing expression grammar) matching. Uses no memorization, but uses superoperators and symbol inlining to improve performance. Note: Matching performance is hopefully competitive with optimized regular expression engines.
  369. <h1><a class="toc-backref" id="peg-syntax-and-semantics" href="#peg-syntax-and-semantics">PEG syntax and semantics</a></h1><p>A PEG (Parsing expression grammar) is a simple deterministic grammar, that can be directly used for parsing. The current implementation has been designed as a more powerful replacement for regular expressions. UTF-8 is supported.</p>
  370. <p>The notation used for a PEG is similar to that of EBNF:</p>
  371. <table border="1" class="docutils"><tr><th>notation</th><th>meaning</th></tr>
  372. <tr><td><tt class="docutils literal"><span class="pre">A / ... / Z</span></tt></td><td>Ordered choice: Apply expressions <tt class="docutils literal"><span class="pre"><span class="Identifier">A</span></span></tt>, ..., <tt class="docutils literal"><span class="pre"><span class="Identifier">Z</span></span></tt>, in this order, to the text ahead, until one of them succeeds and possibly consumes some text. Indicate success if one of expressions succeeded. Otherwise, do not consume any text and indicate failure.</td></tr>
  373. <tr><td><tt class="docutils literal"><span class="pre">A ... Z</span></tt></td><td>Sequence: Apply expressions <tt class="docutils literal"><span class="pre"><span class="Identifier">A</span></span></tt>, ..., <tt class="docutils literal"><span class="pre"><span class="Identifier">Z</span></span></tt>, in this order, to consume consecutive portions of the text ahead, as long as they succeed. Indicate success if all succeeded. Otherwise, do not consume any text and indicate failure. The sequence's precedence is higher than that of ordered choice: <tt class="docutils literal"><span class="pre">A B / C</span></tt> means <tt class="docutils literal"><span class="pre">(A B) / Z</span></tt> and not <tt class="docutils literal"><span class="pre">A (B / Z)</span></tt>.</td></tr>
  374. <tr><td><tt class="docutils literal"><span class="pre">(E)</span></tt></td><td>Grouping: Parenthesis can be used to change operator priority.</td></tr>
  375. <tr><td><tt class="docutils literal"><span class="pre">{E}</span></tt></td><td>Capture: Apply expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> and store the substring that matched <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> into a <em>capture</em> that can be accessed after the matching process.</td></tr>
  376. <tr><td><tt class="docutils literal"><span class="pre">{}</span></tt></td><td>Empty capture: Delete the last capture. No character is consumed.</td></tr>
  377. <tr><td><tt class="docutils literal"><span class="pre">$i</span></tt></td><td>Back reference to the <tt class="docutils literal"><span class="pre">i</span></tt>th capture. <tt class="docutils literal"><span class="pre">i</span></tt> counts forwards from 1 or backwards (last capture to first) from ^1.</td></tr>
  378. <tr><td><tt class="docutils literal"><span class="pre">$</span></tt></td><td>Anchor: Matches at the end of the input. No character is consumed. Same as <tt class="docutils literal"><span class="pre">!.</span></tt>.</td></tr>
  379. <tr><td><tt class="docutils literal"><span class="pre">^</span></tt></td><td>Anchor: Matches at the start of the input. No character is consumed.</td></tr>
  380. <tr><td><tt class="docutils literal"><span class="pre">&amp;E</span></tt></td><td>And predicate: Indicate success if expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> matches the text ahead; otherwise indicate failure. Do not consume any text.</td></tr>
  381. <tr><td><tt class="docutils literal"><span class="pre">!E</span></tt></td><td>Not predicate: Indicate failure if expression E matches the text ahead; otherwise indicate success. Do not consume any text.</td></tr>
  382. <tr><td><tt class="docutils literal"><span class="pre">E+</span></tt></td><td>One or more: Apply expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> repeatedly to match the text ahead, as long as it succeeds. Consume the matched text (if any) and indicate success if there was at least one match. Otherwise, indicate failure.</td></tr>
  383. <tr><td><tt class="docutils literal"><span class="pre">E*</span></tt></td><td>Zero or more: Apply expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> repeatedly to match the text ahead, as long as it succeeds. Consume the matched text (if any). Always indicate success.</td></tr>
  384. <tr><td><tt class="docutils literal"><span class="pre">E?</span></tt></td><td>Zero or one: If expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> matches the text ahead, consume it. Always indicate success.</td></tr>
  385. <tr><td><tt class="docutils literal"><span class="pre">[s]</span></tt></td><td>Character class: If the character ahead appears in the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>, consume it and indicate success. Otherwise, indicate failure.</td></tr>
  386. <tr><td><tt class="docutils literal"><span class="pre">[a-b]</span></tt></td><td>Character range: If the character ahead is one from the range <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt> through <tt class="docutils literal"><span class="pre"><span class="Identifier">b</span></span></tt>, consume it and indicate success. Otherwise, indicate failure.</td></tr>
  387. <tr><td><tt class="docutils literal"><span class="pre">'s'</span></tt></td><td>String: If the text ahead is the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>, consume it and indicate success. Otherwise, indicate failure.</td></tr>
  388. <tr><td><tt class="docutils literal"><span class="pre">i's'</span></tt></td><td>String match ignoring case.</td></tr>
  389. <tr><td><tt class="docutils literal"><span class="pre">y's'</span></tt></td><td>String match ignoring style.</td></tr>
  390. <tr><td><tt class="docutils literal"><span class="pre">v's'</span></tt></td><td>Verbatim string match: Use this to override a global <tt class="docutils literal"><span class="pre">\i</span></tt> or <tt class="docutils literal"><span class="pre">\y</span></tt> modifier.</td></tr>
  391. <tr><td><tt class="docutils literal"><span class="pre">i$j</span></tt></td><td>String match ignoring case for back reference.</td></tr>
  392. <tr><td><tt class="docutils literal"><span class="pre">y$j</span></tt></td><td>String match ignoring style for back reference.</td></tr>
  393. <tr><td><tt class="docutils literal"><span class="pre">v$j</span></tt></td><td>Verbatim string match for back reference.</td></tr>
  394. <tr><td><tt class="docutils literal"><span class="pre">.</span></tt></td><td>Any character: If there is a character ahead, consume it and indicate success. Otherwise, (that is, at the end of input) indicate failure.</td></tr>
  395. <tr><td><tt class="docutils literal"><span class="pre">_</span></tt></td><td>Any Unicode character: If there is a UTF-8 character ahead, consume it and indicate success. Otherwise, indicate failure.</td></tr>
  396. <tr><td><tt class="docutils literal"><span class="pre">@E</span></tt></td><td>Search: Shorthand for <tt class="docutils literal"><span class="pre">(!E .)* E</span></tt>. (Search loop for the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt>.)</td></tr>
  397. <tr><td><tt class="docutils literal"><span class="pre">{@} E</span></tt></td><td>Captured Search: Shorthand for <tt class="docutils literal"><span class="pre">{(!E .)*} E</span></tt>. (Search loop for the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt>.) Everything until and excluding <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> is captured.</td></tr>
  398. <tr><td><tt class="docutils literal"><span class="pre">@@ E</span></tt></td><td>Same as <tt class="docutils literal"><span class="pre">{@} E</span></tt>.</td></tr>
  399. <tr><td><tt class="docutils literal"><span class="pre">A &lt;- E</span></tt></td><td>Rule: Bind the expression <tt class="docutils literal"><span class="pre"><span class="Identifier">E</span></span></tt> to the <em>nonterminal symbol</em> <tt class="docutils literal"><span class="pre"><span class="Identifier">A</span></span></tt>. <strong>Left recursive rules are not possible and crash the matching engine.</strong></td></tr>
  400. <tr><td><tt class="docutils literal"><span class="pre">\identifier</span></tt></td><td>Built-in macro for a longer expression.</td></tr>
  401. <tr><td><tt class="docutils literal"><span class="pre">\ddd</span></tt></td><td>Character with decimal code <em>ddd</em>.</td></tr>
  402. <tr><td><tt class="docutils literal"><span class="pre">\&quot;</span></tt>, etc.</td><td>Literal <tt class="docutils literal"><span class="pre">&quot;</span></tt>, etc.</td></tr>
  403. </table>
  404. <h2><a class="toc-backref" id="peg-syntax-and-semantics-builtminusin-macros" href="#peg-syntax-and-semantics-builtminusin-macros">Built-in macros</a></h2><table border="1" class="docutils"><tr><th>macro</th><th>meaning</th></tr>
  405. <tr><td><tt class="docutils literal"><span class="pre">\d</span></tt></td><td>any decimal digit: <tt class="docutils literal"><span class="pre">[0-9]</span></tt></td></tr>
  406. <tr><td><tt class="docutils literal"><span class="pre">\D</span></tt></td><td>any character that is not a decimal digit: <tt class="docutils literal"><span class="pre">[^0-9]</span></tt></td></tr>
  407. <tr><td><tt class="docutils literal"><span class="pre">\s</span></tt></td><td>any whitespace character: <tt class="docutils literal"><span class="pre">[ \9-\13]</span></tt></td></tr>
  408. <tr><td><tt class="docutils literal"><span class="pre">\S</span></tt></td><td>any character that is not a whitespace character: <tt class="docutils literal"><span class="pre">[^ \9-\13]</span></tt></td></tr>
  409. <tr><td><tt class="docutils literal"><span class="pre">\w</span></tt></td><td>any &quot;word&quot; character: <tt class="docutils literal"><span class="pre">[a-zA-Z0-9_]</span></tt></td></tr>
  410. <tr><td><tt class="docutils literal"><span class="pre">\W</span></tt></td><td>any &quot;non-word&quot; character: <tt class="docutils literal"><span class="pre">[^a-zA-Z0-9_]</span></tt></td></tr>
  411. <tr><td><tt class="docutils literal"><span class="pre">\a</span></tt></td><td>same as <tt class="docutils literal"><span class="pre">[a-zA-Z]</span></tt></td></tr>
  412. <tr><td><tt class="docutils literal"><span class="pre">\A</span></tt></td><td>same as <tt class="docutils literal"><span class="pre">[^a-zA-Z]</span></tt></td></tr>
  413. <tr><td><tt class="docutils literal"><span class="pre">\n</span></tt></td><td>any newline combination: <tt class="docutils literal"><span class="pre">\10 / \13\10 / \13</span></tt></td></tr>
  414. <tr><td><tt class="docutils literal"><span class="pre">\i</span></tt></td><td>ignore case for matching; use this at the start of the PEG</td></tr>
  415. <tr><td><tt class="docutils literal"><span class="pre">\y</span></tt></td><td>ignore style for matching; use this at the start of the PEG</td></tr>
  416. <tr><td><tt class="docutils literal"><span class="pre">\skip</span></tt> pat</td><td>skip pattern <em>pat</em> before trying to match other tokens; this is useful for whitespace skipping, for example: <tt class="docutils literal"><span class="pre">\skip(\s*) {\ident} ':' {\ident}</span></tt> matches key value pairs ignoring whitespace around the <tt class="docutils literal"><span class="pre">':'</span></tt>.</td></tr>
  417. <tr><td><tt class="docutils literal"><span class="pre">\ident</span></tt></td><td>a standard ASCII identifier: <tt class="docutils literal"><span class="pre">[a-zA-Z_][a-zA-Z_0-9]*</span></tt></td></tr>
  418. <tr><td><tt class="docutils literal"><span class="pre">\letter</span></tt></td><td>any Unicode letter</td></tr>
  419. <tr><td><tt class="docutils literal"><span class="pre">\upper</span></tt></td><td>any Unicode uppercase letter</td></tr>
  420. <tr><td><tt class="docutils literal"><span class="pre">\lower</span></tt></td><td>any Unicode lowercase letter</td></tr>
  421. <tr><td><tt class="docutils literal"><span class="pre">\title</span></tt></td><td>any Unicode title letter</td></tr>
  422. <tr><td><tt class="docutils literal"><span class="pre">\white</span></tt></td><td>any Unicode whitespace character</td></tr>
  423. </table><p>A backslash followed by a letter is a built-in macro, otherwise it is used for ordinary escaping:</p>
  424. <table border="1" class="docutils"><tr><th>notation</th><th>meaning</th></tr>
  425. <tr><td><tt class="docutils literal"><span class="pre">\\</span></tt></td><td>a single backslash</td></tr>
  426. <tr><td><tt class="docutils literal"><span class="pre">\*</span></tt></td><td>same as <tt class="docutils literal"><span class="pre">'*'</span></tt></td></tr>
  427. <tr><td><tt class="docutils literal"><span class="pre">\t</span></tt></td><td>not a tabulator, but an (unknown) built-in</td></tr>
  428. </table>
  429. <h2><a class="toc-backref" id="peg-syntax-and-semantics-supported-peg-grammar" href="#peg-syntax-and-semantics-supported-peg-grammar">Supported PEG grammar</a></h2><p>The PEG parser implements this grammar (written in PEG syntax):</p>
  430. <pre># Example grammar of PEG in PEG syntax.
  431. # Comments start with '#'.
  432. # First symbol is the start symbol.
  433. grammar &lt;- rule* / expr
  434. identifier &lt;- [A-Za-z][A-Za-z0-9_]*
  435. charsetchar &lt;- &quot;\\&quot; . / [^\]]
  436. charset &lt;- &quot;[&quot; &quot;^&quot;? (charsetchar (&quot;-&quot; charsetchar)?)+ &quot;]&quot;
  437. stringlit &lt;- identifier? (&quot;\&quot;&quot; (&quot;\\&quot; . / [^&quot;])* &quot;\&quot;&quot; /
  438. &quot;'&quot; (&quot;\\&quot; . / [^'])* &quot;'&quot;)
  439. builtin &lt;- &quot;\\&quot; identifier / [^\13\10]
  440. comment &lt;- '#' @ \n
  441. ig &lt;- (\s / comment)* # things to ignore
  442. rule &lt;- identifier \s* &quot;&lt;-&quot; expr ig
  443. identNoArrow &lt;- identifier !(\s* &quot;&lt;-&quot;)
  444. prefixOpr &lt;- ig '&amp;' / ig '!' / ig '@' / ig '{@}' / ig '@@'
  445. literal &lt;- ig identifier? '$' '^'? [0-9]+ / '$' / '^' /
  446. ig identNoArrow /
  447. ig charset /
  448. ig stringlit /
  449. ig builtin /
  450. ig '.' /
  451. ig '_' /
  452. (ig &quot;(&quot; expr ig &quot;)&quot;) /
  453. (ig &quot;{&quot; expr? ig &quot;}&quot;)
  454. postfixOpr &lt;- ig '?' / ig '*' / ig '+'
  455. primary &lt;- prefixOpr* (literal postfixOpr*)
  456. # Concatenation has higher priority than choice:
  457. # ``a b / c`` means ``(a b) / c``
  458. seqExpr &lt;- primary+
  459. expr &lt;- seqExpr (ig &quot;/&quot; expr)*</pre>
  460. <p><strong>Note</strong>: As a special syntactic extension if the whole PEG is only a single expression, identifiers are not interpreted as non-terminals, but are interpreted as verbatim string:</p>
  461. <p><pre class="listing"><span class="Identifier">abc</span> <span class="Operator">=~</span> <span class="RawData">peg&quot;abc&quot;</span> <span class="Comment"># is true</span></pre></p>
  462. <p>So it is not necessary to write <tt class="docutils literal"><span class="pre">peg&quot; 'abc' &quot;</span></tt> in the above example.</p>
  463. <h2><a class="toc-backref" id="peg-syntax-and-semantics-examples" href="#peg-syntax-and-semantics-examples">Examples</a></h2><p>Check if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> matches Nim's &quot;while&quot; keyword:</p>
  464. <p><pre class="listing"><span class="Identifier">s</span> <span class="Operator">=~</span> <span class="RawData">peg&quot; y'while'&quot;</span></pre></p>
  465. <p>Exchange (key, val)-pairs:</p>
  466. <p><pre class="listing"><span class="StringLit">&quot;key: val; key2: val2&quot;</span><span class="Operator">.</span><span class="Identifier">replacef</span><span class="Punctuation">(</span><span class="RawData">peg&quot;{\ident} \s* ':' \s* {\ident}&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;$2: $1&quot;</span><span class="Punctuation">)</span></pre></p>
  467. <p>Determine the <tt class="docutils literal"><span class="pre">#include</span></tt>'ed files of a C file:</p>
  468. <p><pre class="listing"><span class="Keyword">for</span> <span class="Identifier">line</span> <span class="Keyword">in</span> <span class="Identifier">lines</span><span class="Punctuation">(</span><span class="StringLit">&quot;myfile.c&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  469. <span class="Keyword">if</span> <span class="Identifier">line</span> <span class="Operator">=~</span> <span class="LongStringLit">peg&quot;&quot;&quot;s &lt;- ws '#include' ws '&quot;' {[^&quot;]+} '&quot;' ws
  470. comment &lt;- '/*' @ '*/' / '//' .*
  471. ws &lt;- (comment / \s+)* &quot;&quot;&quot;</span><span class="Punctuation">:</span>
  472. <span class="Identifier">echo</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span></pre></p>
  473. <h2><a class="toc-backref" id="peg-syntax-and-semantics-peg-vs-regular-expression" href="#peg-syntax-and-semantics-peg-vs-regular-expression">PEG vs regular expression</a></h2><p>As a regular expression <tt class="docutils literal"><span class="pre">\[.*\]</span></tt> matches the longest possible text between <tt class="docutils literal"><span class="pre">'['</span></tt> and <tt class="docutils literal"><span class="pre">']'</span></tt>. As a PEG it never matches anything, because a PEG is deterministic: <tt class="docutils literal"><span class="pre">.*</span></tt> consumes the rest of the input, so <tt class="docutils literal"><span class="pre">\]</span></tt> never matches. As a PEG this needs to be written as: <tt class="docutils literal"><span class="pre">\[ ( !\] . )* \]</span></tt> (or <tt class="docutils literal"><span class="pre">\[ @ \]</span></tt>).</p>
  474. <p>Note that the regular expression does not behave as intended either: in the example <tt class="docutils literal"><span class="pre">*</span></tt> should not be greedy, so <tt class="docutils literal"><span class="pre">\[.*?\]</span></tt> should be used instead.</p>
  475. <h2><a class="toc-backref" id="peg-syntax-and-semantics-peg-construction" href="#peg-syntax-and-semantics-peg-construction">PEG construction</a></h2><p>There are two ways to construct a PEG in Nim code:</p>
  476. <ol class="simple"><li>Parsing a string into an AST which consists of <tt class="docutils literal"><span class="pre"><span class="Identifier">Peg</span></span></tt> nodes with the <tt class="docutils literal"><span class="pre"><span class="Identifier">peg</span></span></tt> proc.</li>
  477. <li>Constructing the AST directly with proc calls. This method does not support constructing rules, only simple expressions and is not as convenient. Its only advantage is that it does not pull in the whole PEG parser into your executable.</li>
  478. </ol>
  479. </p>
  480. <div class="section" id="6">
  481. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  482. <dl class="item">
  483. <a class="reference external" href="syncio.html">syncio</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="strutils.html">strutils</a>, <a class="reference external" href="macros.html">macros</a>, <a class="reference external" href="decode_helpers.html">decode_helpers</a>, <a class="reference external" href="unicode.html">unicode</a>
  484. </dl>
  485. </div>
  486. <div class="section" id="7">
  487. <h1><a class="toc-backref" href="#7">Types</a></h1>
  488. <dl class="item">
  489. <div id="Captures">
  490. <dt><pre><a href="pegs.html#Captures"><span class="Identifier">Captures</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
  491. <dd>
  492. contains the captured substrings.
  493. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L536" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  494. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L536" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  495. </dd>
  496. </div>
  497. <div id="EInvalidPeg">
  498. <dt><pre><a href="pegs.html#EInvalidPeg"><span class="Identifier">EInvalidPeg</span></a> <span class="Other">=</span> <span class="Keyword">object</span> <span class="Keyword">of</span> <a href="exceptions.html#ValueError"><span class="Identifier">ValueError</span></a></pre></dt>
  499. <dd>
  500. raised if an invalid PEG has been detected
  501. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1815" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  502. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1815" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  503. </dd>
  504. </div>
  505. <div id="NonTerminal">
  506. <dt><pre><a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Identifier">NonTerminalObj</span></pre></dt>
  507. <dd>
  508. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L90" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  509. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L90" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  510. </dd>
  511. </div>
  512. <div id="NonTerminalFlag">
  513. <dt><pre><a href="pegs.html#NonTerminalFlag"><span class="Identifier">NonTerminalFlag</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  514. <span class="Identifier">ntDeclared</span><span class="Other">,</span> <span class="Identifier">ntUsed</span></pre></dt>
  515. <dd>
  516. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L73" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  517. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L73" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  518. </dd>
  519. </div>
  520. <div id="Peg">
  521. <dt><pre><a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">shallow</span>.} <span class="Other">=</span> <span class="Keyword">object</span>
  522. <span class="Keyword">case</span>
  523. <span class="Keyword">of</span> <span class="Identifier">pkEmpty</span> <span class="Operator">..</span> <span class="Identifier">pkWhitespace</span><span class="Other">:</span>
  524. <span class="Keyword">nil</span>
  525. <span class="Keyword">of</span> <span class="Identifier">pkTerminal</span><span class="Other">,</span> <span class="Identifier">pkTerminalIgnoreCase</span><span class="Other">,</span> <span class="Identifier">pkTerminalIgnoreStyle</span><span class="Other">:</span>
  526. <span class="Keyword">of</span> <span class="Identifier">pkChar</span><span class="Other">,</span> <span class="Identifier">pkGreedyRepChar</span><span class="Other">:</span>
  527. <span class="Keyword">of</span> <span class="Identifier">pkCharChoice</span><span class="Other">,</span> <span class="Identifier">pkGreedyRepSet</span><span class="Other">:</span>
  528. <span class="Keyword">of</span> <span class="Identifier">pkNonTerminal</span><span class="Other">:</span>
  529. <span class="Keyword">of</span> <span class="Identifier">pkBackRef</span> <span class="Operator">..</span> <span class="Identifier">pkBackRefIgnoreStyle</span><span class="Other">:</span>
  530. <span class="Keyword">else</span><span class="Other">:</span></pre></dt>
  531. <dd>
  532. type that represents a PEG
  533. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L81" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  534. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L81" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  535. </dd>
  536. </div>
  537. <div id="PegKind">
  538. <dt><pre><a href="pegs.html#PegKind"><span class="Identifier">PegKind</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
  539. <span class="Identifier">pkEmpty</span><span class="Other">,</span> <span class="Identifier">pkAny</span><span class="Other">,</span> <span class="Comment">## any character (.)</span>
  540. <span class="Identifier">pkAnyRune</span><span class="Other">,</span> <span class="Comment">## any Unicode character (_)</span>
  541. <span class="Identifier">pkNewLine</span><span class="Other">,</span> <span class="Comment">## CR-LF, LF, CR</span>
  542. <span class="Identifier">pkLetter</span><span class="Other">,</span> <span class="Comment">## Unicode letter</span>
  543. <span class="Identifier">pkLower</span><span class="Other">,</span> <span class="Comment">## Unicode lower case letter</span>
  544. <span class="Identifier">pkUpper</span><span class="Other">,</span> <span class="Comment">## Unicode upper case letter</span>
  545. <span class="Identifier">pkTitle</span><span class="Other">,</span> <span class="Comment">## Unicode title character</span>
  546. <span class="Identifier">pkWhitespace</span><span class="Other">,</span> <span class="Comment">## Unicode whitespace character</span>
  547. <span class="Identifier">pkTerminal</span><span class="Other">,</span> <span class="Identifier">pkTerminalIgnoreCase</span><span class="Other">,</span> <span class="Identifier">pkTerminalIgnoreStyle</span><span class="Other">,</span> <span class="Identifier">pkChar</span><span class="Other">,</span> <span class="Comment">## single character to match</span>
  548. <span class="Identifier">pkCharChoice</span><span class="Other">,</span> <span class="Identifier">pkNonTerminal</span><span class="Other">,</span> <span class="Identifier">pkSequence</span><span class="Other">,</span> <span class="Comment">## a b c ... --&gt; Internal DSL: peg(a, b, c)</span>
  549. <span class="Identifier">pkOrderedChoice</span><span class="Other">,</span> <span class="Comment">## a / b / ... --&gt; Internal DSL: a / b or /[a, b, c]</span>
  550. <span class="Identifier">pkGreedyRep</span><span class="Other">,</span> <span class="Comment">## a* --&gt; Internal DSL: *a</span>
  551. <span class="Comment">## a+ --&gt; (a a*)</span>
  552. <span class="Identifier">pkGreedyRepChar</span><span class="Other">,</span> <span class="Comment">## x* where x is a single character (superop)</span>
  553. <span class="Identifier">pkGreedyRepSet</span><span class="Other">,</span> <span class="Comment">## [set]* (superop)</span>
  554. <span class="Identifier">pkGreedyAny</span><span class="Other">,</span> <span class="Comment">## .* or _* (superop)</span>
  555. <span class="Identifier">pkOption</span><span class="Other">,</span> <span class="Comment">## a? --&gt; Internal DSL: ?a</span>
  556. <span class="Identifier">pkAndPredicate</span><span class="Other">,</span> <span class="Comment">## &amp;a --&gt; Internal DSL: &amp;a</span>
  557. <span class="Identifier">pkNotPredicate</span><span class="Other">,</span> <span class="Comment">## !a --&gt; Internal DSL: !a</span>
  558. <span class="Identifier">pkCapture</span><span class="Other">,</span> <span class="Comment">## {a} --&gt; Internal DSL: capture(a)</span>
  559. <span class="Identifier">pkBackRef</span><span class="Other">,</span> <span class="Comment">## $i --&gt; Internal DSL: backref(i)</span>
  560. <span class="Identifier">pkBackRefIgnoreCase</span><span class="Other">,</span> <span class="Identifier">pkBackRefIgnoreStyle</span><span class="Other">,</span> <span class="Identifier">pkSearch</span><span class="Other">,</span> <span class="Comment">## @a --&gt; Internal DSL: !*a</span>
  561. <span class="Identifier">pkCapturedSearch</span><span class="Other">,</span> <span class="Comment">## {@} a --&gt; Internal DSL: !*\a</span>
  562. <span class="Identifier">pkRule</span><span class="Other">,</span> <span class="Comment">## a &lt;- b</span>
  563. <span class="Identifier">pkList</span><span class="Other">,</span> <span class="Comment">## a, b</span>
  564. <span class="Identifier">pkStartAnchor</span> <span class="Comment">## ^ --&gt; Internal DSL: startAnchor()</span></pre></dt>
  565. <dd>
  566. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L38" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  567. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L38" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  568. </dd>
  569. </div>
  570. </dl>
  571. </div>
  572. <div class="section" id="10">
  573. <h1><a class="toc-backref" href="#10">Consts</a></h1>
  574. <dl class="item">
  575. <div id="MaxSubpatterns">
  576. <dt><pre><a href="pegs.html#MaxSubpatterns"><span class="Identifier">MaxSubpatterns</span></a> <span class="Other">=</span> <span class="DecNumber">20</span></pre></dt>
  577. <dd>
  578. defines the maximum number of subpatterns that can be captured. More subpatterns cannot be captured!
  579. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L34" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  580. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L34" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  581. </dd>
  582. </div>
  583. </dl>
  584. </div>
  585. <div class="section" id="12">
  586. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  587. <dl class="item">
  588. <div id="!-procs-all">
  589. <div id="!,Peg">
  590. <dt><pre><span class="Keyword">func</span> <a href="#%21%2CPeg"><span class="Identifier">`!`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsNotPredicate&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>
  591. <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>
  592. <dd>
  593. constructs a &quot;not predicate&quot; with the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  594. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L264" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  595. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L264" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  596. </dd>
  597. </div>
  598. </div>
  599. <div id="!*-procs-all">
  600. <div id="!*,Peg">
  601. <dt><pre><span class="Keyword">func</span> <a href="#%21%2A%2CPeg"><span class="Identifier">`!*`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsSearch&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>
  602. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  603. <dd>
  604. constructs a &quot;search&quot; for the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  605. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L247" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  606. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L247" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  607. </dd>
  608. </div>
  609. </div>
  610. <div id="!*\-procs-all">
  611. <div id="!*\,Peg">
  612. <dt><pre><span class="Keyword">func</span> <a href="#%21%2A%5C%2CPeg"><span class="Identifier">`!*\`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npgegsCapturedSearch&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>
  613. <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>
  614. <dd>
  615. constructs a &quot;captured search&quot; for the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  616. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L251" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  617. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L251" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  618. </dd>
  619. </div>
  620. </div>
  621. <div id="$-procs-all">
  622. <div id="$,Peg">
  623. <dt><pre><span class="Keyword">func</span> <a href="#%24%2CPeg"><span class="Identifier">`$`</span></a><span class="Other">(</span><span class="Identifier">r</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsToString&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>
  624. <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>
  625. <dd>
  626. converts a PEG to its string representation
  627. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L528" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  628. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L528" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  629. </dd>
  630. </div>
  631. </div>
  632. <div id="&amp;-procs-all">
  633. <div id="&,Peg">
  634. <dt><pre><span class="Keyword">func</span> <a href="#%26%2CPeg"><span class="Identifier">`&amp;`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsAndPredicate&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>
  635. <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>
  636. <dd>
  637. constructs an &quot;and predicate&quot; with the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  638. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L260" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  639. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L260" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  640. </dd>
  641. </div>
  642. </div>
  643. <div id="*-procs-all">
  644. <div id="*,Peg">
  645. <dt><pre><span class="Keyword">func</span> <a href="#%2A%2CPeg"><span class="Identifier">`*`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsGreedyRep&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>
  646. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  647. <dd>
  648. constructs a &quot;greedy repetition&quot; for the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  649. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L233" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  650. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L233" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  651. </dd>
  652. </div>
  653. </div>
  654. <div id="+-procs-all">
  655. <div id="+,Peg">
  656. <dt><pre><span class="Keyword">func</span> <a href="#%2B%2CPeg"><span class="Identifier">`+`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsGreedyPosRep&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>
  657. <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>
  658. <dd>
  659. constructs a &quot;greedy positive repetition&quot; with the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  660. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L256" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  661. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L256" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  662. </dd>
  663. </div>
  664. </div>
  665. <div id="/-procs-all">
  666. <div id="/,varargs[Peg]">
  667. <dt><pre><span class="Keyword">func</span> <a href="#%2F%2Cvarargs%5BPeg%5D"><span class="Identifier">`/`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsOrderedChoice&quot;</span><span class="Other">,</span>
  668. <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>
  669. <dd>
  670. constructs an ordered choice with the PEGs in <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  671. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L201" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  672. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L201" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  673. </dd>
  674. </div>
  675. </div>
  676. <div id="?-procs-all">
  677. <div id="?,Peg">
  678. <dt><pre><span class="Keyword">func</span> <a href="#%3F%2CPeg"><span class="Identifier">`?`</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsOptional&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>
  679. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  680. <dd>
  681. constructs an optional for the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  682. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L223" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  683. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L223" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  684. </dd>
  685. </div>
  686. </div>
  687. <div id="any-procs-all">
  688. <div id="any">
  689. <dt><pre><span class="Keyword">func</span> <a href="#any"><span class="Identifier">any</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  690. <dd>
  691. constructs the PEG <span id="any-character_1">any character</span> (<tt class="docutils literal"><span class="pre">.</span></tt>)
  692. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L268" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  693. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L268" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  694. </dd>
  695. </div>
  696. </div>
  697. <div id="anyRune-procs-all">
  698. <div id="anyRune">
  699. <dt><pre><span class="Keyword">func</span> <a href="#anyRune"><span class="Identifier">anyRune</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  700. <dd>
  701. constructs the PEG <span id="any-rune_1">any rune</span> (<tt class="docutils literal"><span class="pre">_</span></tt>)
  702. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L272" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  703. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L272" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  704. </dd>
  705. </div>
  706. </div>
  707. <div id="backref-procs-all">
  708. <div id="backref,range[],bool">
  709. <dt><pre><span class="Keyword">func</span> <a href="#backref%2Crange%5B%5D%2Cbool"><span class="Identifier">backref</span></a><span class="Other">(</span><span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="Identifier">MaxSubpatterns</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">reverse</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.
  710. <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;npegs$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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  711. <dd>
  712. constructs a back reference of the given <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt> starts counting from 1. <tt class="docutils literal"><span class="pre"><span class="Identifier">reverse</span></span></tt> specifies whether indexing starts from the end of the capture list.
  713. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L313" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  714. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  715. </dd>
  716. </div>
  717. </div>
  718. <div id="backrefIgnoreCase-procs-all">
  719. <div id="backrefIgnoreCase,range[],bool">
  720. <dt><pre><span class="Keyword">func</span> <a href="#backrefIgnoreCase%2Crange%5B%5D%2Cbool"><span class="Identifier">backrefIgnoreCase</span></a><span class="Other">(</span><span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="Identifier">MaxSubpatterns</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">reverse</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.
  721. <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;npegs$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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  722. <dd>
  723. constructs a back reference of the given <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt> starts counting from 1. <tt class="docutils literal"><span class="pre"><span class="Identifier">reverse</span></span></tt> specifies whether indexing starts from the end of the capture list. Ignores case for matching.
  724. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L320" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  725. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L320" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  726. </dd>
  727. </div>
  728. </div>
  729. <div id="backrefIgnoreStyle-procs-all">
  730. <div id="backrefIgnoreStyle,range[],bool">
  731. <dt><pre><span class="Keyword">func</span> <a href="#backrefIgnoreStyle%2Crange%5B%5D%2Cbool"><span class="Identifier">backrefIgnoreStyle</span></a><span class="Other">(</span><span class="Identifier">index</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="Identifier">MaxSubpatterns</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">reverse</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> <span class="Other">=</span> <span class="Identifier">false</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.
  732. <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;npegs$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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  733. <dd>
  734. constructs a back reference of the given <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">index</span></span></tt> starts counting from 1. <tt class="docutils literal"><span class="pre"><span class="Identifier">reverse</span></span></tt> specifies whether indexing starts from the end of the capture list. Ignores style for matching.
  735. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L327" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  736. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L327" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  737. </dd>
  738. </div>
  739. </div>
  740. <div id="bounds-procs-all">
  741. <div id="bounds,Captures,range[]">
  742. <dt><pre><span class="Keyword">func</span> <a href="#bounds%2CCaptures%2Crange%5B%5D"><span class="Identifier">bounds</span></a><span class="Other">(</span><span class="Identifier">c</span><span class="Other">:</span> <a href="pegs.html#Captures"><span class="Identifier">Captures</span></a><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">20</span> <span class="Operator">-</span> <span class="DecNumber">1</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span> {.
  743. <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>
  744. <dd>
  745. returns the bounds <tt class="docutils literal"><span class="pre">[first..last]</span></tt> of the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>'th capture.
  746. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L541" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  747. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L541" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  748. </dd>
  749. </div>
  750. </div>
  751. <div id="capture-procs-all">
  752. <div id="capture,Peg">
  753. <dt><pre><span class="Keyword">func</span> <a href="#capture%2CPeg"><span class="Identifier">capture</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> <span class="Other">=</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">(</span><span class="Identifier">kind</span><span class="Other">:</span> <span class="DecNumber">pkEmpty</span><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegsCapture&quot;</span><span class="Other">,</span>
  754. <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>
  755. <dd>
  756. constructs a capture with the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  757. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L309" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  758. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L309" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  759. </dd>
  760. </div>
  761. </div>
  762. <div id="ch-procs-all">
  763. <div id="ch,Peg">
  764. <dt><pre><span class="Keyword">func</span> <a href="#ch%2CPeg"><span class="Identifier">ch</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</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>
  765. <dd>
  766. Returns the <em>char</em> representation of a given <em>Peg</em> variant object where present.
  767. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L99" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  768. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L99" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  769. </dd>
  770. </div>
  771. </div>
  772. <div id="charChoice-procs-all">
  773. <div id="charChoice,Peg">
  774. <dt><pre><span class="Keyword">func</span> <a href="#charChoice%2CPeg"><span class="Identifier">charChoice</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">ref</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  775. <dd>
  776. Returns the <em>charChoice</em> field of a given <em>Peg</em> variant object where present.
  777. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L103" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  778. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L103" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  779. </dd>
  780. </div>
  781. </div>
  782. <div id="charSet-procs-all">
  783. <div id="charSet,set[char]">
  784. <dt><pre><span class="Keyword">func</span> <a href="#charSet%2Cset%5Bchar%5D"><span class="Identifier">charSet</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$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>
  785. <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>
  786. <dd>
  787. constructs a PEG from a character set <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt>
  788. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L167" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  789. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L167" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  790. </dd>
  791. </div>
  792. </div>
  793. <div id="col-procs-all">
  794. <div id="col,NonTerminal">
  795. <dt><pre><span class="Keyword">func</span> <a href="#col%2CNonTerminal"><span class="Identifier">col</span></a><span class="Other">(</span><span class="Identifier">nt</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</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">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>
  796. <dd>
  797. Gets the column number of the definition of the parent <em>Peg</em> object variant of a given <em>NonTerminal</em>.
  798. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L133" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  799. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  800. </dd>
  801. </div>
  802. </div>
  803. <div id="contains-procs-all">
  804. <div id="contains,string,Peg,openArray[string],int">
  805. <dt><pre><span class="Keyword">func</span> <a href="#contains%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
  806. <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;npegs$1Capture&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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  807. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  808. <dd>
  809. same as <tt class="docutils literal"><span class="pre">find(s, pattern, matches, start) &gt;= 0</span></tt>
  810. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1207" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  811. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1207" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  812. </dd>
  813. </div>
  814. <div id="contains,string,Peg,int">
  815. <dt><pre><span class="Keyword">func</span> <a href="#contains%2Cstring%2CPeg%2Cint"><span class="Identifier">contains</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  816. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  817. <dd>
  818. same as <tt class="docutils literal"><span class="pre">find(s, pattern, start) &gt;= 0</span></tt>
  819. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1202" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  820. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1202" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  821. </dd>
  822. </div>
  823. </div>
  824. <div id="endAnchor-procs-all">
  825. <div id="endAnchor">
  826. <dt><pre><span class="Keyword">func</span> <a href="#endAnchor"><span class="Identifier">endAnchor</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  827. <dd>
  828. constructs the PEG <tt class="docutils literal"><span class="pre">$</span></tt> which matches the end of the input.
  829. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L305" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  830. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L305" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  831. </dd>
  832. </div>
  833. </div>
  834. <div id="endsWith-procs-all">
  835. <div id="endsWith,string,Peg,int">
  836. <dt><pre><span class="Keyword">func</span> <a href="#endsWith%2Cstring%2CPeg%2Cint"><span class="Identifier">endsWith</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">suffix</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  837. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  838. <dd>
  839. returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> ends with the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">suffix</span></span></tt>
  840. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1217" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  841. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1217" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  842. </dd>
  843. </div>
  844. </div>
  845. <div id="escapePeg-procs-all">
  846. <div id="escapePeg,string">
  847. <dt><pre><span class="Keyword">func</span> <a href="#escapePeg%2Cstring"><span class="Identifier">escapePeg</span></a><span class="Other">(</span><span class="Identifier">s</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">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>
  848. <dd>
  849. escapes <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> so that it is matched verbatim when used as a peg.
  850. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L2067" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  851. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L2067" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  852. </dd>
  853. </div>
  854. </div>
  855. <div id="find-procs-all">
  856. <div id="find,string,Peg,openArray[string],int">
  857. <dt><pre><span class="Keyword">func</span> <a href="#find%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  858. <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;npegs$1Capture&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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  859. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  860. <dd>
  861. returns the starting position of <tt class="docutils literal"><span class="pre">pattern</span></tt> in <tt class="docutils literal"><span class="pre">s</span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre">matches</span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre">matches</span></tt> and -1 is returned.
  862. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1119" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  863. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1119" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  864. </dd>
  865. </div>
  866. <div id="find,string,Peg,int">
  867. <dt><pre><span class="Keyword">func</span> <a href="#find%2Cstring%2CPeg%2Cint"><span class="Identifier">find</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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;npegs$1&quot;</span><span class="Other">,</span>
  868. <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="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>
  869. <dd>
  870. returns the starting position of <tt class="docutils literal"><span class="pre">pattern</span></tt> in <tt class="docutils literal"><span class="pre">s</span></tt>. If it does not match, -1 is returned.
  871. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1149" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  872. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1149" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  873. </dd>
  874. </div>
  875. </div>
  876. <div id="findAll-procs-all">
  877. <div id="findAll,string,Peg,int">
  878. <dt><pre><span class="Keyword">func</span> <a href="#findAll%2Cstring%2CPeg%2Cint"><span class="Identifier">findAll</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><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">gcsafe</span><span class="Other">,</span>
  879. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  880. <dd>
  881. returns all matching <em>substrings</em> of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> that match <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>. If it does not match, <tt class="docutils literal"><span class="pre"><span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">]</span></span></tt> is returned.
  882. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1171" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  883. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1171" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  884. </dd>
  885. </div>
  886. </div>
  887. <div id="findBounds-procs-all">
  888. <div id="findBounds,string,Peg,openArray[string],int">
  889. <dt><pre><span class="Keyword">func</span> <a href="#findBounds%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">findBounds</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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>
  890. <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">first</span><span class="Other">,</span> <span class="Identifier">last</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</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>
  891. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$1Capture&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="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>
  892. <dd>
  893. returns the starting position and end position of <tt class="docutils literal"><span class="pre">pattern</span></tt> in <tt class="docutils literal"><span class="pre">s</span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre">matches</span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre">matches</span></tt> and (-1,0) is returned.
  894. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1133" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  895. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  896. </dd>
  897. </div>
  898. </div>
  899. <div id="flags-procs-all">
  900. <div id="flags,NonTerminal">
  901. <dt><pre><span class="Keyword">func</span> <a href="#flags%2CNonTerminal"><span class="Identifier">flags</span></a><span class="Other">(</span><span class="Identifier">nt</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#set"><span class="Identifier">set</span></a><span class="Other">[</span><a href="pegs.html#NonTerminalFlag"><span class="Identifier">NonTerminalFlag</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>
  902. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  903. <dd>
  904. Gets the <em>NonTerminalFlag</em>-typed flags field of the parent <em>Peg</em> variant object of a given <em>NonTerminal</em>.
  905. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L137" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  906. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L137" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  907. </dd>
  908. </div>
  909. </div>
  910. <div id="index-procs-all">
  911. <div id="index,Peg">
  912. <dt><pre><span class="Keyword">func</span> <a href="#index%2CPeg"><span class="Identifier">index</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="Operator">-</span><span class="DecNumber">20</span> <span class="Operator">..</span> <span class="DecNumber">20</span> <span class="Operator">-</span> <span class="DecNumber">1</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  913. <dd>
  914. Returns the back-reference index of a captured sub-pattern in the <em>Captures</em> object for a given <em>Peg</em> variant object where present.
  915. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L111" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  916. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L111" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  917. </dd>
  918. </div>
  919. </div>
  920. <div id="kind-procs-all">
  921. <div id="kind,Peg">
  922. <dt><pre><span class="Keyword">func</span> <a href="#kind%2CPeg"><span class="Identifier">kind</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#PegKind"><span class="Identifier">PegKind</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>
  923. <dd>
  924. Returns the <em>PegKind</em> of a given <em>Peg</em> object.
  925. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L92" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  926. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L92" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  927. </dd>
  928. </div>
  929. </div>
  930. <div id="line-procs-all">
  931. <div id="line,NonTerminal">
  932. <dt><pre><span class="Keyword">func</span> <a href="#line%2CNonTerminal"><span class="Identifier">line</span></a><span class="Other">(</span><span class="Identifier">nt</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</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">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>
  933. <dd>
  934. Gets the line number of the definition of the parent <em>Peg</em> object variant of a given <em>NonTerminal</em>.
  935. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L129" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  936. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L129" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  937. </dd>
  938. </div>
  939. </div>
  940. <div id="match-procs-all">
  941. <div id="match,string,Peg,openArray[string],int">
  942. <dt><pre><span class="Keyword">func</span> <a href="#match%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.
  943. <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;npegs$1Capture&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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  944. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  945. <dd>
  946. returns <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">s[start..]</span></tt> matches the <tt class="docutils literal"><span class="pre">pattern</span></tt> and the captured substrings in the array <tt class="docutils literal"><span class="pre">matches</span></tt>. If it does not match, nothing is written into <tt class="docutils literal"><span class="pre">matches</span></tt> and <tt class="docutils literal"><span class="pre">false</span></tt> is returned.
  947. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1105" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  948. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1105" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  949. </dd>
  950. </div>
  951. <div id="match,string,Peg,int">
  952. <dt><pre><span class="Keyword">func</span> <a href="#match%2Cstring%2CPeg%2Cint"><span class="Identifier">match</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  953. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  954. <dd>
  955. returns <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">s</span></tt> matches the <tt class="docutils literal"><span class="pre">pattern</span></tt> beginning from <tt class="docutils literal"><span class="pre">start</span></tt>.
  956. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1113" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  957. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1113" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  958. </dd>
  959. </div>
  960. </div>
  961. <div id="matchLen-procs-all">
  962. <div id="matchLen,string,Peg,openArray[string],int">
  963. <dt><pre><span class="Keyword">func</span> <a href="#matchLen%2Cstring%2CPeg%2CopenArray%5Bstring%5D%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">matches</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="system.html#openArray"><span class="Identifier">openArray</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> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.
  964. <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;npegs$1Capture&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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  965. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  966. <dd>
  967. the same as <tt class="docutils literal"><span class="pre">match</span></tt>, but it returns the length of the match, if there is no match, -1 is returned. Note that a match length of zero can happen. It's possible that a suffix of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> remains that does not belong to the match.
  968. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1086" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  969. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1086" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  970. </dd>
  971. </div>
  972. <div id="matchLen,string,Peg,int">
  973. <dt><pre><span class="Keyword">func</span> <a href="#matchLen%2Cstring%2CPeg%2Cint"><span class="Identifier">matchLen</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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>
  974. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  975. <dd>
  976. the same as <tt class="docutils literal"><span class="pre">match</span></tt>, but it returns the length of the match, if there is no match, -1 is returned. Note that a match length of zero can happen. It's possible that a suffix of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> remains that does not belong to the match.
  977. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1096" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  978. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1096" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  979. </dd>
  980. </div>
  981. </div>
  982. <div id="name-procs-all">
  983. <div id="name,NonTerminal">
  984. <dt><pre><span class="Keyword">func</span> <a href="#name%2CNonTerminal"><span class="Identifier">name</span></a><span class="Other">(</span><span class="Identifier">nt</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</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="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>
  985. <dd>
  986. Gets the name of the symbol represented by the parent <em>Peg</em> object variant of a given <em>NonTerminal</em>.
  987. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L125" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  988. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L125" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  989. </dd>
  990. </div>
  991. </div>
  992. <div id="newLine-procs-all">
  993. <div id="newLine">
  994. <dt><pre><span class="Keyword">func</span> <a href="#newLine"><span class="Identifier">newLine</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  995. <dd>
  996. constructs the PEG <span id="newline_1">newline</span> (<tt class="docutils literal"><span class="pre">\n</span></tt>)
  997. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L276" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  998. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L276" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  999. </dd>
  1000. </div>
  1001. </div>
  1002. <div id="newNonTerminal-procs-all">
  1003. <div id="newNonTerminal,string,int,int">
  1004. <dt><pre><span class="Keyword">func</span> <a href="#newNonTerminal%2Cstring%2Cint%2Cint"><span class="Identifier">newNonTerminal</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">line</span><span class="Other">,</span> <span class="Identifier">column</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  1005. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1006. <dd>
  1007. constructs a nonterminal symbol
  1008. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L360" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1009. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L360" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1010. </dd>
  1011. </div>
  1012. </div>
  1013. <div id="nonterminal-procs-all">
  1014. <div id="nonterminal,NonTerminal">
  1015. <dt><pre><span class="Keyword">func</span> <a href="#nonterminal%2CNonTerminal"><span class="Identifier">nonterminal</span></a><span class="Other">(</span><span class="Identifier">n</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$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>
  1016. <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>
  1017. <dd>
  1018. constructs a PEG that consists of the nonterminal symbol
  1019. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L350" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1020. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L350" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1021. </dd>
  1022. </div>
  1023. </div>
  1024. <div id="nt-procs-all">
  1025. <div id="nt,Peg">
  1026. <dt><pre><span class="Keyword">func</span> <a href="#nt%2CPeg"><span class="Identifier">nt</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</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>
  1027. <dd>
  1028. Returns the <em>NonTerminal</em> object of a given <em>Peg</em> variant object where present.
  1029. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L107" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1030. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L107" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1031. </dd>
  1032. </div>
  1033. </div>
  1034. <div id="parallelReplace-procs-all">
  1035. <div id="parallelReplace,string,varargs[tuple[Peg,string]]">
  1036. <dt><pre><span class="Keyword">func</span> <a href="#parallelReplace%2Cstring%2Cvarargs%5Btuple%5BPeg%2Cstring%5D%5D"><span class="Identifier">parallelReplace</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">subs</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">,</span> <span class="Identifier">repl</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.
  1037. <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;npegs$1&quot;</span><span class="Other">,</span> <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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  1038. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1039. <dd>
  1040. Returns a modified copy of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> with the substitutions in <tt class="docutils literal"><span class="pre"><span class="Identifier">subs</span></span></tt> applied in parallel.
  1041. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1272" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1042. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1272" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1043. </dd>
  1044. </div>
  1045. </div>
  1046. <div id="parsePeg-procs-all">
  1047. <div id="parsePeg,string,string,int,int">
  1048. <dt><pre><span class="Keyword">func</span> <a href="#parsePeg%2Cstring%2Cstring%2Cint%2Cint"><span class="Identifier">parsePeg</span></a><span class="Other">(</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">filename</span> <span class="Other">=</span> <span class="StringLit">&quot;pattern&quot;</span><span class="Other">;</span> <span class="Identifier">line</span> <span class="Other">=</span> <span class="DecNumber">1</span><span class="Other">;</span> <span class="Identifier">col</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.
  1049. <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">ValueError</span><span class="Other">,</span> <span class="Identifier">EInvalidPeg</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  1050. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1051. <dd>
  1052. constructs a Peg object from <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">filename</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">line</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">col</span></span></tt> are used for error messages, but they only provide start offsets. <tt class="docutils literal"><span class="pre"><span class="Identifier">parsePeg</span></span></tt> keeps track of line and column numbers within <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>.
  1053. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L2045" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1054. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L2045" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1055. </dd>
  1056. </div>
  1057. </div>
  1058. <div id="peg-procs-all">
  1059. <div id="peg,string">
  1060. <dt><pre><span class="Keyword">func</span> <a href="#peg%2Cstring"><span class="Identifier">peg</span></a><span class="Other">(</span><span class="Identifier">pattern</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="pegs.html#Peg"><span class="Identifier">Peg</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">ValueError</span><span class="Other">,</span> <span class="Identifier">EInvalidPeg</span><span class="Other">,</span> <span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
  1061. <span class="Identifier">tags</span><span class="Other">:</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>
  1062. <dd>
  1063. constructs a Peg object from the <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>. The short name has been chosen to encourage its use as a raw string modifier:<pre>peg&quot;{\ident} \s* '=' \s* {.*}&quot;</pre>
  1064. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L2060" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1065. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L2060" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1066. </dd>
  1067. </div>
  1068. </div>
  1069. <div id="rawMatch-procs-all">
  1070. <div id="rawMatch,string,Peg,int,Captures">
  1071. <dt><pre><span class="Keyword">func</span> <a href="#rawMatch%2Cstring%2CPeg%2Cint%2CCaptures"><span class="Identifier">rawMatch</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">c</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="pegs.html#Captures"><span class="Identifier">Captures</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>
  1072. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  1073. <dd>
  1074. low-level matching proc that implements the PEG interpreter. Use this for maximum efficiency (every other PEG operation ends up calling this proc). Returns -1 if it does not match, else the length of the match
  1075. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L871" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1076. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L871" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1077. </dd>
  1078. </div>
  1079. </div>
  1080. <div id="replace-procs-all">
  1081. <div id="replace,string,Peg,proc(int,int,openArray[string])">
  1082. <dt><pre><span class="Keyword">func</span> <a href="#replace%2Cstring%2CPeg%2Cproc%28int%2Cint%2CopenArray%5Bstring%5D%29"><span class="Identifier">replace</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span>
  1083. <span class="Identifier">cb</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">match</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">cnt</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">;</span> <span class="Identifier">caps</span><span class="Other">:</span> <a href="system.html#openArray"><span class="Identifier">openArray</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><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> {.
  1084. <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;npegs$1cb&quot;</span><span class="Other">,</span> </span><span class="Identifier">effectsOf</span><span class="Other">:</span> <span class="Identifier">cb</span><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="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  1085. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1086. <dd>
  1087. <p>Replaces <tt class="docutils literal"><span class="pre"><span class="Identifier">sub</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> by the resulting strings from the callback. The callback proc receives the index of the current match (starting with 0), the count of captures and an open array with the captures of each match. Examples:</p>
  1088. <p><pre class="listing"><span class="Keyword">func</span> <span class="Identifier">handleMatches</span><span class="Operator">*</span><span class="Punctuation">(</span><span class="Identifier">m</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">n</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">c</span><span class="Punctuation">:</span> <span class="Identifier">openArray</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span> <span class="Operator">=</span>
  1089. <span class="Identifier">result</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  1090. <span class="Keyword">if</span> <span class="Identifier">m</span> <span class="Operator">&gt;</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
  1091. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="StringLit">&quot;, &quot;</span>
  1092. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Keyword">case</span> <span class="Identifier">n</span><span class="Punctuation">:</span>
  1093. <span class="Keyword">of</span> <span class="DecNumber">2</span><span class="Punctuation">:</span> <span class="Identifier">c</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toLower</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;: '&quot;</span> <span class="Operator">&amp;</span> <span class="Identifier">c</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">]</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;'&quot;</span>
  1094. <span class="Keyword">of</span> <span class="DecNumber">1</span><span class="Punctuation">:</span> <span class="Identifier">c</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">toLower</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;: ''&quot;</span>
  1095. <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="StringLit">&quot;&quot;</span>
  1096. <span class="Keyword">let</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="StringLit">&quot;Var1=key1;var2=Key2; VAR3&quot;</span>
  1097. <span class="Identifier">echo</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">replace</span><span class="Punctuation">(</span><span class="RawData">peg&quot;{\ident}('='{\ident})* ';'* \s*&quot;</span><span class="Punctuation">,</span> <span class="Identifier">handleMatches</span><span class="Punctuation">)</span></pre></p>
  1098. <p>Results in:</p>
  1099. <p><pre class="listing"><span class="StringLit">&quot;var1: 'key1', var2: 'Key2', var3: ''&quot;</span></pre></p>
  1100. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1299" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1101. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1299" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1102. </dd>
  1103. </div>
  1104. <div id="replace,string,Peg,string">
  1105. <dt><pre><span class="Keyword">func</span> <a href="#replace%2Cstring%2CPeg%2Cstring"><span class="Identifier">replace</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">by</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> {.<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;npegs$1&quot;</span><span class="Other">,</span>
  1106. <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="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>
  1107. <dd>
  1108. Replaces <tt class="docutils literal"><span class="pre"><span class="Identifier">sub</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> by the string <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>. Captures cannot be accessed in <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>.
  1109. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1255" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1110. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1255" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1111. </dd>
  1112. </div>
  1113. </div>
  1114. <div id="replacef-procs-all">
  1115. <div id="replacef,string,Peg,string">
  1116. <dt><pre><span class="Keyword">func</span> <a href="#replacef%2Cstring%2CPeg%2Cstring"><span class="Identifier">replacef</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sub</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">by</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>
  1117. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$1&quot;</span><span class="Other">,</span> <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="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>
  1118. <dd>
  1119. <p>Replaces <tt class="docutils literal"><span class="pre"><span class="Identifier">sub</span></span></tt> in <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> by the string <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt>. Captures can be accessed in <tt class="docutils literal"><span class="pre"><span class="Identifier">by</span></span></tt> with the notation <tt class="docutils literal"><span class="pre">$i</span></tt> and <tt class="docutils literal"><span class="pre">$#</span></tt> (see strutils.<tt class="docutils literal"><span class="pre"><span class="Operator">%</span></span></tt>). Examples:</p>
  1120. <p><pre class="listing"><span class="StringLit">&quot;var1=key; var2=key2&quot;</span><span class="Operator">.</span><span class="Identifier">replacef</span><span class="Punctuation">(</span><span class="RawData">peg&quot;{\ident}'='{\ident}&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;$1&lt;-$2$2&quot;</span><span class="Punctuation">)</span></pre></p>
  1121. <p>Results in:</p>
  1122. <p><pre class="listing"><span class="StringLit">&quot;var1&lt;-keykey; val2&lt;-key2key2&quot;</span></pre></p>
  1123. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1225" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1124. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1225" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1125. </dd>
  1126. </div>
  1127. </div>
  1128. <div id="rule-procs-all">
  1129. <div id="rule,NonTerminal">
  1130. <dt><pre><span class="Keyword">func</span> <a href="#rule%2CNonTerminal"><span class="Identifier">rule</span></a><span class="Other">(</span><span class="Identifier">nt</span><span class="Other">:</span> <a href="pegs.html#NonTerminal"><span class="Identifier">NonTerminal</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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>
  1131. <dd>
  1132. Gets the <em>Peg</em> object representing the rule definition of the parent <em>Peg</em> object variant of a given <em>NonTerminal</em>.
  1133. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L141" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1134. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L141" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1135. </dd>
  1136. </div>
  1137. </div>
  1138. <div id="sequence-procs-all">
  1139. <div id="sequence,varargs[Peg]">
  1140. <dt><pre><span class="Keyword">func</span> <a href="#sequence%2Cvarargs%5BPeg%5D"><span class="Identifier">sequence</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$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>
  1141. <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>
  1142. <dd>
  1143. constructs a sequence with all the PEGs from <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>
  1144. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L218" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1145. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L218" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1146. </dd>
  1147. </div>
  1148. </div>
  1149. <div id="split-procs-all">
  1150. <div id="split,string,Peg">
  1151. <dt><pre><span class="Keyword">func</span> <a href="#split%2Cstring%2CPeg"><span class="Identifier">split</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sep</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#seq"><span class="Identifier">seq</span></a><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">gcsafe</span><span class="Other">,</span> <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$1&quot;</span><span class="Other">,</span>
  1152. <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="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>
  1153. <dd>
  1154. Splits the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into substrings.
  1155. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1392" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1156. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1392" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1157. </dd>
  1158. </div>
  1159. </div>
  1160. <div id="startAnchor-procs-all">
  1161. <div id="startAnchor">
  1162. <dt><pre><span class="Keyword">func</span> <a href="#startAnchor"><span class="Identifier">startAnchor</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1163. <dd>
  1164. constructs the PEG <tt class="docutils literal"><span class="pre">^</span></tt> which matches the start of the input.
  1165. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L301" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1166. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L301" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1167. </dd>
  1168. </div>
  1169. </div>
  1170. <div id="startsWith-procs-all">
  1171. <div id="startsWith,string,Peg,int">
  1172. <dt><pre><span class="Keyword">func</span> <a href="#startsWith%2Cstring%2CPeg%2Cint"><span class="Identifier">startsWith</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">prefix</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  1173. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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="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>
  1174. <dd>
  1175. returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> starts with the pattern <tt class="docutils literal"><span class="pre"><span class="Identifier">prefix</span></span></tt>
  1176. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1212" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1177. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1212" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1178. </dd>
  1179. </div>
  1180. </div>
  1181. <div id="term-procs-all">
  1182. <div id="term,Peg">
  1183. <dt><pre><span class="Keyword">func</span> <a href="#term%2CPeg"><span class="Identifier">term</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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="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>
  1184. <dd>
  1185. Returns the <em>string</em> representation of a given <em>Peg</em> variant object where present.
  1186. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L95" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1187. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L95" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1188. </dd>
  1189. </div>
  1190. <div id="term,char">
  1191. <dt><pre><span class="Keyword">func</span> <a href="#term%2Cchar"><span class="Identifier">term</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#char"><span class="Identifier">char</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$1Char&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>
  1192. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1193. <dd>
  1194. constructs a PEG from a terminal char
  1195. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L162" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1196. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L162" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1197. </dd>
  1198. </div>
  1199. <div id="term,string">
  1200. <dt><pre><span class="Keyword">func</span> <a href="#term%2Cstring"><span class="Identifier">term</span></a><span class="Other">(</span><span class="Identifier">t</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="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$1Str&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>
  1201. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1202. <dd>
  1203. constructs a PEG from a terminal string
  1204. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L145" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1205. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L145" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1206. </dd>
  1207. </div>
  1208. </div>
  1209. <div id="termIgnoreCase-procs-all">
  1210. <div id="termIgnoreCase,string">
  1211. <dt><pre><span class="Keyword">func</span> <a href="#termIgnoreCase%2Cstring"><span class="Identifier">termIgnoreCase</span></a><span class="Other">(</span><span class="Identifier">t</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="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$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>
  1212. <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>
  1213. <dd>
  1214. constructs a PEG from a terminal string; ignore case for matching
  1215. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L152" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1216. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L152" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1217. </dd>
  1218. </div>
  1219. </div>
  1220. <div id="termIgnoreStyle-procs-all">
  1221. <div id="termIgnoreStyle,string">
  1222. <dt><pre><span class="Keyword">func</span> <a href="#termIgnoreStyle%2Cstring"><span class="Identifier">termIgnoreStyle</span></a><span class="Other">(</span><span class="Identifier">t</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="pegs.html#Peg"><span class="Identifier">Peg</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;npegs$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>
  1223. <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>
  1224. <dd>
  1225. constructs a PEG from a terminal string; ignore style for matching
  1226. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L157" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1227. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L157" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1228. </dd>
  1229. </div>
  1230. </div>
  1231. <div id="transformFile-procs-all">
  1232. <div id="transformFile,string,string,varargs[tuple[Peg,string]]">
  1233. <dt><pre><span class="Keyword">proc</span> <a href="#transformFile%2Cstring%2Cstring%2Cvarargs%5Btuple%5BPeg%2Cstring%5D%5D"><span class="Identifier">transformFile</span></a><span class="Other">(</span><span class="Identifier">infile</span><span class="Other">,</span> <span class="Identifier">outfile</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span>
  1234. <span class="Identifier">subs</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">,</span> <span class="Identifier">repl</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">]</span><span class="Other">]</span><span class="Other">)</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">gcsafe</span><span class="Other">,</span>
  1235. <span class="Identifier">extern</span><span class="Other">:</span> <span class="StringLit">&quot;npegs$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">ValueError</span><span class="Other">]</span><span class="Other">,</span>
  1236. <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">WriteIOEffect</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>
  1237. <dd>
  1238. <p>reads in the file <tt class="docutils literal"><span class="pre"><span class="Identifier">infile</span></span></tt>, performs a parallel replacement (calls <tt class="docutils literal"><span class="pre"><span class="Identifier">parallelReplace</span></span></tt>) and writes back to <tt class="docutils literal"><span class="pre"><span class="Identifier">outfile</span></span></tt>. Raises <tt class="docutils literal"><span class="pre">IOError</span></tt> if an error occurs. This is supposed to be used for quick scripting.</p>
  1239. <p><strong>Note</strong>: this proc does not exist while using the JS backend.</p>
  1240. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1344" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1241. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1344" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1242. </dd>
  1243. </div>
  1244. </div>
  1245. <div id="unicodeLetter-procs-all">
  1246. <div id="unicodeLetter">
  1247. <dt><pre><span class="Keyword">func</span> <a href="#unicodeLetter"><span class="Identifier">unicodeLetter</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1248. <dd>
  1249. constructs the PEG <tt class="docutils literal"><span class="pre">\letter</span></tt> which matches any Unicode letter.
  1250. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L280" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1251. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L280" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1252. </dd>
  1253. </div>
  1254. </div>
  1255. <div id="unicodeLower-procs-all">
  1256. <div id="unicodeLower">
  1257. <dt><pre><span class="Keyword">func</span> <a href="#unicodeLower"><span class="Identifier">unicodeLower</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1258. <dd>
  1259. constructs the PEG <tt class="docutils literal"><span class="pre">\lower</span></tt> which matches any Unicode lowercase letter.
  1260. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L284" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1261. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L284" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1262. </dd>
  1263. </div>
  1264. </div>
  1265. <div id="unicodeTitle-procs-all">
  1266. <div id="unicodeTitle">
  1267. <dt><pre><span class="Keyword">func</span> <a href="#unicodeTitle"><span class="Identifier">unicodeTitle</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1268. <dd>
  1269. constructs the PEG <tt class="docutils literal"><span class="pre">\title</span></tt> which matches any Unicode title letter.
  1270. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L292" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1271. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L292" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1272. </dd>
  1273. </div>
  1274. </div>
  1275. <div id="unicodeUpper-procs-all">
  1276. <div id="unicodeUpper">
  1277. <dt><pre><span class="Keyword">func</span> <a href="#unicodeUpper"><span class="Identifier">unicodeUpper</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1278. <dd>
  1279. constructs the PEG <tt class="docutils literal"><span class="pre">\upper</span></tt> which matches any Unicode uppercase letter.
  1280. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L288" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1281. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L288" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1282. </dd>
  1283. </div>
  1284. </div>
  1285. <div id="unicodeWhitespace-procs-all">
  1286. <div id="unicodeWhitespace">
  1287. <dt><pre><span class="Keyword">func</span> <a href="#unicodeWhitespace"><span class="Identifier">unicodeWhitespace</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1288. <dd>
  1289. constructs the PEG <tt class="docutils literal"><span class="pre">\white</span></tt> which matches any Unicode whitespace character.
  1290. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L296" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1291. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L296" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1292. </dd>
  1293. </div>
  1294. </div>
  1295. </dl>
  1296. </div>
  1297. <div class="section" id="15">
  1298. <h1><a class="toc-backref" href="#15">Iterators</a></h1>
  1299. <dl class="item">
  1300. <div id="findAll-iterators-all">
  1301. <div id="findAll.i,string,Peg,int">
  1302. <dt><pre><span class="Keyword">iterator</span> <a href="#findAll.i%2Cstring%2CPeg%2Cint"><span class="Identifier">findAll</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">;</span> <span class="Identifier">start</span> <span class="Other">=</span> <span class="DecNumber">0</span><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="Other">]</span><span class="Other">,</span>
  1303. <span class="Identifier">tags</span><span class="Other">:</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>
  1304. <dd>
  1305. yields all matching <em>substrings</em> of <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> that match <tt class="docutils literal"><span class="pre"><span class="Identifier">pattern</span></span></tt>.
  1306. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1158" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1307. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1158" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1308. </dd>
  1309. </div>
  1310. </div>
  1311. <div id="items-iterators-all">
  1312. <div id="items.i,Peg">
  1313. <dt><pre><span class="Keyword">iterator</span> <a href="#items.i%2CPeg"><span class="Identifier">items</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1314. <dd>
  1315. Yields the child nodes of a <em>Peg</em> variant object where present.
  1316. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L115" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1317. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L115" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1318. </dd>
  1319. </div>
  1320. </div>
  1321. <div id="pairs-iterators-all">
  1322. <div id="pairs.i,Peg">
  1323. <dt><pre><span class="Keyword">iterator</span> <a href="#pairs.i%2CPeg"><span class="Identifier">pairs</span></a><span class="Other">(</span><span class="Identifier">p</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">,</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span> {.<span class="Identifier">inline</span><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> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1324. <dd>
  1325. Yields the indices and child nodes of a <em>Peg</em> variant object where present.
  1326. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L120" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1327. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L120" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1328. </dd>
  1329. </div>
  1330. </div>
  1331. <div id="split-iterators-all">
  1332. <div id="split.i,string,Peg">
  1333. <dt><pre><span class="Keyword">iterator</span> <a href="#split.i%2Cstring%2CPeg"><span class="Identifier">split</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">sep</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</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="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span><span class="Other">,</span>
  1334. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  1335. <dd>
  1336. <p>Splits the string <tt class="docutils literal"><span class="pre"><span class="Identifier">s</span></span></tt> into substrings.</p>
  1337. <p>Substrings are separated by the PEG <tt class="docutils literal"><span class="pre"><span class="Identifier">sep</span></span></tt>. Examples:</p>
  1338. <p><pre class="listing"><span class="Keyword">for</span> <span class="Identifier">word</span> <span class="Keyword">in</span> <span class="Identifier">split</span><span class="Punctuation">(</span><span class="StringLit">&quot;00232this02939is39an22example111&quot;</span><span class="Punctuation">,</span> <span class="RawData">peg&quot;\d+&quot;</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  1339. <span class="Identifier">writeLine</span><span class="Punctuation">(</span><span class="Identifier">stdout</span><span class="Punctuation">,</span> <span class="Identifier">word</span><span class="Punctuation">)</span></pre></p>
  1340. <p>Results in:</p>
  1341. <p><pre class="listing"><span class="StringLit">&quot;this&quot;</span>
  1342. <span class="StringLit">&quot;is&quot;</span>
  1343. <span class="StringLit">&quot;an&quot;</span>
  1344. <span class="StringLit">&quot;example&quot;</span></pre></p>
  1345. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1356" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1346. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1356" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1347. </dd>
  1348. </div>
  1349. </div>
  1350. </dl>
  1351. </div>
  1352. <div class="section" id="18">
  1353. <h1><a class="toc-backref" href="#18">Templates</a></h1>
  1354. <dl class="item">
  1355. <div id="=~-templates-all">
  1356. <div id="=~.t,string,Peg">
  1357. <dt><pre><span class="Keyword">template</span> <a href="#%3D~.t%2Cstring%2CPeg"><span class="Identifier">`=~`</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a><span class="Other">;</span> <span class="Identifier">pattern</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a></pre></dt>
  1358. <dd>
  1359. <p>This calls <tt class="docutils literal"><span class="pre">match</span></tt> with an implicit declared <tt class="docutils literal"><span class="pre">matches</span></tt> array that can be used in the scope of the <tt class="docutils literal"><span class="pre">=~</span></tt> call:</p>
  1360. <p><pre class="listing"><span class="Keyword">if</span> <span class="Identifier">line</span> <span class="Operator">=~</span> <span class="RawData">peg&quot;\s* {\w+} \s* '=' \s* {\w+}&quot;</span><span class="Punctuation">:</span>
  1361. <span class="Comment"># matches a key=value pair:</span>
  1362. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;Key: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1363. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;Value: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1364. <span class="Keyword">elif</span> <span class="Identifier">line</span> <span class="Operator">=~</span> <span class="RawData">peg&quot;\s*{'#'.*}&quot;</span><span class="Punctuation">:</span>
  1365. <span class="Comment"># matches a comment</span>
  1366. <span class="Comment"># note that the implicit ``matches`` array is different from the</span>
  1367. <span class="Comment"># ``matches`` array of the first branch</span>
  1368. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;comment: &quot;</span><span class="Punctuation">,</span> <span class="Identifier">matches</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span>
  1369. <span class="Keyword">else</span><span class="Punctuation">:</span>
  1370. <span class="Identifier">echo</span><span class="Punctuation">(</span><span class="StringLit">&quot;syntax error&quot;</span><span class="Punctuation">)</span></pre></p>
  1371. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L1178" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1372. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L1178" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1373. </dd>
  1374. </div>
  1375. </div>
  1376. <div id="digits-templates-all">
  1377. <div id="digits.t">
  1378. <dt><pre><span class="Keyword">template</span> <a href="#digits.t"><span class="Identifier">digits</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1379. <dd>
  1380. expands to <tt class="docutils literal"><span class="pre">charset({'0'..'9'})</span></tt>
  1381. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L369" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1382. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L369" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1383. </dd>
  1384. </div>
  1385. </div>
  1386. <div id="eventParser-templates-all">
  1387. <div id="eventParser.t,untyped,untyped">
  1388. <dt><pre><span class="Keyword">template</span> <a href="#eventParser.t%2Cuntyped%2Cuntyped"><span class="Identifier">eventParser</span></a><span class="Other">(</span><span class="Identifier">pegAst</span><span class="Other">,</span> <span class="Identifier">handlers</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Other">(</span><span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">s</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#int"><span class="Identifier">int</span></a><span class="Other">)</span></pre></dt>
  1389. <dd>
  1390. <p>Generates an interpreting event parser <em>proc</em> according to the specified PEG AST and handler code blocks. The <em>proc</em> can be called with a string to be parsed and will execute the handler code blocks whenever their associated grammar element is matched. It returns -1 if the string does not match, else the length of the total match. The following example code evaluates an arithmetic expression defined by a simple PEG:</p>
  1391. <p><pre class="listing"><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">pegs</span><span class="Punctuation">]</span>
  1392. <span class="Keyword">let</span>
  1393. <span class="Identifier">pegAst</span> <span class="Operator">=</span> <span class="LongStringLit">&quot;&quot;&quot;
  1394. Expr &lt;- Sum
  1395. Sum &lt;- Product (('+' / '-')Product)*
  1396. Product &lt;- Value (('*' / '/')Value)*
  1397. Value &lt;- [0-9]+ / '(' Expr ')'
  1398. &quot;&quot;&quot;</span><span class="Operator">.</span><span class="Identifier">peg</span>
  1399. <span class="Identifier">txt</span> <span class="Operator">=</span> <span class="StringLit">&quot;(5+3)/2-7*22&quot;</span>
  1400. <span class="Keyword">var</span>
  1401. <span class="Identifier">pStack</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">]</span>
  1402. <span class="Identifier">valStack</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Operator">@</span><span class="Punctuation">[</span><span class="Punctuation">]</span>
  1403. <span class="Identifier">opStack</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  1404. <span class="Keyword">let</span>
  1405. <span class="Identifier">parseArithExpr</span> <span class="Operator">=</span> <span class="Identifier">pegAst</span><span class="Operator">.</span><span class="Identifier">eventParser</span><span class="Punctuation">:</span>
  1406. <span class="Identifier">pkNonTerminal</span><span class="Punctuation">:</span>
  1407. <span class="Identifier">enter</span><span class="Punctuation">:</span>
  1408. <span class="Identifier">pStack</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">nt</span><span class="Operator">.</span><span class="Identifier">name</span>
  1409. <span class="Identifier">leave</span><span class="Punctuation">:</span>
  1410. <span class="Identifier">pStack</span><span class="Operator">.</span><span class="Identifier">setLen</span> <span class="Identifier">pStack</span><span class="Operator">.</span><span class="Identifier">high</span>
  1411. <span class="Keyword">if</span> <span class="Identifier">length</span> <span class="Operator">&gt;</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
  1412. <span class="Keyword">let</span> <span class="Identifier">matchStr</span> <span class="Operator">=</span> <span class="Identifier">s</span><span class="Operator">.</span><span class="Identifier">substr</span><span class="Punctuation">(</span><span class="Identifier">start</span><span class="Punctuation">,</span> <span class="Identifier">start</span><span class="Operator">+</span><span class="Identifier">length</span><span class="Operator">-</span><span class="DecNumber">1</span><span class="Punctuation">)</span>
  1413. <span class="Keyword">case</span> <span class="Identifier">p</span><span class="Operator">.</span><span class="Identifier">nt</span><span class="Operator">.</span><span class="Identifier">name</span>
  1414. <span class="Keyword">of</span> <span class="StringLit">&quot;Value&quot;</span><span class="Punctuation">:</span>
  1415. <span class="Keyword">try</span><span class="Punctuation">:</span>
  1416. <span class="Identifier">valStack</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">matchStr</span><span class="Operator">.</span><span class="Identifier">parseFloat</span>
  1417. <span class="Identifier">echo</span> <span class="Identifier">valStack</span>
  1418. <span class="Keyword">except</span> <span class="Identifier">ValueError</span><span class="Punctuation">:</span>
  1419. <span class="Keyword">discard</span>
  1420. <span class="Keyword">of</span> <span class="StringLit">&quot;Sum&quot;</span><span class="Punctuation">,</span> <span class="StringLit">&quot;Product&quot;</span><span class="Punctuation">:</span>
  1421. <span class="Keyword">try</span><span class="Punctuation">:</span>
  1422. <span class="Keyword">let</span> <span class="Identifier">val</span> <span class="Operator">=</span> <span class="Identifier">matchStr</span><span class="Operator">.</span><span class="Identifier">parseFloat</span>
  1423. <span class="Keyword">except</span> <span class="Identifier">ValueError</span><span class="Punctuation">:</span>
  1424. <span class="Keyword">if</span> <span class="Identifier">valStack</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">&gt;</span> <span class="DecNumber">1</span> <span class="Keyword">and</span> <span class="Identifier">opStack</span><span class="Operator">.</span><span class="Identifier">len</span> <span class="Operator">&gt;</span> <span class="DecNumber">0</span><span class="Punctuation">:</span>
  1425. <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">case</span> <span class="Identifier">opStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
  1426. <span class="Keyword">of</span> <span class="CharLit">'+'</span><span class="Punctuation">:</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span> <span class="Operator">+</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
  1427. <span class="Keyword">of</span> <span class="CharLit">'-'</span><span class="Punctuation">:</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span> <span class="Operator">-</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
  1428. <span class="Keyword">of</span> <span class="CharLit">'*'</span><span class="Punctuation">:</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span> <span class="Operator">*</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
  1429. <span class="Keyword">else</span><span class="Punctuation">:</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">2</span><span class="Punctuation">]</span> <span class="Operator">/</span> <span class="Identifier">valStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span>
  1430. <span class="Identifier">valStack</span><span class="Operator">.</span><span class="Identifier">setLen</span> <span class="Identifier">valStack</span><span class="Operator">.</span><span class="Identifier">high</span>
  1431. <span class="Identifier">echo</span> <span class="Identifier">valStack</span>
  1432. <span class="Identifier">opStack</span><span class="Operator">.</span><span class="Identifier">setLen</span> <span class="Identifier">opStack</span><span class="Operator">.</span><span class="Identifier">high</span>
  1433. <span class="Identifier">echo</span> <span class="Identifier">opStack</span>
  1434. <span class="Identifier">pkChar</span><span class="Punctuation">:</span>
  1435. <span class="Identifier">leave</span><span class="Punctuation">:</span>
  1436. <span class="Keyword">if</span> <span class="Identifier">length</span> <span class="Operator">==</span> <span class="DecNumber">1</span> <span class="Keyword">and</span> <span class="StringLit">&quot;Value&quot;</span> <span class="Operator">!=</span> <span class="Identifier">pStack</span><span class="Punctuation">[</span><span class="Operator">^</span><span class="DecNumber">1</span><span class="Punctuation">]</span><span class="Punctuation">:</span>
  1437. <span class="Keyword">let</span> <span class="Identifier">matchChar</span> <span class="Operator">=</span> <span class="Identifier">s</span><span class="Punctuation">[</span><span class="Identifier">start</span><span class="Punctuation">]</span>
  1438. <span class="Identifier">opStack</span><span class="Operator">.</span><span class="Identifier">add</span> <span class="Identifier">matchChar</span>
  1439. <span class="Identifier">echo</span> <span class="Identifier">opStack</span>
  1440. <span class="Keyword">let</span> <span class="Identifier">pLen</span> <span class="Operator">=</span> <span class="Identifier">parseArithExpr</span><span class="Punctuation">(</span><span class="Identifier">txt</span><span class="Punctuation">)</span></pre></p>
  1441. <p>The <em>handlers</em> parameter consists of code blocks for <em>PegKinds</em>, which define the grammar elements of interest. Each block can contain handler code to be executed when the parser enters and leaves text matching the grammar element. An <em>enter</em> handler can access the specific PEG AST node being matched as <em>p</em>, the entire parsed string as <em>s</em> and the position of the matched text segment in <em>s</em> as <em>start</em>. A <em>leave</em> handler can access <em>p</em>, <em>s</em>, <em>start</em> and also the length of the matched text segment as <em>length</em>. For an unsuccessful match, the <em>enter</em> and <em>leave</em> handlers will be executed, with <em>length</em> set to -1.</p>
  1442. <p>Symbols declared in an <em>enter</em> handler can be made visible in the corresponding <em>leave</em> handler by annotating them with an <em>inject</em> pragma.</p>
  1443. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L957" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1444. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L957" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1445. </dd>
  1446. </div>
  1447. </div>
  1448. <div id="ident-templates-all">
  1449. <div id="ident.t">
  1450. <dt><pre><span class="Keyword">template</span> <a href="#ident.t"><span class="Identifier">ident</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1451. <dd>
  1452. same as <tt class="docutils literal"><span class="pre">[a-zA-Z_][a-zA-z_0-9]*</span></tt>; standard identifier
  1453. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L385" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1454. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L385" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1455. </dd>
  1456. </div>
  1457. </div>
  1458. <div id="identChars-templates-all">
  1459. <div id="identChars.t">
  1460. <dt><pre><span class="Keyword">template</span> <a href="#identChars.t"><span class="Identifier">identChars</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1461. <dd>
  1462. expands to <tt class="docutils literal"><span class="pre">charset({'a'..'z', 'A'..'Z', '0'..'9', '_'})</span></tt>
  1463. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L377" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1464. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L377" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1465. </dd>
  1466. </div>
  1467. </div>
  1468. <div id="identStartChars-templates-all">
  1469. <div id="identStartChars.t">
  1470. <dt><pre><span class="Keyword">template</span> <a href="#identStartChars.t"><span class="Identifier">identStartChars</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1471. <dd>
  1472. expands to <tt class="docutils literal"><span class="pre">charset({'A'..'Z', 'a'..'z', '_'})</span></tt>
  1473. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L381" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1474. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L381" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1475. </dd>
  1476. </div>
  1477. </div>
  1478. <div id="letters-templates-all">
  1479. <div id="letters.t">
  1480. <dt><pre><span class="Keyword">template</span> <a href="#letters.t"><span class="Identifier">letters</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1481. <dd>
  1482. expands to <tt class="docutils literal"><span class="pre">charset({'A'..'Z', 'a'..'z'})</span></tt>
  1483. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L365" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1484. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L365" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1485. </dd>
  1486. </div>
  1487. </div>
  1488. <div id="natural-templates-all">
  1489. <div id="natural.t">
  1490. <dt><pre><span class="Keyword">template</span> <a href="#natural.t"><span class="Identifier">natural</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1491. <dd>
  1492. same as <tt class="docutils literal"><span class="pre">\d+</span></tt>
  1493. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L390" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1494. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L390" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1495. </dd>
  1496. </div>
  1497. </div>
  1498. <div id="whitespace-templates-all">
  1499. <div id="whitespace.t">
  1500. <dt><pre><span class="Keyword">template</span> <a href="#whitespace.t"><span class="Identifier">whitespace</span></a><span class="Other">(</span><span class="Other">)</span><span class="Other">:</span> <a href="pegs.html#Peg"><span class="Identifier">Peg</span></a></pre></dt>
  1501. <dd>
  1502. expands to <tt class="docutils literal"><span class="pre">charset({' ', '\9'..'\13'})</span></tt>
  1503. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/pegs.nim#L373" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  1504. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/pegs.nim#L373" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  1505. </dd>
  1506. </div>
  1507. </div>
  1508. </dl>
  1509. </div>
  1510. </div>
  1511. </div>
  1512. <div class="twelve-columns footer">
  1513. <span class="nim-sprite"></span>
  1514. <br>
  1515. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-03 14:57:02 UTC</small>
  1516. </div>
  1517. </div>
  1518. </div>
  1519. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  1520. </body>
  1521. </html>